Skip to content

Commit

Permalink
Final changes from POC, adds agg support
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Engelbrecht <[email protected]>
  • Loading branch information
engechas committed Apr 18, 2024
1 parent 96e03dd commit 60739ab
Show file tree
Hide file tree
Showing 114 changed files with 1,376 additions and 608 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class JacksonDocument extends JacksonEvent implements Document {
protected JacksonDocument(final Builder builder) {
super(builder);

checkArgument(this.getMetadata().getEventType().equals("DOCUMENT"), "eventType must be of type Document");
checkArgument(this.getEventMetadata().getEventType().equals("DOCUMENT"), "eventType must be of type Document");
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public interface Event extends Serializable {
* @return EventMetadata for the event
* @since 1.2
*/
EventMetadata getMetadata();
EventMetadata getEventMetadata();

/**
* Checks if the key exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private String formatStringInternal(final String format, final ExpressionEvaluat
}

@Override
public EventMetadata getMetadata() {
public EventMetadata getEventMetadata() {
return eventMetadata;
}

Expand Down Expand Up @@ -477,7 +477,7 @@ public static JacksonEvent fromEvent(final Event event) {
} else {
return JacksonEvent.builder()
.withData(event.toMap())
.withEventMetadata(event.getMetadata())
.withEventMetadata(event.getEventMetadata())
.build();
}
}
Expand Down Expand Up @@ -609,7 +609,7 @@ public String toJsonString() {

final String tagsKey = getTagsKey();
if (tagsKey != null) {
final JsonNode tagsNode = mapper.valueToTree(event.getMetadata().getTags());
final JsonNode tagsNode = mapper.valueToTree(event.getEventMetadata().getTags());
return jsonString.substring(0, jsonString.length() - 1) + ",\"" + tagsKey + "\":" + tagsNode.toString() + "}";
}
return jsonString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class JacksonLog extends JacksonEvent implements Log {
protected JacksonLog(final Builder builder) {
super(builder);

checkArgument(this.getMetadata().getEventType().equals("LOG"), "eventType must be of type Log");
checkArgument(this.getEventMetadata().getEventType().equals("LOG"), "eventType must be of type Log");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class JacksonOtelLog extends JacksonEvent implements OpenTelemetryLog {
protected JacksonOtelLog(final JacksonOtelLog.Builder builder) {
super(builder);

checkArgument(this.getMetadata().getEventType().equals("LOG"), "eventType must be of type Log");
checkArgument(this.getEventMetadata().getEventType().equals("LOG"), "eventType must be of type Log");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class JacksonExponentialHistogram extends JacksonMetric implements Expone
protected JacksonExponentialHistogram(JacksonExponentialHistogram.Builder builder, boolean flattenAttributes) {
super(builder, flattenAttributes);

checkArgument(this.getMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
checkArgument(this.getEventMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
}

public static JacksonExponentialHistogram.Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class JacksonGauge extends JacksonMetric implements Gauge {

protected JacksonGauge(Builder builder, boolean flattenAttributes) {
super(builder, flattenAttributes);
checkArgument(this.getMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
checkArgument(this.getEventMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class JacksonHistogram extends JacksonMetric implements Histogram {
protected JacksonHistogram(JacksonHistogram.Builder builder, boolean flattenAttributes) {
super(builder, flattenAttributes);

checkArgument(this.getMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
checkArgument(this.getEventMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
}
public static JacksonHistogram.Builder builder() {
return new JacksonHistogram.Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class JacksonSum extends JacksonMetric implements Sum {
protected JacksonSum(JacksonSum.Builder builder, boolean flattenAttributes) {
super(builder, flattenAttributes);

checkArgument(this.getMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
checkArgument(this.getEventMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
}

public static JacksonSum.Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class JacksonSummary extends JacksonMetric implements Summary {
protected JacksonSummary(JacksonSummary.Builder builder, boolean flattenAttributes) {
super(builder, flattenAttributes);

checkArgument(this.getMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
checkArgument(this.getEventMetadata().getEventType().equals(EventType.METRIC.toString()), "eventType must be of type Metric");
}

public static JacksonSummary.Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class JacksonSpan extends JacksonEvent implements Span {
protected JacksonSpan(final Builder builder) {
super(builder);

checkArgument(this.getMetadata().getEventType().equals("TRACE"), "eventType must be of type Trace");
checkArgument(this.getEventMetadata().getEventType().equals("TRACE"), "eventType must be of type Trace");
}

private JacksonSpan(final JacksonSpan otherSpan) {
Expand Down Expand Up @@ -182,7 +182,7 @@ public static JacksonSpan fromSpan(final Span span) {
} else {
return JacksonSpan.builder()
.withData(span.toMap())
.withEventMetadata(span.getMetadata())
.withEventMetadata(span.getEventMetadata())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testBuilderUsesDocumentEventType() {
final Document document = JacksonDocument.builder().build();

assertThat(document, is(notNullValue()));
assertThat(document.getMetadata().getEventType(), is(equalTo("DOCUMENT")));
assertThat(document.getEventMetadata().getEventType(), is(equalTo("DOCUMENT")));
}

@Test
Expand All @@ -35,7 +35,7 @@ public void testBuilderUsesCustomEventType() {
.build();

assertThat(document, is(notNullValue()));
assertThat(document.getMetadata().getEventType(), is(equalTo("DOCUMENT")));
assertThat(document.getEventMetadata().getEventType(), is(equalTo("DOCUMENT")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void testBuild_withEventType() {
.withEventType(eventType)
.build();

assertThat(event.getMetadata().getEventType(), is(equalTo(eventType)));
assertThat(event.getEventMetadata().getEventType(), is(equalTo(eventType)));
assertThat(event.getEventHandle(), is(notNullValue()));
assertThat(event.getEventHandle().getInternalOriginationTime(), is(notNullValue()));
}
Expand All @@ -431,7 +431,7 @@ public void testBuild_withTimeReceived() {
.withTimeReceived(now)
.build();

assertThat(event.getMetadata().getTimeReceived(), is(equalTo(now)));
assertThat(event.getEventMetadata().getTimeReceived(), is(equalTo(now)));
assertThat(event.getEventHandle(), is(notNullValue()));
assertThat(event.getEventHandle().getInternalOriginationTime(), is(equalTo(now)));
}
Expand Down Expand Up @@ -461,7 +461,7 @@ public void testBuild_withAttributes() {
.withEventMetadataAttributes(testAttributes)
.build();

assertThat(event.getMetadata().getAttributes(), is(equalTo(testAttributes)));
assertThat(event.getEventMetadata().getAttributes(), is(equalTo(testAttributes)));
}

@Test
Expand All @@ -484,9 +484,9 @@ public void testBuild_withAllMetadataFields() {
.withEventMetadata(metadata)
.build();

assertThat(event.getMetadata().getAttributes(), is(not(equalTo(testAttributes))));
assertThat(event.getMetadata().getTimeReceived(), is(not(equalTo(now))));
assertThat(event.getMetadata().getEventType(), is(equalTo(emEventType)));
assertThat(event.getEventMetadata().getAttributes(), is(not(equalTo(testAttributes))));
assertThat(event.getEventMetadata().getTimeReceived(), is(not(equalTo(now))));
assertThat(event.getEventMetadata().getEventType(), is(equalTo(emEventType)));
}

@Test
Expand All @@ -500,7 +500,7 @@ public void testBuild_withEventMetadata() {
.withEventMetadata(metadata)
.build();

assertThat(event.getMetadata(), is(equalTo(metadata)));
assertThat(event.getEventMetadata(), is(equalTo(metadata)));
}


Expand Down Expand Up @@ -690,9 +690,9 @@ void fromEvent_with_a_JacksonEvent() {
assertThat(createdEvent.toMap(), equalTo(dataObject));
assertThat(createdEvent.getJsonNode(), not(sameInstance(originalEvent.getJsonNode())));

assertThat(createdEvent.getMetadata(), notNullValue());
assertThat(createdEvent.getMetadata(), not(sameInstance(originalEvent.getMetadata())));
assertThat(createdEvent.getMetadata(), equalTo(originalEvent.getMetadata()));
assertThat(createdEvent.getEventMetadata(), notNullValue());
assertThat(createdEvent.getEventMetadata(), not(sameInstance(originalEvent.getEventMetadata())));
assertThat(createdEvent.getEventMetadata(), equalTo(originalEvent.getEventMetadata()));
}

@Test
Expand All @@ -702,7 +702,7 @@ void fromEvent_with_a_non_JacksonEvent() {
final EventMetadata eventMetadata = mock(EventMetadata.class);
final Event originalEvent = mock(Event.class);
when(originalEvent.toMap()).thenReturn(dataObject);
when(originalEvent.getMetadata()).thenReturn(eventMetadata);
when(originalEvent.getEventMetadata()).thenReturn(eventMetadata);

final JacksonEvent createdEvent = JacksonEvent.fromEvent(originalEvent);

Expand All @@ -711,8 +711,8 @@ void fromEvent_with_a_non_JacksonEvent() {

assertThat(createdEvent.toMap(), equalTo(dataObject));

assertThat(createdEvent.getMetadata(), notNullValue());
assertThat(createdEvent.getMetadata(), equalTo(eventMetadata));
assertThat(createdEvent.getEventMetadata(), notNullValue());
assertThat(createdEvent.getEventMetadata(), equalTo(eventMetadata));
}

@Test
Expand All @@ -723,7 +723,7 @@ void testJsonStringBuilder() {
.withEventType(eventType)
.withData(jsonString)
.build();
final EventMetadata eventMetadata = event.getMetadata();
final EventMetadata eventMetadata = event.getEventMetadata();
eventMetadata.addTags(List.of("tag1", "tag2"));
final String expectedJsonString = "{\"foo\":\"bar\",\"tags\":[\"tag1\",\"tag2\"]}";
assertThat(event.jsonBuilder().includeTags("tags").toJsonString(), equalTo(expectedJsonString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ void serialize_without_acknowledgementSet_includes_data() throws IOException, Cl
final JacksonEvent deserializedEvent = (JacksonEvent) deserializedObject;

assertThat(deserializedEvent.toMap(), equalTo(objectUnderTest.toMap()));
assertThat(deserializedEvent.getMetadata(), equalTo(objectUnderTest.getMetadata()));
assertThat(deserializedEvent.getEventMetadata(), equalTo(objectUnderTest.getEventMetadata()));

assertThat(deserializedEvent.getEventHandle(), instanceOf(InternalEventHandle.class));
assertThat(((InternalEventHandle) deserializedEvent.getEventHandle()).getAcknowledgementSet(), nullValue());
assertThat(deserializedEvent.getEventHandle().getInternalOriginationTime(), equalTo(objectUnderTest.getMetadata().getTimeReceived()));
assertThat(deserializedEvent.getEventHandle().getInternalOriginationTime(), equalTo(objectUnderTest.getEventMetadata().getTimeReceived()));

}

Expand All @@ -71,11 +71,11 @@ void serialize_with_acknowledgementSet_does_not_include_old_acknowledgement_set(
final JacksonEvent deserializedEvent = (JacksonEvent) deserializedObject;

assertThat(deserializedEvent.toMap(), equalTo(objectUnderTest.toMap()));
assertThat(deserializedEvent.getMetadata(), equalTo(objectUnderTest.getMetadata()));
assertThat(deserializedEvent.getEventMetadata(), equalTo(objectUnderTest.getEventMetadata()));

assertThat(deserializedEvent.getEventHandle(), instanceOf(InternalEventHandle.class));
assertThat(((InternalEventHandle) deserializedEvent.getEventHandle()).getAcknowledgementSet(), nullValue());
assertThat(deserializedEvent.getEventHandle().getInternalOriginationTime(), equalTo(objectUnderTest.getMetadata().getTimeReceived()));
assertThat(deserializedEvent.getEventHandle().getInternalOriginationTime(), equalTo(objectUnderTest.getEventMetadata().getTimeReceived()));
}

private Object serializeAndDeserialize(final JacksonEvent objectUnderTest) throws IOException, ClassNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testBuilder_usesLogEventType() {
final Log log = JacksonLog.builder().build();

assertThat(log, is(notNullValue()));
assertThat(log.getMetadata().getEventType(), is(equalTo("LOG")));
assertThat(log.getEventMetadata().getEventType(), is(equalTo("LOG")));
}

@Test
Expand All @@ -34,7 +34,7 @@ public void testBuilder_usesLogEventType_withUserProvidedEventType() {
.build();

assertThat(log, is(notNullValue()));
assertThat(log.getMetadata().getEventType(), is(equalTo("LOG")));
assertThat(log.getEventMetadata().getEventType(), is(equalTo("LOG")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ void testBuilder_withEventMetadata_with_event_metadata_with_valid_metadata() {
.build();

assertThat(jacksonSpan, is(notNullValue()));
assertThat(jacksonSpan.getMetadata(), is(notNullValue()));
assertThat(jacksonSpan.getMetadata().getTimeReceived(), equalTo(now));
assertThat(jacksonSpan.getEventMetadata(), is(notNullValue()));
assertThat(jacksonSpan.getEventMetadata().getTimeReceived(), equalTo(now));
}

@Test
Expand Down Expand Up @@ -677,8 +677,8 @@ void testBuilder_withData_with_event_valid_data() {
.build();

assertThat(jacksonSpan, is(notNullValue()));
assertThat(jacksonSpan.getMetadata(), is(notNullValue()));
assertThat(jacksonSpan.getMetadata().getTimeReceived(), equalTo(now));
assertThat(jacksonSpan.getEventMetadata(), is(notNullValue()));
assertThat(jacksonSpan.getEventMetadata().getTimeReceived(), equalTo(now));
assertThat(jacksonSpan.toMap().get("traceId"), equalTo(traceId));
assertThat(jacksonSpan.toMap().get("kind"), equalTo(kind));
assertThat(jacksonSpan.toMap().get("traceGroup"), equalTo(traceGroup));
Expand All @@ -699,17 +699,17 @@ void fromSpan_with_a_Jackson_Span() {

assertThat(createdEvent.toMap(), equalTo(jacksonSpan.toMap()));

assertThat(createdEvent.getMetadata(), notNullValue());
assertThat(createdEvent.getMetadata(), not(sameInstance(jacksonSpan.getMetadata())));
assertThat(createdEvent.getMetadata(), equalTo(jacksonSpan.getMetadata()));
assertThat(createdEvent.getEventMetadata(), notNullValue());
assertThat(createdEvent.getEventMetadata(), not(sameInstance(jacksonSpan.getEventMetadata())));
assertThat(createdEvent.getEventMetadata(), equalTo(jacksonSpan.getEventMetadata()));
}

@Test
void fromSpan_with_a_non_JacksonSpan() {
final EventMetadata eventMetadata = mock(EventMetadata.class);
final Span originalSpan = mock(Span.class);
when(originalSpan.toMap()).thenReturn(jacksonSpan.toMap());
when(originalSpan.getMetadata()).thenReturn(eventMetadata);
when(originalSpan.getEventMetadata()).thenReturn(eventMetadata);
when(eventMetadata.getEventType()).thenReturn("TRACE");

final JacksonSpan createdEvent = JacksonSpan.fromSpan(originalSpan);
Expand All @@ -718,8 +718,8 @@ void fromSpan_with_a_non_JacksonSpan() {

assertThat(createdEvent.toMap(), equalTo(jacksonSpan.toMap()));

assertThat(createdEvent.getMetadata(), notNullValue());
assertThat(createdEvent.getMetadata(), not(sameInstance(jacksonSpan.getMetadata())));
assertThat(createdEvent.getMetadata().getEventType(), equalTo("TRACE"));
assertThat(createdEvent.getEventMetadata(), notNullValue());
assertThat(createdEvent.getEventMetadata(), not(sameInstance(jacksonSpan.getEventMetadata())));
assertThat(createdEvent.getEventMetadata().getEventType(), equalTo("TRACE"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ private WireEvents fromPeerForwardingEventsToWireEvents(final PeerForwardingEven
List<WireEvent> wireEventList = null;
if (peerForwardingEvents.getEvents() != null) {
wireEventList = peerForwardingEvents.getEvents().stream().map(event -> new WireEvent(
event.getMetadata().getEventType(),
event.getMetadata().getTimeReceived(),
event.getMetadata().getAttributes(),
event.getEventMetadata().getEventType(),
event.getEventMetadata().getTimeReceived(),
event.getEventMetadata().getAttributes(),
event.toJsonString()
)).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.opensearch.dataprepper.model.trace.Span;
import org.opensearch.dataprepper.model.trace.JacksonSpan;
import org.opensearch.dataprepper.model.record.Record;
import org.opensearch.dataprepper.model.event.Event;
import org.opensearch.dataprepper.model.event.JacksonEvent;
import org.opensearch.dataprepper.model.event.EventFactory;
Expand Down Expand Up @@ -98,7 +97,7 @@ public Record getRecord(final Record record) {
Record newRecord;
DefaultEventHandle eventHandle = (DefaultEventHandle)recordEvent.getEventHandle();
if (eventHandle != null && eventHandle.getAcknowledgementSet() != null) {
final EventMetadata eventMetadata = recordEvent.getMetadata();
final EventMetadata eventMetadata = recordEvent.getEventMetadata();
final EventBuilder eventBuilder = (EventBuilder) eventFactory.eventBuilder(EventBuilder.class).withEventMetadata(eventMetadata).withData(recordEvent.toMap());
newRecordEvent = (JacksonEvent) eventBuilder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testBasic() {
EventBuilder eventBuilder = (EventBuilder)baseEventBuilder.withEventMetadataAttributes(attributes).withData(data);

JacksonEvent event = (JacksonEvent) eventBuilder.build();
EventMetadata eventMetadata = event.getMetadata();
EventMetadata eventMetadata = event.getEventMetadata();
assertThat(eventMetadata.getTimeReceived(), not(equalTo(null)));
assertThat(eventMetadata.getEventType(), equalTo(DefaultEventBuilderFactory.EVENT_TYPE));
assertThat(eventMetadata.getAttributes(), equalTo(attributes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testBasic() {
LogEventBuilder eventBuilder = (LogEventBuilder)baseEventBuilder.withEventMetadataAttributes(attributes).withData(data);

JacksonLog log = (JacksonLog) eventBuilder.build();
EventMetadata eventMetadata = log.getMetadata();
EventMetadata eventMetadata = log.getEventMetadata();
assertThat(eventMetadata.getTimeReceived(), not(equalTo(null)));
assertThat(eventMetadata.getEventType(), equalTo(DefaultLogEventBuilderFactory.LOG_EVENT_TYPE));
assertThat(eventMetadata.getAttributes(), equalTo(attributes));
Expand Down
Loading

0 comments on commit 60739ab

Please sign in to comment.