Skip to content

Commit 2e5b399

Browse files
authored
Merge branch 'opensearch-project:main' into main
2 parents 2b443ce + 9a4628b commit 2e5b399

442 files changed

Lines changed: 21309 additions & 5486 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/data-prepper-trace-analytics-raw-span-e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
java: [11, 17, 21, docker]
17-
otelVersion: ['0.9.0-alpha', '0.16.0-alpha']
17+
otelVersion: ['0.16.0-alpha', '1.3.2-alpha']
1818
fail-fast: false
1919

2020
runs-on: ubuntu-latest

data-prepper-api/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
1515
implementation libs.parquet.common
1616
implementation libs.commons.lang3
17+
implementation 'jakarta.validation:jakarta.validation-api:3.0.2'
1718
testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
1819
testImplementation project(':data-prepper-test-common')
1920
testImplementation 'org.skyscreamer:jsonassert:1.5.3'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.dataprepper.model.annotations;
7+
8+
import jakarta.validation.Constraint;
9+
import jakarta.validation.Payload;
10+
import org.opensearch.dataprepper.model.validation.RegexValueValidator;
11+
12+
import java.lang.annotation.ElementType;
13+
import java.lang.annotation.Retention;
14+
import java.lang.annotation.RetentionPolicy;
15+
import java.lang.annotation.Target;
16+
17+
@Constraint(validatedBy = RegexValueValidator.class)
18+
@Target({ElementType.FIELD, ElementType.PARAMETER})
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface ValidRegex {
21+
String message() default "Invalid regular expression pattern";
22+
23+
Class<?>[] groups() default {};
24+
25+
Class<? extends Payload>[] payload() default {};
26+
}

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/codec/JsonDecoder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.core.JsonFactory;
99
import com.fasterxml.jackson.core.JsonParser;
1010
import com.fasterxml.jackson.core.JsonToken;
11+
import com.fasterxml.jackson.core.StreamReadConstraints;
1112
import com.fasterxml.jackson.databind.ObjectMapper;
1213

