Skip to content

Commit

Permalink
support for follow_from (#26)
Browse files Browse the repository at this point in the history
* support for follow_from

* test modified , scenario for follow_from event

* comment nit

* Update data-model/src/main/java/org/hypertrace/core/datamodel/shared/trace/StructuredTraceBuilder.java

Co-authored-by: kotharironak <[email protected]>

Co-authored-by: kotharironak <[email protected]>
  • Loading branch information
Sunn-y-Arora and kotharironak authored Oct 7, 2021
1 parent f8dc2b1 commit acf2c3d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,22 @@ private void processEventRefList(ByteBuffer traceId, Event event) {
//TODO: consider creating an empty event node?
continue;
}
//todo: Read about what can we do with FOLLOWS_FROM
//Ignore FOLLOWS_FROM for now.
if (!eventRef.getRefType().equals(EventRefType.CHILD_OF)) {
continue;
}

/*
* For Follow from relationship:
* As, both the construct `child_of` and `follow_from` represent parent-child relation in common
* where in one case parent is interested in child span's result while in other case not.
*
* So, to support common behaviour, we will be establish link for `follow_from` as well.
* commenting out this part.
*
* if (!eventRef.getRefType().equals(EventRefType.CHILD_OF)) {
*
* continue;
* }
* Ref: https://github.com/hypertrace/hypertrace/issues/234.
Note: Ideally, an event should have a single parent. It would be either via child_of or using follow_from.
*/

Event parentEvent = eventMap.get(eventRef.getEventId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;


class StructuredTraceGraphTest {

private static final String CUSTOMER_ID = "customer_id";
Expand Down Expand Up @@ -139,34 +140,50 @@ void testOnMockedEvents() {
RawSpan rawSpan2 = RawSpan.newBuilder().setCustomerId(CUSTOMER_ID).setTraceId(traceId)
.setEvent(e2).setEntityList(List.of(entity2)).build();

String entityId3 = UUID.randomUUID().toString();
Event e3 = getEvent(generateRandomId(), entityId3);
Entity entity3 = getEntity(entityId3, "DAEMONSET");
RawSpan rawSpan3 = RawSpan.newBuilder().setCustomerId(CUSTOMER_ID).setTraceId(traceId)
.setEvent(e3).setEntityList(List.of(entity3)).build();

// Make e2 as child of e1.
ByteBuffer eventId1 = e1.getEventId();
when(e2.getEventRefList()).thenReturn(Collections.singletonList(
EventRef.newBuilder().setEventId(eventId1).setRefType(EventRefType.CHILD_OF)
.setTraceId(traceId).build()));

//Making e3 as child of e2, follow_from construct
ByteBuffer eventId2 = e2.getEventId();
when(e3.getEventRefList()).thenReturn(Collections.singletonList(
EventRef.newBuilder().setEventId(eventId2).setRefType(EventRefType.FOLLOWS_FROM)
.setTraceId(traceId).build()));

StructuredTrace trace = StructuredTraceBuilder
.buildStructuredTraceFromRawSpans(List.of(rawSpan1, rawSpan2),
.buildStructuredTraceFromRawSpans(List.of(rawSpan1, rawSpan2,rawSpan3),
traceId,
CUSTOMER_ID);

assertEquals(traceId, trace.getTraceId());
assertEquals(CUSTOMER_ID, trace.getCustomerId());
assertEquals(2, trace.getEventList().size());
assertEquals(2, trace.getEntityList().size());
assertEquals(3, trace.getEventList().size());
assertEquals(3, trace.getEntityList().size());

StructuredTraceAssert.assertEntityEntityEdge(trace);
StructuredTraceAssert.assertEventEventEdge(trace);
StructuredTraceAssert.assertEntityEventEdges(trace);

StructuredTraceGraph graph = new StructuredTraceGraph(trace);
assertEquals(2, graph.getEventMap().size());
assertEquals(3, graph.getEventMap().size());
assertEquals(1, graph.getRootEntities().size());
assertEquals(1, graph.getRootEvents().size());
assertTrue(graph.getChildIdsToParentIds().containsKey(e2.getEventId()));
assertTrue(graph.getParentToChildEventIds().containsKey(e1.getEventId()));
Map<ByteBuffer,ByteBuffer> childIdToParentIds = graph.getChildIdsToParentIds();
Map<ByteBuffer,List<ByteBuffer>> parentToChildEventIds = graph.getParentToChildEventIds();
assertTrue(childIdToParentIds.containsKey(e2.getEventId()) && childIdToParentIds.containsKey(e3.getEventId()));
assertTrue(parentToChildEventIds.containsKey(e1.getEventId()) && parentToChildEventIds.containsKey(e2.getEventId()));
assertTrue(graph.getParentEntities(entity2).contains(entity1));
assertTrue(graph.getParentEntities(entity3).contains(entity2));
assertEquals(e1, graph.getParentEvent(e2));
assertEquals(e2, graph.getParentEvent(e3));
}

private ByteBuffer generateRandomId() {
Expand Down

0 comments on commit acf2c3d

Please sign in to comment.