From 5cc2ac0b022113af791e96683aaefa66bc7e3cb2 Mon Sep 17 00:00:00 2001 From: avinash Date: Wed, 4 Oct 2023 22:29:20 -0700 Subject: [PATCH] Added support for passing additional filters to EntityRequest --- .../joiner/DefaultEntityJoinerBuilder.java | 3 ++- .../request/DefaultEntityRequestBuilder.java | 24 +++++++++++++++++++ .../graphql/entity/request/EntityRequest.java | 3 ++- .../entity/request/EntityRequestBuilder.java | 7 ++++++ .../NeighborEntitiesRequestBuilder.java | 2 ++ .../DefaultEntityAndRuleJoinerBuilder.java | 3 ++- 6 files changed, 39 insertions(+), 3 deletions(-) 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..f2f6c718 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 @@ -291,7 +291,7 @@ private Single buildEntityRequest( context, entityType, this.entityFieldsByType.get(entityType)), (resultSetRequest, metricRequestList, optionalLabelRequest) -> new DefaultEntityRequest( - entityType, resultSetRequest, metricRequestList, optionalLabelRequest)); + context, entityType, resultSetRequest, metricRequestList, optionalLabelRequest)); } private Single>> buildIdFilter( @@ -304,6 +304,7 @@ private Single>> buildIdFilter( @Value @Accessors(fluent = true) private static class DefaultEntityRequest implements EntityRequest { + GraphQlRequestContext context; String entityType; ResultSetRequest resultSetRequest; List metricRequests; diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/DefaultEntityRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/DefaultEntityRequestBuilder.java index 39a9e154..b31251d9 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/DefaultEntityRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/DefaultEntityRequestBuilder.java @@ -18,6 +18,7 @@ import org.hypertrace.core.graphql.common.request.ResultSetRequestBuilder; import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument; import org.hypertrace.core.graphql.common.schema.results.ResultSet; +import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument; import org.hypertrace.core.graphql.common.schema.results.arguments.space.SpaceArgument; import org.hypertrace.core.graphql.context.GraphQlRequestContext; import org.hypertrace.core.graphql.deserialization.ArgumentDeserializer; @@ -74,6 +75,27 @@ public Single build( return this.build(context, arguments, entityScope, selectionSet); } + @Override + public Single rebuildWithAdditionalFilters( + GraphQlRequestContext context, + EntityRequest originalRequest, + List filterArguments) { + return this.resultSetRequestBuilder + .rebuildWithAdditionalFilters(originalRequest.resultSetRequest(), filterArguments) + .map( + newResultSetRequest -> + new DefaultEntityRequest( + originalRequest.context(), + originalRequest.entityType(), + newResultSetRequest, + originalRequest.metricRequests(), + originalRequest.incomingEdgeRequests(), + originalRequest.outgoingEdgeRequests(), + originalRequest.includeInactive(), + originalRequest.fetchTotal(), + originalRequest.labelRequest())); + } + private Single build( GraphQlRequestContext context, Map arguments, @@ -113,6 +135,7 @@ private Single build( outgoingEdges, optionalLabelsAttributeRequest) -> new DefaultEntityRequest( + context, scope, resultSetRequest, metricRequestList, @@ -157,6 +180,7 @@ private Optional space(Map arguments) { @Value @Accessors(fluent = true) private static class DefaultEntityRequest implements EntityRequest { + GraphQlRequestContext context; String entityType; ResultSetRequest resultSetRequest; List metricRequests; diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequest.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequest.java index 7f25cf51..27cfd450 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequest.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequest.java @@ -2,11 +2,12 @@ import java.util.List; import java.util.Optional; +import org.hypertrace.core.graphql.common.request.ContextualRequest; import org.hypertrace.core.graphql.common.request.ResultSetRequest; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; -public interface EntityRequest { +public interface EntityRequest extends ContextualRequest { String entityType(); ResultSetRequest resultSetRequest(); diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequestBuilder.java index e0e8bd16..f27dab2d 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/EntityRequestBuilder.java @@ -2,7 +2,9 @@ import graphql.schema.DataFetchingFieldSelectionSet; import io.reactivex.rxjava3.core.Single; +import java.util.List; import java.util.Map; +import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument; import org.hypertrace.core.graphql.context.GraphQlRequestContext; public interface EntityRequestBuilder { @@ -10,4 +12,9 @@ Single build( GraphQlRequestContext context, Map arguments, DataFetchingFieldSelectionSet selectionSet); + + Single rebuildWithAdditionalFilters( + GraphQlRequestContext context, + EntityRequest originalRequest, + List filterArguments); } diff --git a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/NeighborEntitiesRequestBuilder.java b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/NeighborEntitiesRequestBuilder.java index 1d888a59..c43b9ba4 100644 --- a/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/NeighborEntitiesRequestBuilder.java +++ b/hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/request/NeighborEntitiesRequestBuilder.java @@ -90,6 +90,7 @@ private Single build( context, timeRange, space, this.getOutgoingEdges(neighborFields)), (resultSetRequest, metricRequestList, incomingEdges, outgoingEdges) -> new NeighborEntityRequest( + context, entityScope, resultSetRequest, metricRequestList, @@ -174,6 +175,7 @@ private static class EntityNeighborIdFilter implements FilterArgument { @Value @Accessors(fluent = true) private static class NeighborEntityRequest implements EntityRequest { + GraphQlRequestContext context; String entityType; ResultSetRequest resultSetRequest; List metricRequests; 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..77b0088f 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 @@ -291,7 +291,7 @@ private Single buildEntityRequest( filterArguments, selectionSet.getFields().stream(), Optional.empty()) - .map(request -> new DefaultEntityRequest(entityType, request, fetchTotal)); + .map(request -> new DefaultEntityRequest(context, entityType, request, fetchTotal)); } private Single>> buildLabelIdFilter( @@ -303,6 +303,7 @@ private Single>> buildLabelIdFilter( @Value @Accessors(fluent = true) private static class DefaultEntityRequest implements EntityRequest { + GraphQlRequestContext context; String entityType; ResultSetRequest resultSetRequest; List metricRequests = Collections.emptyList(); // Only support attributes for now