diff --git a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/DefaultSpanJoinerBuilder.java b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/DefaultSpanJoinerBuilder.java index 46bcd6c3..8cae31c7 100644 --- a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/DefaultSpanJoinerBuilder.java +++ b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/DefaultSpanJoinerBuilder.java @@ -5,6 +5,7 @@ import static org.hypertrace.core.graphql.atttributes.scopes.HypertraceCoreAttributeScopeString.SPAN; import static org.hypertrace.core.graphql.span.joiner.MultipleSpanJoin.SPANS_KEY; import static org.hypertrace.core.graphql.span.joiner.SpanJoin.SPAN_KEY; +import static org.hypertrace.core.graphql.span.joiner.SpanSource.DOMAIN_EVENT_SPAN_VIEW; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ListMultimap; @@ -49,6 +50,7 @@ public class DefaultSpanJoinerBuilder implements SpanJoinerBuilder { private static final int ZERO_OFFSET = 0; + private static final String IS_ANOMALOUS_KEY = "isAnomalous"; private final SpanDao spanDao; private final GraphQlSelectionFinder selectionFinder; @@ -86,26 +88,29 @@ private class DefaultSpanJoiner implements SpanJoiner { @Override public Single> joinSpan( - Collection joinSources, SpanIdGetter spanIdGetter) { + Collection joinSources, SpanIdGetter spanIdGetter, SpanSource spanSource) { Function>> idsGetter = source -> spanIdGetter.getSpanId(source).map(List::of); - return this.joinSpans(joinSources, idsGetter, SPAN_KEY).map(this::reduceMap); + return this.joinSpans(joinSources, idsGetter, SPAN_KEY, spanSource).map(this::reduceMap); } @Override public Single> joinSpans( - Collection joinSources, MultipleSpanIdGetter multipleSpanIdGetter) { - return this.joinSpans(joinSources, multipleSpanIdGetter::getSpanIds, SPANS_KEY); + Collection joinSources, + MultipleSpanIdGetter multipleSpanIdGetter, + SpanSource spanSource) { + return this.joinSpans(joinSources, multipleSpanIdGetter::getSpanIds, SPANS_KEY, spanSource); } private Single> joinSpans( Collection joinSources, Function>> idsGetter, - String joinSpanKey) { + String joinSpanKey, + SpanSource spanSource) { return this.buildSourceToIdsMap(joinSources, idsGetter) .flatMap( sourceToSpanIdsMap -> - this.buildSpanRequest(sourceToSpanIdsMap, joinSpanKey) + this.buildSpanRequest(sourceToSpanIdsMap, joinSpanKey, spanSource) .flatMap(spanDao::getSpans) .map(this::buildSpanIdToSpanMap) .map( @@ -152,13 +157,15 @@ private Map buildSpanIdToSpanMap(SpanResultSet resultSet) { } private Single buildSpanRequest( - ListMultimap sourceToSpanIdsMultimap, String joinSpanKey) { + ListMultimap sourceToSpanIdsMultimap, + String joinSpanKey, + SpanSource spanSource) { Collection spanIds = sourceToSpanIdsMultimap.values().stream() .distinct() .collect(Collectors.toUnmodifiableList()); List selectedFields = getSelections(joinSpanKey); - return buildSpanIdsFilter(context, spanIds) + return buildSpanFilter(context, spanIds, spanSource) .flatMap( filterArguments -> buildSpanRequest(spanIds.size(), filterArguments, selectedFields)); } @@ -181,8 +188,14 @@ private Single buildSpanRequest( .map(spanEventsRequest -> new SpanJoinRequest(context, spanEventsRequest)); } - private Single>> buildSpanIdsFilter( - GraphQlRequestContext context, Collection spanIds) { + private Single>> buildSpanFilter( + GraphQlRequestContext context, Collection spanIds, SpanSource spanSource) { + if (DOMAIN_EVENT_SPAN_VIEW.equals(spanSource)) { + return filterRequestBuilder.build( + context, + SPAN, + Set.of(new DomainEventSpanViewSourceFilter(), new SpanIdFilter(spanIds))); + } return filterRequestBuilder.build(context, SPAN, Set.of(new SpanIdFilter(spanIds))); } } @@ -199,6 +212,18 @@ private static class SpanIdFilter implements FilterArgument { String idScope = SPAN; } + @Value + @Accessors(fluent = true) + private static class DomainEventSpanViewSourceFilter implements FilterArgument { + FilterType type = FilterType.ATTRIBUTE; + String key = null; + AttributeExpression keyExpression = new AttributeExpression(IS_ANOMALOUS_KEY, null); + FilterOperatorType operator = FilterOperatorType.EQUALS; + Boolean value = Boolean.TRUE; + AttributeScope idType = null; + String idScope = SPAN; + } + @Value @Accessors(fluent = true) private static class SpanJoinRequest implements SpanRequest { diff --git a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanJoiner.java b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanJoiner.java index 9997257a..1462d1df 100644 --- a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanJoiner.java +++ b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanJoiner.java @@ -16,21 +16,26 @@ public interface SpanJoiner { new SpanJoiner() { @Override public Single> joinSpan( - Collection joinSources, SpanIdGetter spanIdGetter) { + Collection joinSources, SpanIdGetter spanIdGetter, SpanSource spanSource) { return Single.just(Collections.emptyMap()); } @Override public Single> joinSpans( - Collection joinSources, MultipleSpanIdGetter multipleSpanIdGetter) { + Collection joinSources, + MultipleSpanIdGetter multipleSpanIdGetter, + SpanSource spanSource) { return Single.just(ArrayListMultimap.create()); } }; - Single> joinSpan(Collection joinSources, SpanIdGetter spanIdGetter); + Single> joinSpan( + Collection joinSources, SpanIdGetter spanIdGetter, SpanSource spanSource); Single> joinSpans( - Collection joinSources, MultipleSpanIdGetter multipleSpanIdGetter); + Collection joinSources, + MultipleSpanIdGetter multipleSpanIdGetter, + SpanSource spanSource); @FunctionalInterface interface SpanIdGetter { diff --git a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanSource.java b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanSource.java new file mode 100644 index 00000000..dc228060 --- /dev/null +++ b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/joiner/SpanSource.java @@ -0,0 +1,7 @@ +package org.hypertrace.core.graphql.span.joiner; + +public enum SpanSource { + SPAN_EVENT_VIEW, + DOMAIN_EVENT_SPAN_VIEW, + ; +} diff --git a/hypertrace-core-graphql-span-schema/src/test/java/org/hypertrace/core/graphql/span/joiner/SpanJoinerBuilderTest.java b/hypertrace-core-graphql-span-schema/src/test/java/org/hypertrace/core/graphql/span/joiner/SpanJoinerBuilderTest.java index eae7b19a..5209e1d8 100644 --- a/hypertrace-core-graphql-span-schema/src/test/java/org/hypertrace/core/graphql/span/joiner/SpanJoinerBuilderTest.java +++ b/hypertrace-core-graphql-span-schema/src/test/java/org/hypertrace/core/graphql/span/joiner/SpanJoinerBuilderTest.java @@ -3,6 +3,8 @@ import static java.util.Collections.emptyList; import static java.util.Map.entry; import static org.hypertrace.core.graphql.atttributes.scopes.HypertraceCoreAttributeScopeString.SPAN; +import static org.hypertrace.core.graphql.span.joiner.SpanSource.DOMAIN_EVENT_SPAN_VIEW; +import static org.hypertrace.core.graphql.span.joiner.SpanSource.SPAN_EVENT_VIEW; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anySet; @@ -112,7 +114,8 @@ void fetchSpans() { List.of("pathToSpan")) .blockingGet(); assertEquals( - expected, joiner.joinSpan(joinSources, new TestJoinSourceIdGetter()).blockingGet()); + expected, + joiner.joinSpan(joinSources, new TestJoinSourceIdGetter(), SPAN_EVENT_VIEW).blockingGet()); } @Test @@ -155,7 +158,9 @@ void fetchMultipleSpans() { .blockingGet(); assertEquals( expected, - joiner.joinSpans(joinSources, new TestMultipleJoinSourceIdGetter()).blockingGet()); + joiner + .joinSpans(joinSources, new TestMultipleJoinSourceIdGetter(), DOMAIN_EVENT_SPAN_VIEW) + .blockingGet()); } private void mockResult(List spans) {