From 5cc2ac0b022113af791e96683aaefa66bc7e3cb2 Mon Sep 17 00:00:00 2001 From: avinash Date: Wed, 4 Oct 2023 22:29:20 -0700 Subject: [PATCH 1/3] 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 From c1c6f22eb3dfdb93c5703a030b9efd01e96cc7db Mon Sep 17 00:00:00 2001 From: avinash Date: Wed, 4 Oct 2023 22:36:52 -0700 Subject: [PATCH 2/3] minor cleanup --- .../graphql/entity/request/DefaultEntityRequestBuilder.java | 4 +--- .../graphql/entity/request/EntityRequestBuilder.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) 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 b31251d9..fa3b823f 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 @@ -77,9 +77,7 @@ public Single build( @Override public Single rebuildWithAdditionalFilters( - GraphQlRequestContext context, - EntityRequest originalRequest, - List filterArguments) { + EntityRequest originalRequest, List filterArguments) { return this.resultSetRequestBuilder .rebuildWithAdditionalFilters(originalRequest.resultSetRequest(), filterArguments) .map( 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 f27dab2d..411a86b3 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 @@ -14,7 +14,5 @@ Single build( DataFetchingFieldSelectionSet selectionSet); Single rebuildWithAdditionalFilters( - GraphQlRequestContext context, - EntityRequest originalRequest, - List filterArguments); + EntityRequest originalRequest, List filterArguments); } From e80252387727bdb9e012e24a1700a58c08797618 Mon Sep 17 00:00:00 2001 From: Aaron Steinfeld Date: Thu, 5 Oct 2023 10:03:35 -0400 Subject: [PATCH 3/3] refactor: default context --- .../graphql/entity/joiner/DefaultEntityJoinerBuilder.java | 3 +-- .../entity/request/DefaultEntityRequestBuilder.java | 3 --- .../hypertrace/graphql/entity/request/EntityRequest.java | 7 +++++++ .../entity/request/NeighborEntitiesRequestBuilder.java | 2 -- .../label/joiner/DefaultEntityAndRuleJoinerBuilder.java | 3 +-- 5 files changed, 9 insertions(+), 9 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 f2f6c718..0a5a2daf 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( - context, entityType, resultSetRequest, metricRequestList, optionalLabelRequest)); + entityType, resultSetRequest, metricRequestList, optionalLabelRequest)); } private Single>> buildIdFilter( @@ -304,7 +304,6 @@ 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 fa3b823f..788a0725 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 @@ -83,7 +83,6 @@ public Single rebuildWithAdditionalFilters( .map( newResultSetRequest -> new DefaultEntityRequest( - originalRequest.context(), originalRequest.entityType(), newResultSetRequest, originalRequest.metricRequests(), @@ -133,7 +132,6 @@ private Single build( outgoingEdges, optionalLabelsAttributeRequest) -> new DefaultEntityRequest( - context, scope, resultSetRequest, metricRequestList, @@ -178,7 +176,6 @@ 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 27cfd450..3562b1e1 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 @@ -4,10 +4,17 @@ import java.util.Optional; import org.hypertrace.core.graphql.common.request.ContextualRequest; import org.hypertrace.core.graphql.common.request.ResultSetRequest; +import org.hypertrace.core.graphql.context.GraphQlRequestContext; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; public interface EntityRequest extends ContextualRequest { + + @Override + default GraphQlRequestContext context() { + return resultSetRequest().context(); + } + String entityType(); ResultSetRequest resultSetRequest(); 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 c43b9ba4..1d888a59 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,7 +90,6 @@ private Single build( context, timeRange, space, this.getOutgoingEdges(neighborFields)), (resultSetRequest, metricRequestList, incomingEdges, outgoingEdges) -> new NeighborEntityRequest( - context, entityScope, resultSetRequest, metricRequestList, @@ -175,7 +174,6 @@ 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 77b0088f..a15737a6 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(context, entityType, request, fetchTotal)); + .map(request -> new DefaultEntityRequest(entityType, request, fetchTotal)); } private Single>> buildLabelIdFilter( @@ -303,7 +303,6 @@ 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