From 342e110ac683183141c76c0891aa9bb29525ac8f Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Mon, 27 Nov 2023 13:11:54 +0530 Subject: [PATCH 1/8] chore | adding the support for querying multi interaction filters --- hypertrace-core-graphql | 2 +- .../graphql/entity/dao/EntityDaoModule.java | 6 ++ ...erviceEntityInteractionRequestBuilder.java | 43 +++++++----- .../joiner/DefaultEntityJoinerBuilder.java | 3 +- .../entity/request/EdgeRequestBuilder.java | 70 +++++++++++-------- .../entity/request/EdgeSetGroupRequest.java | 4 +- .../DefaultEntityAndRuleJoinerBuilder.java | 3 +- 7 files changed, 80 insertions(+), 51 deletions(-) diff --git a/hypertrace-core-graphql b/hypertrace-core-graphql index 6f68e95d..fd15f6eb 160000 --- a/hypertrace-core-graphql +++ b/hypertrace-core-graphql @@ -1 +1 @@ -Subproject commit 6f68e95d677dd06da2e30bc25418a09ce0596b4c +Subproject commit fd15f6eb33f8f49a861f7d59d2a76e8c86514241 diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java index 965c306d..100193af 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java @@ -65,6 +65,12 @@ protected void configure() { new TypeLiteral< Converter>, Filter>>() {})); + requireBinding( + Key.get( + new TypeLiteral< + Converter< + Collection>>, Filter>>() {})); + requireBinding( Key.get( new TypeLiteral< diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java index d44cf876..70d2965d 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java @@ -5,6 +5,7 @@ import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; import java.util.Collection; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -31,13 +32,15 @@ class GatewayServiceEntityInteractionRequestBuilder { private final Converter, Set> selectionConverter; private final Converter, Set> aggregationConverter; - private final Converter>, Filter> filterConverter; + private final Converter>>, Filter> + filterConverter; @Inject GatewayServiceEntityInteractionRequestBuilder( Converter, Set> selectionConverter, Converter, Set> aggregationConverter, - Converter>, Filter> filterConverter) { + Converter>>, Filter> + filterConverter) { this.selectionConverter = selectionConverter; this.aggregationConverter = aggregationConverter; this.filterConverter = filterConverter; @@ -69,22 +72,28 @@ private Single> collectSelectionsAndAggregations(EdgeSetGroupReq } private Single buildEntityInteractionFilter(EdgeSetGroupRequest request) { - return Observable.fromIterable(request.entityTypes()) // add entity types filter - .collect(Collectors.toUnmodifiableSet()) + return this.filterConverter.convert(this.buildFilterArguments(request)); + } + + private Collection>> buildFilterArguments( + EdgeSetGroupRequest request) { + return request.filterArguments().entrySet().stream() .map( - entityTypes -> - AttributeAssociation.of( - request.neighborTypeAttribute().attributeExpressionAssociation().attribute(), - new EntityNeighborTypeFilter( - request.neighborTypeAttribute().attributeExpressionAssociation().value(), - entityTypes))) - .flatMap( - filterAssociation -> - this.filterConverter.convert( - Stream.concat( - request.filterArguments().stream(), // add all other filters - Stream.of(filterAssociation)) - .collect(Collectors.toUnmodifiableSet()))); + entry -> + Stream.concat( + Stream.of(buildEntityTypeFilter(request, entry.getKey())), + entry.getValue().stream()) + .collect(Collectors.toUnmodifiableList())) + .collect(Collectors.toUnmodifiableList()); + } + + private AttributeAssociation buildEntityTypeFilter( + EdgeSetGroupRequest request, String entityType) { + return AttributeAssociation.of( + request.neighborTypeAttribute().attributeExpressionAssociation().attribute(), + new EntityNeighborTypeFilter( + request.neighborTypeAttribute().attributeExpressionAssociation().value(), + List.of(entityType))); } @Value diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java index 0a5a2daf..ba17f9e6 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java @@ -320,7 +320,8 @@ private static class EmptyEdgeSetGroupRequest implements EdgeSetGroupRequest { Set entityTypes = Collections.emptySet(); Collection attributeRequests = Collections.emptyList(); Collection metricAggregationRequests = Collections.emptyList(); - Collection> filterArguments = Collections.emptyList(); + Map>> filterArguments = + Collections.emptyMap(); AttributeRequest neighborIdAttribute = null; AttributeRequest neighborTypeAttribute = null; diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java index 34611e5f..824d5df5 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java @@ -3,11 +3,11 @@ import static io.reactivex.rxjava3.core.Single.zip; import graphql.schema.SelectedField; -import io.grpc.Status; import io.reactivex.rxjava3.core.Single; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; @@ -89,31 +89,30 @@ private Single buildEdgeRequest( Stream edgeSetFields, EdgeType edgeType) { Set edgeFields = edgeSetFields.collect(Collectors.toUnmodifiableSet()); - List filterArguments = this.getFilters(edgeFields); - - if (!filterArguments.isEmpty() && edgeFields.size() > 1) { - throw Status.UNIMPLEMENTED - .withDescription("Cannot specify more than one edge type with edge filters") - .asRuntimeException(); - } - - Map> edgesByType = this.getEdgesByType(edgeFields.stream()); - Set allEdges = - edgesByType.values().stream() + Map> edgesSelectionsByType = + this.getEdgesSelectionByType(edgeFields.stream()); + Set allEdgesSelections = + edgesSelectionsByType.values().stream() .flatMap(Collection::stream) .collect(Collectors.toUnmodifiableSet()); + Map> edgesFiltersByType = + getEdgesFiltersByType(edgeFields.stream()); + Map>> filterArguments = + edgesFiltersByType.entrySet().stream() + .collect( + Collectors.toMap( + Entry::getKey, entry -> getFilterArguments(context, entry.getValue()))); return zip( - this.getRequestedAndRequiredAttributes(context, allEdges, edgeType), + this.getRequestedAndRequiredAttributes(context, allEdgesSelections, edgeType), this.getNeighborIdAttribute(context, edgeType), this.getNeighborTypeAttribute(context, edgeType), this.metricAggregationRequestBuilder.build( - context, HypertraceAttributeScopeString.INTERACTION, allEdges.stream()), - this.filterRequestBuilder.build( - context, HypertraceAttributeScopeString.INTERACTION, filterArguments), + context, HypertraceAttributeScopeString.INTERACTION, allEdgesSelections.stream()), + Single.just(filterArguments), (attributeRequests, neighborIdRequest, neighborTypeRequest, metricRequests, filters) -> new DefaultEdgeSetGroupRequest( - edgesByType.keySet(), + edgesSelectionsByType.keySet(), attributeRequests, metricRequests, neighborIdRequest, @@ -127,12 +126,12 @@ private Single buildEdgeRequest( timeRange, space, neighborIds, - edgesByType.get(entityType)), + edgesSelectionsByType.get(entityType)), filters)); } - private Map> getEdgesByType(Stream edgeSetStream) { - + private Map> getEdgesSelectionByType( + Stream edgeSetStream) { return edgeSetStream.collect( Collectors.groupingBy( this::getEntityType, @@ -183,15 +182,26 @@ private Single getNeighborIdAttribute( } } - private List getFilters(Set selectedFields) { - return selectedFields.stream() - .map( - selectedField -> - this.argumentDeserializer.deserializeObjectList( - selectedField.getArguments(), FilterArgument.class)) - .flatMap(Optional::stream) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableList()); + private List> getFilterArguments( + GraphQlRequestContext context, Set edgeFields) { + return this.filterRequestBuilder + .build(context, HypertraceAttributeScopeString.INTERACTION, edgeFields) + .blockingGet(); + } + + private Map> getEdgesFiltersByType( + Stream edgeSetStream) { + return edgeSetStream.collect( + Collectors.groupingBy( + this::getEntityType, + Collectors.flatMapping(this::getFilter, Collectors.toUnmodifiableSet()))); + } + + private Stream getFilter(SelectedField selectedField) { + return this.argumentDeserializer + .deserializeObjectList(selectedField.getArguments(), FilterArgument.class) + .stream() + .flatMap(Collection::stream); } private Single getNeighborTypeAttribute( @@ -227,7 +237,7 @@ private static class DefaultEdgeSetGroupRequest implements EdgeSetGroupRequest { AttributeRequest neighborIdAttribute; AttributeRequest neighborTypeAttribute; BiFunction, Single> neighborRequestBuilder; - Collection> filterArguments; + Map>> filterArguments; @Override public Single buildNeighborRequest( diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java index c6859008..c34c64d9 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java @@ -2,6 +2,7 @@ import io.reactivex.rxjava3.core.Single; import java.util.Collection; +import java.util.Map; import java.util.Set; import org.hypertrace.core.graphql.common.request.AttributeAssociation; import org.hypertrace.core.graphql.common.request.AttributeRequest; @@ -23,5 +24,6 @@ public interface EdgeSetGroupRequest { Single buildNeighborRequest(String entityType, Collection neighborIds); - Collection> filterArguments(); + // map of filters. All map values will become OR filter and all filter arguments will be AND + Map>> filterArguments(); } diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java index a15737a6..feb7deab 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java @@ -319,7 +319,8 @@ private static class EmptyEdgeSetGroupRequest implements EdgeSetGroupRequest { Set entityTypes = Collections.emptySet(); Collection attributeRequests = Collections.emptyList(); Collection metricAggregationRequests = Collections.emptyList(); - Collection> filterArguments = Collections.emptyList(); + Map>> filterArguments = + Collections.emptyMap(); AttributeRequest neighborIdAttribute = null; AttributeRequest neighborTypeAttribute = null; From c26bba57326e10372ccca7b523495f63a793dcb4 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Mon, 27 Nov 2023 21:10:53 +0530 Subject: [PATCH 2/8] fixing the request builder --- hypertrace-core-graphql | 2 +- .../graphql/entity/dao/EntityDaoModule.java | 6 ----- ...erviceEntityInteractionRequestBuilder.java | 23 ++++++++++--------- .../entity/request/EdgeRequestBuilder.java | 23 +++++++++++-------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/hypertrace-core-graphql b/hypertrace-core-graphql index fd15f6eb..beeb208f 160000 --- a/hypertrace-core-graphql +++ b/hypertrace-core-graphql @@ -1 +1 @@ -Subproject commit fd15f6eb33f8f49a861f7d59d2a76e8c86514241 +Subproject commit beeb208f19cf46b7e7f001e59abdf7be18209e44 diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java index 100193af..965c306d 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/EntityDaoModule.java @@ -65,12 +65,6 @@ protected void configure() { new TypeLiteral< Converter>, Filter>>() {})); - requireBinding( - Key.get( - new TypeLiteral< - Converter< - Collection>>, Filter>>() {})); - requireBinding( Key.get( new TypeLiteral< diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java index 70d2965d..b946e0d2 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java @@ -22,6 +22,7 @@ import org.hypertrace.core.graphql.common.utils.Converter; import org.hypertrace.gateway.service.v1.common.Expression; import org.hypertrace.gateway.service.v1.common.Filter; +import org.hypertrace.gateway.service.v1.common.Operator; import org.hypertrace.gateway.service.v1.entity.InteractionsRequest; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; @@ -32,15 +33,13 @@ class GatewayServiceEntityInteractionRequestBuilder { private final Converter, Set> selectionConverter; private final Converter, Set> aggregationConverter; - private final Converter>>, Filter> - filterConverter; + private final Converter>, Filter> filterConverter; @Inject GatewayServiceEntityInteractionRequestBuilder( Converter, Set> selectionConverter, Converter, Set> aggregationConverter, - Converter>>, Filter> - filterConverter) { + Converter>, Filter> filterConverter) { this.selectionConverter = selectionConverter; this.aggregationConverter = aggregationConverter; this.filterConverter = filterConverter; @@ -72,19 +71,21 @@ private Single> collectSelectionsAndAggregations(EdgeSetGroupReq } private Single buildEntityInteractionFilter(EdgeSetGroupRequest request) { - return this.filterConverter.convert(this.buildFilterArguments(request)); - } - - private Collection>> buildFilterArguments( - EdgeSetGroupRequest request) { - return request.filterArguments().entrySet().stream() + return Observable.fromIterable(request.filterArguments().entrySet()) .map( entry -> Stream.concat( Stream.of(buildEntityTypeFilter(request, entry.getKey())), entry.getValue().stream()) .collect(Collectors.toUnmodifiableList())) - .collect(Collectors.toUnmodifiableList()); + .flatMapSingle(this.filterConverter::convert) + .collect(Collectors.toUnmodifiableList()) + .map( + childFilters -> + Filter.newBuilder() + .setOperator(Operator.OR) + .addAllChildFilter(childFilters) + .build()); } private AttributeAssociation buildEntityTypeFilter( diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java index 824d5df5..32880e33 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java @@ -3,6 +3,7 @@ import static io.reactivex.rxjava3.core.Single.zip; import graphql.schema.SelectedField; +import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; import java.util.Collection; import java.util.List; @@ -98,18 +99,14 @@ private Single buildEdgeRequest( Map> edgesFiltersByType = getEdgesFiltersByType(edgeFields.stream()); - Map>> filterArguments = - edgesFiltersByType.entrySet().stream() - .collect( - Collectors.toMap( - Entry::getKey, entry -> getFilterArguments(context, entry.getValue()))); + return zip( this.getRequestedAndRequiredAttributes(context, allEdgesSelections, edgeType), this.getNeighborIdAttribute(context, edgeType), this.getNeighborTypeAttribute(context, edgeType), this.metricAggregationRequestBuilder.build( context, HypertraceAttributeScopeString.INTERACTION, allEdgesSelections.stream()), - Single.just(filterArguments), + this.getFilterArguments(context, edgesFiltersByType), (attributeRequests, neighborIdRequest, neighborTypeRequest, metricRequests, filters) -> new DefaultEdgeSetGroupRequest( edgesSelectionsByType.keySet(), @@ -182,11 +179,19 @@ private Single getNeighborIdAttribute( } } - private List> getFilterArguments( - GraphQlRequestContext context, Set edgeFields) { + private Single>>> getFilterArguments( + GraphQlRequestContext context, Map> edgesFiltersByType) { + return Observable.fromIterable(edgesFiltersByType.entrySet()) + .flatMapSingle(entry -> getFilterArgumentsEntry(context, entry.getKey(), entry.getValue())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + } + + private Single>>> + getFilterArgumentsEntry( + GraphQlRequestContext context, String key, Set edgeFields) { return this.filterRequestBuilder .build(context, HypertraceAttributeScopeString.INTERACTION, edgeFields) - .blockingGet(); + .map(arguments -> Map.entry(key, arguments)); } private Map> getEdgesFiltersByType( From 4dd9616a4f070da456de114d1b394e70e253e94d Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Mon, 27 Nov 2023 23:14:33 +0530 Subject: [PATCH 3/8] review comments --- .../GatewayServiceEntityInteractionRequestBuilder.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java index b946e0d2..a3953dc1 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java @@ -5,7 +5,6 @@ import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; import java.util.Collection; -import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -71,6 +70,7 @@ private Single> collectSelectionsAndAggregations(EdgeSetGroupReq } private Single buildEntityInteractionFilter(EdgeSetGroupRequest request) { + // Todo: we should be using converter taking argument as logical filters with filter arg schema return Observable.fromIterable(request.filterArguments().entrySet()) .map( entry -> @@ -93,8 +93,7 @@ private AttributeAssociation buildEntityTypeFilter( return AttributeAssociation.of( request.neighborTypeAttribute().attributeExpressionAssociation().attribute(), new EntityNeighborTypeFilter( - request.neighborTypeAttribute().attributeExpressionAssociation().value(), - List.of(entityType))); + request.neighborTypeAttribute().attributeExpressionAssociation().value(), entityType)); } @Value @@ -103,8 +102,8 @@ private static class EntityNeighborTypeFilter implements FilterArgument { FilterType type = FilterType.ATTRIBUTE; String key = null; AttributeExpression keyExpression; - FilterOperatorType operator = FilterOperatorType.IN; - Collection value; + FilterOperatorType operator = FilterOperatorType.EQUALS; + String value; AttributeScope idType = null; String idScope = null; } From f75f8fa9372a72e6e5b78d842d895f85c451da68 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 28 Nov 2023 01:24:42 +0530 Subject: [PATCH 4/8] making one single edge request --- .../dao/GatewayServiceEntityEdgeFetcher.java | 15 ++- ...erviceEntityInteractionRequestBuilder.java | 27 ++++- .../joiner/DefaultEntityJoinerBuilder.java | 8 +- .../entity/request/EdgeRequestBuilder.java | 107 +++++++++++------- .../entity/request/EdgeSetGroupRequest.java | 15 +-- .../entity/request/EdgeSetRequest.java | 17 +++ .../DefaultEntityAndRuleJoinerBuilder.java | 8 +- 7 files changed, 121 insertions(+), 76 deletions(-) create mode 100644 hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetRequest.java diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java index ae723f78..345b3489 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; class GatewayServiceEntityEdgeFetcher { + private static final Logger LOG = LoggerFactory.getLogger(GatewayServiceEntityEdgeFetcher.class); static final EdgeResultSet EMPTY_EDGE_RESULT_SET = new ConvertedEdgeResultSet(List.of()); @@ -119,9 +120,17 @@ private Maybe buildEdge( return zip( this.attributeMapConverter.convert( - edgeSetGroupRequest.attributeRequests(), response.getAttributeMap()), + edgeSetGroupRequest + .edgeSetRequests() + .get(source.getEntityType()) + .attributeRequests(), + response.getAttributeMap()), this.baselineMetricAggregationContainerMapConverter.convert( - edgeSetGroupRequest.metricAggregationRequests(), response.getMetricsMap()), + edgeSetGroupRequest + .edgeSetRequests() + .get(source.getEntityType()) + .metricAggregationRequests(), + response.getMetricsMap()), (attributes, metrics) -> (Edge) new ConvertedEdge(neighbor, attributes, metrics)) .toMaybe(); } @@ -129,6 +138,7 @@ private Maybe buildEdge( @lombok.Value @Accessors(fluent = true) private static class ConvertedEdge implements Edge { + Entity neighbor; Map attributeValues; Map metricContainers; @@ -147,6 +157,7 @@ public BaselinedMetricAggregationContainer metric(AttributeExpression attributeE @lombok.Value @Accessors(fluent = true) private static class ConvertedEdgeResultSet implements EdgeResultSet { + List results; @Override diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java index a3953dc1..f71a3ec1 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java @@ -24,6 +24,7 @@ import org.hypertrace.gateway.service.v1.common.Operator; import org.hypertrace.gateway.service.v1.entity.InteractionsRequest; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; +import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; class GatewayServiceEntityInteractionRequestBuilder { @@ -45,7 +46,7 @@ class GatewayServiceEntityInteractionRequestBuilder { } Single build(EdgeSetGroupRequest edgeSetRequestGroup) { - if (edgeSetRequestGroup.entityTypes().isEmpty()) { + if (edgeSetRequestGroup.edgeSetRequests().isEmpty()) { return Single.just(InteractionsRequest.getDefaultInstance()); } @@ -62,21 +63,36 @@ Single build(EdgeSetGroupRequest edgeSetRequestGroup) { private Single> collectSelectionsAndAggregations(EdgeSetGroupRequest request) { return this.selectionConverter - .convert(request.attributeRequests()) - .mergeWith(this.aggregationConverter.convert(request.metricAggregationRequests())) + .convert(getAllAttributeRequests(request)) + .mergeWith(this.aggregationConverter.convert(getAllMetricAggregationRequests(request))) .toObservable() .flatMap(Observable::fromIterable) .collect(Collectors.toUnmodifiableSet()); } + private Set getAllAttributeRequests(EdgeSetGroupRequest request) { + return request.edgeSetRequests().values().stream() + .map(EdgeSetRequest::attributeRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + + private Set getAllMetricAggregationRequests( + EdgeSetGroupRequest request) { + return request.edgeSetRequests().values().stream() + .map(EdgeSetRequest::metricAggregationRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + private Single buildEntityInteractionFilter(EdgeSetGroupRequest request) { // Todo: we should be using converter taking argument as logical filters with filter arg schema - return Observable.fromIterable(request.filterArguments().entrySet()) + return Observable.fromIterable(request.edgeSetRequests().entrySet()) .map( entry -> Stream.concat( Stream.of(buildEntityTypeFilter(request, entry.getKey())), - entry.getValue().stream()) + entry.getValue().filterArguments().stream()) .collect(Collectors.toUnmodifiableList())) .flatMapSingle(this.filterConverter::convert) .collect(Collectors.toUnmodifiableList()) @@ -99,6 +115,7 @@ private AttributeAssociation buildEntityTypeFilter( @Value @Accessors(fluent = true) private static class EntityNeighborTypeFilter implements FilterArgument { + FilterType type = FilterType.ATTRIBUTE; String key = null; AttributeExpression keyExpression; diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java index ba17f9e6..8a24ce58 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java @@ -52,6 +52,7 @@ import org.hypertrace.core.graphql.utils.schema.SelectionQuery; import org.hypertrace.graphql.entity.dao.EntityDao; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; +import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.entity.request.EntityLabelRequest; import org.hypertrace.graphql.entity.request.EntityLabelRequestBuilder; import org.hypertrace.graphql.entity.request.EntityRequest; @@ -59,7 +60,6 @@ import org.hypertrace.graphql.entity.schema.EntityJoinable; import org.hypertrace.graphql.entity.schema.EntityResultSet; import org.hypertrace.graphql.entity.schema.argument.EntityTypeStringArgument; -import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.request.MetricRequestBuilder; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; @@ -317,13 +317,9 @@ private static class DefaultEntityRequest implements EntityRequest { @Value @Accessors(fluent = true) private static class EmptyEdgeSetGroupRequest implements EdgeSetGroupRequest { - Set entityTypes = Collections.emptySet(); - Collection attributeRequests = Collections.emptyList(); - Collection metricAggregationRequests = Collections.emptyList(); - Map>> filterArguments = - Collections.emptyMap(); AttributeRequest neighborIdAttribute = null; AttributeRequest neighborTypeAttribute = null; + Map edgeSetRequests = Collections.emptyMap(); @Override public Single buildNeighborRequest( diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java index 32880e33..50aa73c3 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java @@ -92,28 +92,16 @@ private Single buildEdgeRequest( Set edgeFields = edgeSetFields.collect(Collectors.toUnmodifiableSet()); Map> edgesSelectionsByType = this.getEdgesSelectionByType(edgeFields.stream()); - Set allEdgesSelections = - edgesSelectionsByType.values().stream() - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - - Map> edgesFiltersByType = - getEdgesFiltersByType(edgeFields.stream()); return zip( - this.getRequestedAndRequiredAttributes(context, allEdgesSelections, edgeType), this.getNeighborIdAttribute(context, edgeType), this.getNeighborTypeAttribute(context, edgeType), - this.metricAggregationRequestBuilder.build( - context, HypertraceAttributeScopeString.INTERACTION, allEdgesSelections.stream()), - this.getFilterArguments(context, edgesFiltersByType), - (attributeRequests, neighborIdRequest, neighborTypeRequest, metricRequests, filters) -> + this.getEntityTypeToEdgeSetRequest(context, edgeType, edgeFields), + (neighborIdRequest, neighborTypeRequest, edgeRequests) -> new DefaultEdgeSetGroupRequest( - edgesSelectionsByType.keySet(), - attributeRequests, - metricRequests, neighborIdRequest, neighborTypeRequest, + edgeRequests, (entityType, neighborIds) -> this.neighborEntitiesRequestBuilderProvider .get() @@ -123,8 +111,36 @@ private Single buildEdgeRequest( timeRange, space, neighborIds, - edgesSelectionsByType.get(entityType)), - filters)); + edgesSelectionsByType.get(entityType)))); + } + + private Single> getEntityTypeToEdgeSetRequest( + GraphQlRequestContext context, EdgeType edgeType, Set edgeFields) { + return Observable.fromIterable(edgeFields) + .collect(Collectors.groupingBy(this::getEntityType, Collectors.toUnmodifiableSet())) + .flatMap(entry -> this.getEdgeSetRequest(context, edgeType, entry)); + } + + private Single> getEdgeSetRequest( + GraphQlRequestContext context, + EdgeType edgeType, + Map> edgeFields) { + return Observable.fromIterable(edgeFields.entrySet()) + .flatMapSingle( + entry -> + this.getEdgeSetRequestEntry(context, edgeType, entry.getKey(), entry.getValue())) + .collect(Collectors.toUnmodifiableMap(Entry::getKey, Entry::getValue)); + } + + private Single> getEdgeSetRequestEntry( + GraphQlRequestContext context, EdgeType edgeType, String key, Set edgeFields) { + return zip( + this.getRequestedAndRequiredAttributes(context, edgeFields, edgeType), + this.getMetricAggregationRequestAttributes(context, edgeFields, edgeType), + this.getFilterArguments(context, edgeFields), + (requestAttributes, metricAttributes, filters) -> + Map.entry( + key, new DefaultEdgeSetRequest(requestAttributes, metricAttributes, filters))); } private Map> getEdgesSelectionByType( @@ -151,11 +167,25 @@ private String getEntityType(SelectedField edgeSetField) { .orElseThrow(); } + private Single> getMetricAggregationRequestAttributes( + GraphQlRequestContext context, Collection edges, EdgeType edgeType) { + Set selections = + edges.stream() + .collect( + Collectors.flatMapping(this::getEdgesForEdgeSet, Collectors.toUnmodifiableSet())); + return this.metricAggregationRequestBuilder.build( + context, HypertraceAttributeScopeString.INTERACTION, selections.stream()); + } + private Single> getRequestedAndRequiredAttributes( GraphQlRequestContext context, Collection edges, EdgeType edgeType) { + Set selections = + edges.stream() + .collect( + Collectors.flatMapping(this::getEdgesForEdgeSet, Collectors.toUnmodifiableSet())); return this.attributeRequestBuilder .buildForAttributeQueryableFields( - context, HypertraceAttributeScopeString.INTERACTION, edges.stream()) + context, HypertraceAttributeScopeString.INTERACTION, selections.stream()) .mergeWith(this.getNeighborIdAttribute(context, edgeType)) .mergeWith(this.getNeighborTypeAttribute(context, edgeType)) .collect(Collectors.toUnmodifiableList()); @@ -179,27 +209,14 @@ private Single getNeighborIdAttribute( } } - private Single>>> getFilterArguments( - GraphQlRequestContext context, Map> edgesFiltersByType) { - return Observable.fromIterable(edgesFiltersByType.entrySet()) - .flatMapSingle(entry -> getFilterArgumentsEntry(context, entry.getKey(), entry.getValue())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - } - - private Single>>> - getFilterArgumentsEntry( - GraphQlRequestContext context, String key, Set edgeFields) { - return this.filterRequestBuilder - .build(context, HypertraceAttributeScopeString.INTERACTION, edgeFields) - .map(arguments -> Map.entry(key, arguments)); - } + private Single>> getFilterArguments( + GraphQlRequestContext context, Set edgeFields) { + Set filterArguments = + edgeFields.stream() + .collect(Collectors.flatMapping(this::getFilter, Collectors.toUnmodifiableSet())); - private Map> getEdgesFiltersByType( - Stream edgeSetStream) { - return edgeSetStream.collect( - Collectors.groupingBy( - this::getEntityType, - Collectors.flatMapping(this::getFilter, Collectors.toUnmodifiableSet()))); + return this.filterRequestBuilder.build( + context, HypertraceAttributeScopeString.INTERACTION, filterArguments); } private Stream getFilter(SelectedField selectedField) { @@ -235,14 +252,10 @@ private enum EdgeType { @Value @Accessors(fluent = true) private static class DefaultEdgeSetGroupRequest implements EdgeSetGroupRequest { - - Set entityTypes; - Collection attributeRequests; - Collection metricAggregationRequests; AttributeRequest neighborIdAttribute; AttributeRequest neighborTypeAttribute; + Map edgeSetRequests; BiFunction, Single> neighborRequestBuilder; - Map>> filterArguments; @Override public Single buildNeighborRequest( @@ -250,4 +263,12 @@ public Single buildNeighborRequest( return this.neighborRequestBuilder.apply(entityType, neighborIds); } } + + @Value + @Accessors(fluent = true) + private static class DefaultEdgeSetRequest implements EdgeSetRequest { + Collection attributeRequests; + Collection metricAggregationRequests; + Collection> filterArguments; + } } diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java index c34c64d9..b5075fbb 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java @@ -3,27 +3,14 @@ import io.reactivex.rxjava3.core.Single; import java.util.Collection; import java.util.Map; -import java.util.Set; -import org.hypertrace.core.graphql.common.request.AttributeAssociation; import org.hypertrace.core.graphql.common.request.AttributeRequest; -import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument; -import org.hypertrace.graphql.metric.request.MetricAggregationRequest; public interface EdgeSetGroupRequest { - - Set entityTypes(); - - // Includes neighbor id and type - Collection attributeRequests(); - - Collection metricAggregationRequests(); - AttributeRequest neighborIdAttribute(); AttributeRequest neighborTypeAttribute(); Single buildNeighborRequest(String entityType, Collection neighborIds); - // map of filters. All map values will become OR filter and all filter arguments will be AND - Map>> filterArguments(); + Map edgeSetRequests(); } diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetRequest.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetRequest.java new file mode 100644 index 00000000..9ca1a375 --- /dev/null +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetRequest.java @@ -0,0 +1,17 @@ +package org.hypertrace.graphql.entity.request; + +import java.util.Collection; +import org.hypertrace.core.graphql.common.request.AttributeAssociation; +import org.hypertrace.core.graphql.common.request.AttributeRequest; +import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument; +import org.hypertrace.graphql.metric.request.MetricAggregationRequest; + +public interface EdgeSetRequest { + // list of filter arguments + Collection> filterArguments(); + + // Includes neighbor id and type + Collection attributeRequests(); + + Collection metricAggregationRequests(); +} diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java index feb7deab..0cd0c575 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java @@ -44,6 +44,7 @@ import org.hypertrace.core.graphql.utils.schema.SelectionQuery; import org.hypertrace.graphql.entity.dao.EntityDao; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; +import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.entity.request.EntityLabelRequest; import org.hypertrace.graphql.entity.request.EntityRequest; import org.hypertrace.graphql.entity.schema.EntityResultSet; @@ -55,7 +56,6 @@ import org.hypertrace.graphql.label.schema.LabelResultSet; import org.hypertrace.graphql.label.schema.rule.LabelApplicationRule; import org.hypertrace.graphql.label.schema.rule.LabelApplicationRuleResultSet; -import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; @@ -316,13 +316,9 @@ private static class DefaultEntityRequest implements EntityRequest { @Value @Accessors(fluent = true) private static class EmptyEdgeSetGroupRequest implements EdgeSetGroupRequest { - Set entityTypes = Collections.emptySet(); - Collection attributeRequests = Collections.emptyList(); - Collection metricAggregationRequests = Collections.emptyList(); - Map>> filterArguments = - Collections.emptyMap(); AttributeRequest neighborIdAttribute = null; AttributeRequest neighborTypeAttribute = null; + Map edgeSetRequests = Collections.emptyMap(); @Override public Single buildNeighborRequest( From f09520e3ad9a3a6340f8364963bef4c8de9f7b85 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 28 Nov 2023 10:45:16 +0530 Subject: [PATCH 5/8] refactoring few things --- .../entity/request/EdgeRequestBuilder.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java index 50aa73c3..62c6764c 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java @@ -118,14 +118,14 @@ private Single> getEntityTypeToEdgeSetRequest( GraphQlRequestContext context, EdgeType edgeType, Set edgeFields) { return Observable.fromIterable(edgeFields) .collect(Collectors.groupingBy(this::getEntityType, Collectors.toUnmodifiableSet())) - .flatMap(entry -> this.getEdgeSetRequest(context, edgeType, entry)); + .flatMap(edgeFieldsMap -> this.getEdgeSetRequestMap(context, edgeType, edgeFieldsMap)); } - private Single> getEdgeSetRequest( + private Single> getEdgeSetRequestMap( GraphQlRequestContext context, EdgeType edgeType, - Map> edgeFields) { - return Observable.fromIterable(edgeFields.entrySet()) + Map> entityTypeToEdgeFieldsMap) { + return Observable.fromIterable(entityTypeToEdgeFieldsMap.entrySet()) .flatMapSingle( entry -> this.getEdgeSetRequestEntry(context, edgeType, entry.getKey(), entry.getValue())) @@ -133,14 +133,18 @@ private Single> getEdgeSetRequest( } private Single> getEdgeSetRequestEntry( - GraphQlRequestContext context, EdgeType edgeType, String key, Set edgeFields) { + GraphQlRequestContext context, + EdgeType edgeType, + String entityType, + Set edgeFields) { return zip( this.getRequestedAndRequiredAttributes(context, edgeFields, edgeType), - this.getMetricAggregationRequestAttributes(context, edgeFields, edgeType), + this.getMetricAggregationRequestAttributes(context, edgeFields), this.getFilterArguments(context, edgeFields), (requestAttributes, metricAttributes, filters) -> Map.entry( - key, new DefaultEdgeSetRequest(requestAttributes, metricAttributes, filters))); + entityType, + new DefaultEdgeSetRequest(requestAttributes, metricAttributes, filters))); } private Map> getEdgesSelectionByType( @@ -168,7 +172,7 @@ private String getEntityType(SelectedField edgeSetField) { } private Single> getMetricAggregationRequestAttributes( - GraphQlRequestContext context, Collection edges, EdgeType edgeType) { + GraphQlRequestContext context, Collection edges) { Set selections = edges.stream() .collect( From c016ff5ff9a4f076bb57fc910533b78a1338ca7f Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 28 Nov 2023 11:22:02 +0530 Subject: [PATCH 6/8] fixing the entity edge fetcher --- .../dao/GatewayServiceEntityEdgeFetcher.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java index 345b3489..b7590dfe 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.stream.Collectors; import javax.inject.Inject; import lombok.experimental.Accessors; @@ -21,6 +22,7 @@ import org.hypertrace.gateway.service.v1.common.Value; import org.hypertrace.gateway.service.v1.entity.EntityInteraction; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; +import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.entity.schema.Edge; import org.hypertrace.graphql.entity.schema.EdgeResultSet; import org.hypertrace.graphql.entity.schema.Entity; @@ -120,21 +122,28 @@ private Maybe buildEdge( return zip( this.attributeMapConverter.convert( - edgeSetGroupRequest - .edgeSetRequests() - .get(source.getEntityType()) - .attributeRequests(), - response.getAttributeMap()), + getAllAttributeRequests(edgeSetGroupRequest), response.getAttributeMap()), this.baselineMetricAggregationContainerMapConverter.convert( - edgeSetGroupRequest - .edgeSetRequests() - .get(source.getEntityType()) - .metricAggregationRequests(), - response.getMetricsMap()), + getAllMetricAggregationRequests(edgeSetGroupRequest), response.getMetricsMap()), (attributes, metrics) -> (Edge) new ConvertedEdge(neighbor, attributes, metrics)) .toMaybe(); } + private Set getAllAttributeRequests(EdgeSetGroupRequest request) { + return request.edgeSetRequests().values().stream() + .map(EdgeSetRequest::attributeRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + + private Set getAllMetricAggregationRequests( + EdgeSetGroupRequest request) { + return request.edgeSetRequests().values().stream() + .map(EdgeSetRequest::metricAggregationRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + @lombok.Value @Accessors(fluent = true) private static class ConvertedEdge implements Edge { From 7c265676d9ea1f5d50bc95036eeb1103b7269e30 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 28 Nov 2023 13:21:48 +0530 Subject: [PATCH 7/8] fixing the request --- .../dao/GatewayServiceEntityEdgeFetcher.java | 21 ++----------------- ...erviceEntityInteractionRequestBuilder.java | 20 ++---------------- .../joiner/DefaultEntityJoinerBuilder.java | 11 ++++++++++ .../entity/request/EdgeRequestBuilder.java | 16 ++++++++++++++ .../entity/request/EdgeSetGroupRequest.java | 5 +++++ .../DefaultEntityAndRuleJoinerBuilder.java | 11 ++++++++++ 6 files changed, 47 insertions(+), 37 deletions(-) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java index b7590dfe..f28661c0 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.stream.Collectors; import javax.inject.Inject; import lombok.experimental.Accessors; @@ -22,7 +21,6 @@ import org.hypertrace.gateway.service.v1.common.Value; import org.hypertrace.gateway.service.v1.entity.EntityInteraction; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; -import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.entity.schema.Edge; import org.hypertrace.graphql.entity.schema.EdgeResultSet; import org.hypertrace.graphql.entity.schema.Entity; @@ -122,28 +120,13 @@ private Maybe buildEdge( return zip( this.attributeMapConverter.convert( - getAllAttributeRequests(edgeSetGroupRequest), response.getAttributeMap()), + edgeSetGroupRequest.getAllAttributeRequests(), response.getAttributeMap()), this.baselineMetricAggregationContainerMapConverter.convert( - getAllMetricAggregationRequests(edgeSetGroupRequest), response.getMetricsMap()), + edgeSetGroupRequest.getAllMetricAggregationRequests(), response.getMetricsMap()), (attributes, metrics) -> (Edge) new ConvertedEdge(neighbor, attributes, metrics)) .toMaybe(); } - private Set getAllAttributeRequests(EdgeSetGroupRequest request) { - return request.edgeSetRequests().values().stream() - .map(EdgeSetRequest::attributeRequests) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - } - - private Set getAllMetricAggregationRequests( - EdgeSetGroupRequest request) { - return request.edgeSetRequests().values().stream() - .map(EdgeSetRequest::metricAggregationRequests) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - } - @lombok.Value @Accessors(fluent = true) private static class ConvertedEdge implements Edge { diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java index f71a3ec1..239265a3 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java @@ -24,7 +24,6 @@ import org.hypertrace.gateway.service.v1.common.Operator; import org.hypertrace.gateway.service.v1.entity.InteractionsRequest; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; -import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; class GatewayServiceEntityInteractionRequestBuilder { @@ -63,28 +62,13 @@ Single build(EdgeSetGroupRequest edgeSetRequestGroup) { private Single> collectSelectionsAndAggregations(EdgeSetGroupRequest request) { return this.selectionConverter - .convert(getAllAttributeRequests(request)) - .mergeWith(this.aggregationConverter.convert(getAllMetricAggregationRequests(request))) + .convert(request.getAllAttributeRequests()) + .mergeWith(this.aggregationConverter.convert(request.getAllMetricAggregationRequests())) .toObservable() .flatMap(Observable::fromIterable) .collect(Collectors.toUnmodifiableSet()); } - private Set getAllAttributeRequests(EdgeSetGroupRequest request) { - return request.edgeSetRequests().values().stream() - .map(EdgeSetRequest::attributeRequests) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - } - - private Set getAllMetricAggregationRequests( - EdgeSetGroupRequest request) { - return request.edgeSetRequests().values().stream() - .map(EdgeSetRequest::metricAggregationRequests) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - } - private Single buildEntityInteractionFilter(EdgeSetGroupRequest request) { // Todo: we should be using converter taking argument as logical filters with filter arg schema return Observable.fromIterable(request.edgeSetRequests().entrySet()) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java index 8a24ce58..23a2cc22 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java @@ -60,6 +60,7 @@ import org.hypertrace.graphql.entity.schema.EntityJoinable; import org.hypertrace.graphql.entity.schema.EntityResultSet; import org.hypertrace.graphql.entity.schema.argument.EntityTypeStringArgument; +import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.request.MetricRequestBuilder; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; @@ -328,6 +329,16 @@ public Single buildNeighborRequest( new UnsupportedOperationException( "Does not support fetching neighbors for joined entities")); } + + @Override + public Collection getAllAttributeRequests() { + return Collections.emptyList(); + } + + @Override + public Collection getAllMetricAggregationRequests() { + return Collections.emptyList(); + } } @Value diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java index 62c6764c..50935c02 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java @@ -266,6 +266,22 @@ public Single buildNeighborRequest( String entityType, Collection neighborIds) { return this.neighborRequestBuilder.apply(entityType, neighborIds); } + + @Override + public Collection getAllAttributeRequests() { + return this.edgeSetRequests.values().stream() + .map(EdgeSetRequest::attributeRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + + @Override + public Collection getAllMetricAggregationRequests() { + return this.edgeSetRequests.values().stream() + .map(EdgeSetRequest::metricAggregationRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } } @Value diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java index b5075fbb..4fb23806 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.Map; import org.hypertrace.core.graphql.common.request.AttributeRequest; +import org.hypertrace.graphql.metric.request.MetricAggregationRequest; public interface EdgeSetGroupRequest { AttributeRequest neighborIdAttribute(); @@ -13,4 +14,8 @@ public interface EdgeSetGroupRequest { Single buildNeighborRequest(String entityType, Collection neighborIds); Map edgeSetRequests(); + + Collection getAllAttributeRequests(); + + Collection getAllMetricAggregationRequests(); } diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java index 0cd0c575..e09db042 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java @@ -56,6 +56,7 @@ import org.hypertrace.graphql.label.schema.LabelResultSet; import org.hypertrace.graphql.label.schema.rule.LabelApplicationRule; import org.hypertrace.graphql.label.schema.rule.LabelApplicationRuleResultSet; +import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; @@ -327,6 +328,16 @@ public Single buildNeighborRequest( new UnsupportedOperationException( "Does not support fetching neighbors for joined entities")); } + + @Override + public Collection getAllAttributeRequests() { + return Collections.emptyList(); + } + + @Override + public Collection getAllMetricAggregationRequests() { + return Collections.emptyList(); + } } @Value From b64cb30d6c87b2d3a2fc8e759ed824ae7841afa7 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 28 Nov 2023 22:28:53 +0530 Subject: [PATCH 8/8] fix the request --- .../dao/GatewayServiceEntityEdgeFetcher.java | 9 +++++++-- ...erviceEntityInteractionRequestBuilder.java | 20 +++++++++++++++++-- .../joiner/DefaultEntityJoinerBuilder.java | 11 ---------- .../entity/request/EdgeRequestBuilder.java | 16 --------------- .../entity/request/EdgeSetGroupRequest.java | 5 ----- .../DefaultEntityAndRuleJoinerBuilder.java | 11 ---------- 6 files changed, 25 insertions(+), 47 deletions(-) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java index f28661c0..ba729000 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityEdgeFetcher.java @@ -120,9 +120,14 @@ private Maybe buildEdge( return zip( this.attributeMapConverter.convert( - edgeSetGroupRequest.getAllAttributeRequests(), response.getAttributeMap()), + edgeSetGroupRequest.edgeSetRequests().get(neighbor.type()).attributeRequests(), + response.getAttributeMap()), this.baselineMetricAggregationContainerMapConverter.convert( - edgeSetGroupRequest.getAllMetricAggregationRequests(), response.getMetricsMap()), + edgeSetGroupRequest + .edgeSetRequests() + .get(neighbor.type()) + .metricAggregationRequests(), + response.getMetricsMap()), (attributes, metrics) -> (Edge) new ConvertedEdge(neighbor, attributes, metrics)) .toMaybe(); } diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java index 239265a3..f71a3ec1 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityInteractionRequestBuilder.java @@ -24,6 +24,7 @@ import org.hypertrace.gateway.service.v1.common.Operator; import org.hypertrace.gateway.service.v1.entity.InteractionsRequest; import org.hypertrace.graphql.entity.request.EdgeSetGroupRequest; +import org.hypertrace.graphql.entity.request.EdgeSetRequest; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; class GatewayServiceEntityInteractionRequestBuilder { @@ -62,13 +63,28 @@ Single build(EdgeSetGroupRequest edgeSetRequestGroup) { private Single> collectSelectionsAndAggregations(EdgeSetGroupRequest request) { return this.selectionConverter - .convert(request.getAllAttributeRequests()) - .mergeWith(this.aggregationConverter.convert(request.getAllMetricAggregationRequests())) + .convert(getAllAttributeRequests(request)) + .mergeWith(this.aggregationConverter.convert(getAllMetricAggregationRequests(request))) .toObservable() .flatMap(Observable::fromIterable) .collect(Collectors.toUnmodifiableSet()); } + private Set getAllAttributeRequests(EdgeSetGroupRequest request) { + return request.edgeSetRequests().values().stream() + .map(EdgeSetRequest::attributeRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + + private Set getAllMetricAggregationRequests( + EdgeSetGroupRequest request) { + return request.edgeSetRequests().values().stream() + .map(EdgeSetRequest::metricAggregationRequests) + .flatMap(Collection::stream) + .collect(Collectors.toUnmodifiableSet()); + } + private Single buildEntityInteractionFilter(EdgeSetGroupRequest request) { // Todo: we should be using converter taking argument as logical filters with filter arg schema return Observable.fromIterable(request.edgeSetRequests().entrySet()) diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java index 23a2cc22..8a24ce58 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/joiner/DefaultEntityJoinerBuilder.java @@ -60,7 +60,6 @@ import org.hypertrace.graphql.entity.schema.EntityJoinable; import org.hypertrace.graphql.entity.schema.EntityResultSet; import org.hypertrace.graphql.entity.schema.argument.EntityTypeStringArgument; -import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.request.MetricRequestBuilder; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; @@ -329,16 +328,6 @@ public Single buildNeighborRequest( new UnsupportedOperationException( "Does not support fetching neighbors for joined entities")); } - - @Override - public Collection getAllAttributeRequests() { - return Collections.emptyList(); - } - - @Override - public Collection getAllMetricAggregationRequests() { - return Collections.emptyList(); - } } @Value diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java index 50935c02..62c6764c 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeRequestBuilder.java @@ -266,22 +266,6 @@ public Single buildNeighborRequest( String entityType, Collection neighborIds) { return this.neighborRequestBuilder.apply(entityType, neighborIds); } - - @Override - public Collection getAllAttributeRequests() { - return this.edgeSetRequests.values().stream() - .map(EdgeSetRequest::attributeRequests) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - } - - @Override - public Collection getAllMetricAggregationRequests() { - return this.edgeSetRequests.values().stream() - .map(EdgeSetRequest::metricAggregationRequests) - .flatMap(Collection::stream) - .collect(Collectors.toUnmodifiableSet()); - } } @Value diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java index 4fb23806..b5075fbb 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EdgeSetGroupRequest.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Map; import org.hypertrace.core.graphql.common.request.AttributeRequest; -import org.hypertrace.graphql.metric.request.MetricAggregationRequest; public interface EdgeSetGroupRequest { AttributeRequest neighborIdAttribute(); @@ -14,8 +13,4 @@ public interface EdgeSetGroupRequest { Single buildNeighborRequest(String entityType, Collection neighborIds); Map edgeSetRequests(); - - Collection getAllAttributeRequests(); - - Collection getAllMetricAggregationRequests(); } diff --git a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java index e09db042..0cd0c575 100644 --- a/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java +++ b/hypertrace-graphql-labels-schema-impl/src/main/java/org/hypertrace/graphql/label/joiner/DefaultEntityAndRuleJoinerBuilder.java @@ -56,7 +56,6 @@ import org.hypertrace.graphql.label.schema.LabelResultSet; import org.hypertrace.graphql.label.schema.rule.LabelApplicationRule; import org.hypertrace.graphql.label.schema.rule.LabelApplicationRuleResultSet; -import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; @@ -328,16 +327,6 @@ public Single buildNeighborRequest( new UnsupportedOperationException( "Does not support fetching neighbors for joined entities")); } - - @Override - public Collection getAllAttributeRequests() { - return Collections.emptyList(); - } - - @Override - public Collection getAllMetricAggregationRequests() { - return Collections.emptyList(); - } } @Value