1314
import org.opensearch.dataprepper.model.event.Event;
@@ -30,10 +31,15 @@ public class JsonDecoder implements ByteDecoder {
3031
private Collection<String> includeKeys;
3132
private Collection<String> includeKeysMetadata;
3233

33-
public JsonDecoder(String keyName, Collection<String> includeKeys, Collection<String> includeKeysMetadata) {
34+
public JsonDecoder(String keyName, Collection<String> includeKeys, Collection<String> includeKeysMetadata, Integer maxEventLength) {
3435
this.keyName = keyName;
3536
this.includeKeys = includeKeys;
3637
this.includeKeysMetadata = includeKeysMetadata;
38+
if (maxEventLength != null) {
39+
jsonFactory.setStreamReadConstraints(StreamReadConstraints.builder()
40+
.maxStringLength(maxEventLength)
41+
.build());
42+
}
3743
}
3844

3945
public JsonDecoder() {

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/codec/OutputCodec.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.IOException;
1717
import java.io.OutputStream;
18+
import java.io.ByteArrayOutputStream;
1819
import java.util.Map;
1920

2021
public interface OutputCodec {
@@ -28,7 +29,7 @@ public interface OutputCodec {
2829
* @param outputStream outputStream param for wrapping
2930
* @param event Event to auto-generate schema
3031
* @param context Extra Context used in Codec.
31-
* @throws IOException throws IOException when invalid input is received or not able to create wrapping
32+
* @throws IOException throws IOException when invalid input is received or not able to create wrapping
3233
*/
3334
void start(OutputStream outputStream, Event event, OutputCodecContext context) throws IOException;
3435

@@ -51,6 +52,21 @@ public interface OutputCodec {
5152
*/
5253
void complete(OutputStream outputStream) throws IOException;
5354

55+
/**
56+
* this method get called from {@link Sink} to estimate size of event in {@link OutputStream}
57+
*
58+
* @param event event Record event
59+
* @return long size of the serialized event
60+
* @throws IOException throws IOException when invalid input is received or not able to create wrapping
61+
*/
62+
default long getEstimatedSize(Event event, OutputCodecContext codecContext) throws IOException {
63+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
64+
start(outputStream, event, codecContext);
65+
writeEvent(event, outputStream);
66+
complete(outputStream);
67+
return outputStream.toByteArray().length;
68+
}
69+
5470
/**
5571
* used to get extension of file
5672
*

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/Event.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ public interface Event extends Serializable {
247247
*/
248248
EventHandle getEventHandle();
249249

250+
default void putIfAbsent(final String key, final Class clazz, final Object value) {
251+
if (get(key, clazz) == null)
252+
put(key, value);
253+
}
254+
250255
JsonStringBuilder jsonBuilder();
251256

252257
abstract class JsonStringBuilder {

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/failures/DlqObject.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88

99
import com.fasterxml.jackson.annotation.JsonIgnore;
10-
import org.opensearch.dataprepper.model.event.EventHandle;
1110
import org.apache.commons.lang3.StringUtils;
1211
import org.opensearch.dataprepper.model.event.EventHandle;
12+
import org.opensearch.dataprepper.model.configuration.PluginSetting;
1313

1414
import java.time.Instant;
1515
import java.time.ZoneId;
@@ -122,6 +122,16 @@ public String toString() {
122122
'}';
123123
}
124124

125+
public static DlqObject createDlqObject(PluginSetting pluginSetting, EventHandle eventHandle, Object failedData) {
126+
return DlqObject.builder()
127+
.withEventHandle(eventHandle)
128+
.withFailedData(failedData)
129+
.withPluginName(pluginSetting.getName())
130+
.withPipelineName(pluginSetting.getPipelineName())
131+
.withPluginId(pluginSetting.getName())
132+
.build();
133+
}
134+
125135
public static Builder builder() {
126136
return new Builder();
127137
}

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/JacksonOtelLog.java

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
*/
2525
public class JacksonOtelLog extends JacksonEvent implements OpenTelemetryLog {
2626

27-
protected static final String OBSERVED_TIME_KEY = "observedTime";
27+
protected static final String OBSERVED_TIME_KEY = "observedTimestamp";
28+
protected static final String SCOPE_KEY = "instrumentationScope";
29+
protected static final String RESOURCE_KEY = "resource";
2830
protected static final String TIME_KEY = "time";
2931
protected static final String SERVICE_NAME_KEY = "serviceName";
3032
protected static final String ATTRIBUTES_KEY = "attributes";
@@ -33,13 +35,18 @@ public class JacksonOtelLog extends JacksonEvent implements OpenTelemetryLog {
3335
protected static final String BODY_KEY = "body";
3436
protected static final String SPAN_ID_KEY = "spanId";
3537
protected static final String TRACE_ID_KEY = "traceId";
38+
protected static final String SEVERITY_KEY = "severity";
3639
protected static final String SEVERITY_NUMBER_KEY = "severityNumber";
3740
protected static final String SEVERITY_TEXT_KEY = "severityText";
3841
protected static final String DROPPED_ATTRIBUTES_COUNT_KEY = "droppedAttributesCount";
3942

43+
protected void checkAndSetDefaultValues() {
44+
putIfAbsent(ATTRIBUTES_KEY, Map.class, new HashMap<>());
45+
}
4046

4147
protected JacksonOtelLog(final JacksonOtelLog.Builder builder) {
4248
super(builder);
49+
checkAndSetDefaultValues();
4350

4451
checkArgument(this.getMetadata().getEventType().equals("LOG"), "eventType must be of type Log");
4552
}
@@ -94,6 +101,16 @@ public String getSeverityText() {
94101
return this.get(SEVERITY_TEXT_KEY, String.class);
95102
}
96103

104+
@Override
105+
public Map<String, Object> getScope() {
106+
return this.get(SCOPE_KEY, Map.class);
107+
}
108+
109+
@Override
110+
public Map<String, Object> getResource() {
111+
return this.get(RESOURCE_KEY, Map.class);
112+
}
113+
97114
@Override
98115
public Integer getDroppedAttributesCount() {
99116
return this.get(DROPPED_ATTRIBUTES_COUNT_KEY, Integer.class);
@@ -221,6 +238,30 @@ public Builder withSchemaUrl(final String schemaUrl) {
221238
return getThis();
222239
}
223240

241+
/**
242+
* Sets the scope of the log event
243+
*
244+
* @param scope scope to be set
245+
* @return the builder
246+
* @since 2.11
247+
*/
248+
public Builder withScope(final Map<String, Object> scope) {
249+
data.put(SCOPE_KEY, scope);
250+
return getThis();
251+
}
252+
253+
/**
254+
* Sets the resource of the log event
255+
*
256+
* @param resource resource to be set
257+
* @return the builder
258+
* @since 2.11
259+
*/
260+
public Builder withResource(final Map<String, Object> resource) {
261+
data.put(RESOURCE_KEY, resource);
262+
return getThis();
263+
}
264+
224265
/**
225266
* Sets the flags that are associated with this log event
226267
*
@@ -305,21 +346,20 @@ public Builder withDroppedAttributesCount(final Integer droppedAttributesCount)
305346
return getThis();
306347
}
307348

349+
protected void populateEvent() {
350+
this.withEventType(EventType.LOG.toString());
351+
this.withData(data);
352+
}
353+
308354
/**
309355
* Returns a newly created {@link JacksonOtelLog}.
310356
*
311357
* @return a log
312358
* @since 2.1
313359
*/
314360
public JacksonOtelLog build() {
315-
this.withEventType(EventType.LOG.toString());
316-
this.withData(data);
317-
checkAndSetDefaultValues();
361+
populateEvent();
318362
return new JacksonOtelLog(this);
319363
}
320-
321-
private void checkAndSetDefaultValues() {
322-
data.computeIfAbsent(ATTRIBUTES_KEY, k -> new HashMap<>());
323-
}
324364
}
325365
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.dataprepper.model.log;
7+
8+
/**
9+
* A Jackson Standard implementation for {@link OpenTelemetryLog}.
10+
*
11+
* @since 2.11
12+
*/
13+
public class JacksonStandardOTelLog extends JacksonOtelLog {
14+
15+
JacksonStandardOTelLog(final JacksonOtelLog.Builder builder) {
16+
super(builder);
17+
}
18+
19+
public static JacksonStandardOTelLog.Builder builder() {
20+
return new JacksonStandardOTelLog.Builder();
21+
}
22+
23+
@Override
24+
public String toJsonString() {
25+
return getJsonNode().toString();
26+
}
27+
28+
public static class Builder extends JacksonOtelLog.Builder {
29+
30+
@Override
31+
public JacksonOtelLog build() {
32+
populateEvent();
33+
return new JacksonStandardOTelLog(this);
34+
}
35+
36+
}
37+
}

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/log/OpenTelemetryLog.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,21 @@ public interface OpenTelemetryLog extends Log {
112112
* @since 2.1
113113
*/
114114
Object getBody();
115+
116+
/**
117+
* Gets the scope of this log event.
118+
*
119+
* @return the scope
120+
* @since 2.11
121+
*/
122+
Map<String, Object> getScope();
123+
124+
/**
125+
* Gets the resource of this log event.
126+
*
127+
* @return the resource
128+
* @since 2.11
129+
*/
130+
Map<String, Object> getResource();
131+
115132
}

0 commit comments

Comments
 (0)