Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore | Add support for selecting spanSource as DomainEventSpanView or SpanEventView in span join #180

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -86,26 +88,29 @@ private class DefaultSpanJoiner implements SpanJoiner {

@Override
public <T> Single<Map<T, Span>> joinSpan(
Collection<T> joinSources, SpanIdGetter<T> spanIdGetter) {
Collection<T> joinSources, SpanIdGetter<T> spanIdGetter, SpanSource spanSource) {
Function<T, Single<List<String>>> 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 <T> Single<ListMultimap<T, Span>> joinSpans(
Collection<T> joinSources, MultipleSpanIdGetter<T> multipleSpanIdGetter) {
return this.joinSpans(joinSources, multipleSpanIdGetter::getSpanIds, SPANS_KEY);
Collection<T> joinSources,
MultipleSpanIdGetter<T> multipleSpanIdGetter,
SpanSource spanSource) {
return this.joinSpans(joinSources, multipleSpanIdGetter::getSpanIds, SPANS_KEY, spanSource);
}

private <T> Single<ListMultimap<T, Span>> joinSpans(
Collection<T> joinSources,
Function<T, Single<List<String>>> 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(
Expand Down Expand Up @@ -152,13 +157,15 @@ private Map<String, Span> buildSpanIdToSpanMap(SpanResultSet resultSet) {
}

private <T> Single<SpanRequest> buildSpanRequest(
ListMultimap<T, String> sourceToSpanIdsMultimap, String joinSpanKey) {
ListMultimap<T, String> sourceToSpanIdsMultimap,
String joinSpanKey,
SpanSource spanSource) {
Collection<String> spanIds =
sourceToSpanIdsMultimap.values().stream()
.distinct()
.collect(Collectors.toUnmodifiableList());
List<SelectedField> selectedFields = getSelections(joinSpanKey);
return buildSpanIdsFilter(context, spanIds)
return buildSpanFilter(context, spanIds, spanSource)
.flatMap(
filterArguments -> buildSpanRequest(spanIds.size(), filterArguments, selectedFields));
}
Expand All @@ -181,8 +188,14 @@ private Single<SpanRequest> buildSpanRequest(
.map(spanEventsRequest -> new SpanJoinRequest(context, spanEventsRequest));
}

private Single<List<AttributeAssociation<FilterArgument>>> buildSpanIdsFilter(
GraphQlRequestContext context, Collection<String> spanIds) {
private Single<List<AttributeAssociation<FilterArgument>>> buildSpanFilter(
GraphQlRequestContext context, Collection<String> 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)));
}
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ public interface SpanJoiner {
new SpanJoiner() {
@Override
public <T> Single<Map<T, Span>> joinSpan(
Collection<T> joinSources, SpanIdGetter<T> spanIdGetter) {
Collection<T> joinSources, SpanIdGetter<T> spanIdGetter, SpanSource spanSource) {
return Single.just(Collections.emptyMap());
}

@Override
public <T> Single<ListMultimap<T, Span>> joinSpans(
Collection<T> joinSources, MultipleSpanIdGetter<T> multipleSpanIdGetter) {
Collection<T> joinSources,
MultipleSpanIdGetter<T> multipleSpanIdGetter,
SpanSource spanSource) {
return Single.just(ArrayListMultimap.create());
}
};

<T> Single<Map<T, Span>> joinSpan(Collection<T> joinSources, SpanIdGetter<T> spanIdGetter);
<T> Single<Map<T, Span>> joinSpan(
Collection<T> joinSources, SpanIdGetter<T> spanIdGetter, SpanSource spanSource);

<T> Single<ListMultimap<T, Span>> joinSpans(
Collection<T> joinSources, MultipleSpanIdGetter<T> multipleSpanIdGetter);
Collection<T> joinSources,
MultipleSpanIdGetter<T> multipleSpanIdGetter,
SpanSource spanSource);

@FunctionalInterface
interface SpanIdGetter<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hypertrace.core.graphql.span.joiner;

public enum SpanSource {
SPAN_EVENT_VIEW,
DOMAIN_EVENT_SPAN_VIEW,
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Span> spans) {
Expand Down
Loading