Skip to content

Commit

Permalink
FIX: build service map relationship even when trace group is missing (o…
Browse files Browse the repository at this point in the history
…pensearch-project#4822)

Signed-off-by: George Chen <qchea@amazon.com>
  • Loading branch information
chenqi0805 authored Aug 12, 2024
1 parent be85abe commit aa50a1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private Collection<Record<Event>> iterateProcessorState(final MapDbProcessorStat
}

final String traceGroupName = getTraceGroupName(child.traceId);
if (traceGroupName == null || parent == null || parent.serviceName.equals(child.serviceName)) {
if (parent == null || parent.serviceName.equals(child.serviceName)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import static io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -301,7 +302,6 @@ public void testTraceGroupsWithEventRecordData() throws Exception {
assertThat(relationshipCountMeasurement.getValue(), equalTo((double)relationshipsFound.size()));


//Make sure that future relationships that are equivalent are caught by cache
final byte[] rootSpanId3Bytes = ServiceMapTestUtils.getRandomBytes(8);
final byte[] traceId3Bytes = ServiceMapTestUtils.getRandomBytes(16);
final String rootSpanId3 = Hex.encodeHexString(rootSpanId3Bytes);
Expand All @@ -312,19 +312,24 @@ public void testTraceGroupsWithEventRecordData() throws Exception {
AUTHENTICATION_SERVICE, "reset", Hex.encodeHexString(ServiceMapTestUtils.getRandomBytes(8)),
frontendSpans3.getSpanId(), traceId3, io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_SERVER);

// relationship missing traceGroupName
when(clock.millis()).thenReturn(450L);
Future<Set<ServiceMapRelationship>> r7 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1,
Collections.singletonList(new Record<>(frontendSpans3)));
Future<Set<ServiceMapRelationship>> r8 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2,
Collections.singletonList(new Record<>(authenticationSpansServer2)));
assertTrue(r7.get().isEmpty());
assertTrue(r8.get().isEmpty());
final Set<ServiceMapRelationship> relationshipsFoundWithNoTraceGroupName = new HashSet<>();
relationshipsFoundWithNoTraceGroupName.addAll(r7.get());
relationshipsFoundWithNoTraceGroupName.addAll(r8.get());

when(clock.millis()).thenReturn(560L);
Future<Set<ServiceMapRelationship>> r9 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1, Arrays.asList());
Future<Set<ServiceMapRelationship>> r10 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2, Arrays.asList());
assertTrue(r9.get().isEmpty());
assertTrue(r10.get().isEmpty());
relationshipsFoundWithNoTraceGroupName.addAll(r9.get());
relationshipsFoundWithNoTraceGroupName.addAll(r10.get());
assertThat(relationshipsFoundWithNoTraceGroupName.size(), equalTo(4));
relationshipsFoundWithNoTraceGroupName.forEach(
relationship -> assertThat(relationship.getTraceGroupName(), nullValue()));
serviceMapStateful1.shutdown();
serviceMapStateful2.shutdown();
}
Expand Down

0 comments on commit aa50a1d

Please sign in to comment.