From bef2cec2598a37c679038b4f5fcced8a80c3846d Mon Sep 17 00:00:00 2001 From: aman bansal Date: Fri, 4 Aug 2023 08:45:34 +0530 Subject: [PATCH] chore | adding context options to explore query (#194) * chore | adding context options to explore query --- hypertrace-core-graphql | 2 +- .../GatewayServiceExploreRequestBuilder.java | 23 +++++++++- ...tyContextOptionsDeserializationConfig.java | 43 +++++++++++++++++++ .../ExplorerDeserializationModule.java | 3 ++ .../request/DefaultExploreRequestBuilder.java | 8 ++++ .../explorer/request/ExploreRequest.java | 3 ++ .../request/ExploreRequestBuilder.java | 2 + .../explorer/schema/ExplorerSchema.java | 4 +- .../schema/argument/EntityContextOptions.java | 17 ++++++++ .../spaces/dao/ExplorerBackedSpacesDao.java | 2 + 10 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/EntityContextOptionsDeserializationConfig.java create mode 100644 hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/argument/EntityContextOptions.java diff --git a/hypertrace-core-graphql b/hypertrace-core-graphql index 8ef6b667..70ad70a3 160000 --- a/hypertrace-core-graphql +++ b/hypertrace-core-graphql @@ -1 +1 @@ -Subproject commit 8ef6b667c33792c4da7a5508d1b6200eaf9ff599 +Subproject commit 70ad70a32d20b882645f511190292c8790063929 diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/dao/GatewayServiceExploreRequestBuilder.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/dao/GatewayServiceExploreRequestBuilder.java index 99f33dc8..6d49643a 100644 --- a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/dao/GatewayServiceExploreRequestBuilder.java +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/dao/GatewayServiceExploreRequestBuilder.java @@ -21,8 +21,11 @@ import org.hypertrace.gateway.service.v1.common.Expression; import org.hypertrace.gateway.service.v1.common.Filter; import org.hypertrace.gateway.service.v1.common.TimeAggregation; +import org.hypertrace.gateway.service.v1.explore.ContextOption; +import org.hypertrace.gateway.service.v1.explore.EntityOption; import org.hypertrace.gateway.service.v1.explore.ExploreRequest.Builder; import org.hypertrace.graphql.explorer.request.ExploreRequest; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricSeriesRequest; @@ -59,7 +62,8 @@ Single buildRequest( this.filterConverter.convert(request.filterArguments()), this.buildAnyAggregations(request), this.buildAnyTimeAggregations(request), - (attributes, orderBys, groupBys, filter, aggregations, series) -> { + this.buildContextOptions(request), + (attributes, orderBys, groupBys, filter, aggregations, series, contextOptions) -> { Builder builder = org.hypertrace.gateway.service.v1.explore.ExploreRequest.newBuilder() .setContext(request.scope()) @@ -73,7 +77,8 @@ Single buildRequest( .setOffset(request.offset()) .setFilter(filter) .setSpaceId(request.spaceId().orElse("")) // String proto default value - .setGroupLimit(request.groupLimit().orElse(0)); // Int proto default value + .setGroupLimit(request.groupLimit().orElse(0)) // Int proto default value + .setContextOption(contextOptions); request .timeRange() .ifPresent( @@ -109,6 +114,20 @@ private Single> buildAnyTimeAggregations(ExploreRequest exp .flatMap(this.seriesConverter::convert); } + private Single buildContextOptions(ExploreRequest exploreRequest) { + if (exploreRequest.entityContextOptions().isEmpty()) { + return Single.just(ContextOption.newBuilder().build()); + } + EntityContextOptions entityContextOptions = exploreRequest.entityContextOptions().get(); + return Single.just( + ContextOption.newBuilder() + .setEntityOption( + EntityOption.newBuilder() + .setIncludeNonLiveEntities(entityContextOptions.includeNonLiveEntities()) + .build()) + .build()); + } + @Value @Accessors(fluent = true) private static class ExplorerMetricSeriesRequest implements MetricSeriesRequest { diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/EntityContextOptionsDeserializationConfig.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/EntityContextOptionsDeserializationConfig.java new file mode 100644 index 00000000..e1b1bbaa --- /dev/null +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/EntityContextOptionsDeserializationConfig.java @@ -0,0 +1,43 @@ +package org.hypertrace.graphql.explorer.deserialization; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.util.List; +import lombok.NoArgsConstructor; +import lombok.Value; +import lombok.experimental.Accessors; +import org.hypertrace.core.graphql.deserialization.ArgumentDeserializationConfig; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; + +public class EntityContextOptionsDeserializationConfig implements ArgumentDeserializationConfig { + + @Override + public String getArgumentKey() { + return EntityContextOptions.ARGUMENT_NAME; + } + + @Override + public Class getArgumentSchema() { + return EntityContextOptions.class; + } + + @Override + public List jacksonModules() { + return List.of( + new SimpleModule() + .addAbstractTypeMapping( + EntityContextOptions.class, + EntityContextOptionsDeserializationConfig.DefaultEntityContextOptionsArgument + .class)); + } + + @Value + @Accessors(fluent = true) + @NoArgsConstructor(force = true) + private static class DefaultEntityContextOptionsArgument implements EntityContextOptions { + + @JsonProperty(EntityContextOptions.INCLUDE_NON_LIVE_ENTITIES) + boolean includeNonLiveEntities; + } +} diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/ExplorerDeserializationModule.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/ExplorerDeserializationModule.java index 49342aeb..acfd3622 100644 --- a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/ExplorerDeserializationModule.java +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/ExplorerDeserializationModule.java @@ -56,5 +56,8 @@ protected void configure() { deserializationConfigMultibinder.addBinding().to(GroupByArgumentDeserializationConfig.class); deserializationConfigMultibinder.addBinding().to(IntervalArgumentDeserializationConfig.class); + deserializationConfigMultibinder + .addBinding() + .to(EntityContextOptionsDeserializationConfig.class); } } diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java index 3d12f8c2..213abc5a 100644 --- a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java @@ -28,6 +28,7 @@ import org.hypertrace.core.graphql.common.utils.attributes.AttributeScopeStringTranslator; import org.hypertrace.core.graphql.context.GraphQlRequestContext; import org.hypertrace.core.graphql.deserialization.ArgumentDeserializer; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; import org.hypertrace.graphql.explorer.schema.argument.ExplorerContext; import org.hypertrace.graphql.explorer.schema.argument.ExplorerContextArgument; import org.hypertrace.graphql.explorer.schema.argument.ExplorerScopeArgument; @@ -112,6 +113,9 @@ public Single build( Optional intervalArgument = this.argumentDeserializer.deserializeObject(arguments, IntervalArgument.class); + Optional entityContextOptions = + this.argumentDeserializer.deserializeObject(arguments, EntityContextOptions.class); + Single> attributeSelections = this.selectionRequestBuilder.getAttributeSelections( requestContext, explorerScope, selectionSet); @@ -131,6 +135,7 @@ public Single build( requestedOrders, groupBy, intervalArgument, + entityContextOptions, attributeSelections, aggregationSelections); } @@ -147,6 +152,7 @@ public Single build( List requestedOrders, Optional groupBy, Optional intervalArgument, + Optional entityContextOptions, Single> attributeSelections, Single> aggregationSelections) { @@ -178,6 +184,7 @@ public Single build( filters, groupByAttribute, intervalArgument, + entityContextOptions, groupBy.map(GroupByArgument::includeRest).orElse(false), spaceId, groupBy.map(GroupByArgument::groupLimit))); @@ -221,6 +228,7 @@ private static class DefaultExploreRequest implements ExploreRequest { List> filterArguments; Set groupByAttributeRequests; Optional timeInterval; + Optional entityContextOptions; boolean includeRest; Optional spaceId; Optional groupLimit; diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequest.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequest.java index 233c92d8..bfbde218 100644 --- a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequest.java +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequest.java @@ -8,6 +8,7 @@ import org.hypertrace.core.graphql.common.request.ContextualRequest; import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument; import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; @@ -37,4 +38,6 @@ public interface ExploreRequest extends ContextualRequest { Optional spaceId(); Optional groupLimit(); + + Optional entityContextOptions(); } diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequestBuilder.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequestBuilder.java index d6dfd0d1..95bee6b4 100644 --- a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequestBuilder.java +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequestBuilder.java @@ -10,6 +10,7 @@ import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument; import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument; import org.hypertrace.core.graphql.context.GraphQlRequestContext; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; import org.hypertrace.graphql.explorer.schema.argument.GroupByArgument; import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; @@ -32,6 +33,7 @@ Single build( List requestedOrders, Optional groupBy, Optional intervalArgument, + Optional entityContextOptions, Single> attributeSelections, Single> aggregationSelections); } diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/ExplorerSchema.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/ExplorerSchema.java index 72376133..74b21393 100644 --- a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/ExplorerSchema.java +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/ExplorerSchema.java @@ -12,6 +12,7 @@ import org.hypertrace.core.graphql.common.schema.results.arguments.page.OffsetArgument; import org.hypertrace.core.graphql.common.schema.results.arguments.space.SpaceArgument; import org.hypertrace.graphql.explorer.fetcher.ExplorerFetcher; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; import org.hypertrace.graphql.explorer.schema.argument.ExplorerContext; import org.hypertrace.graphql.explorer.schema.argument.ExplorerContextArgument; import org.hypertrace.graphql.explorer.schema.argument.ExplorerScopeArgument; @@ -37,5 +38,6 @@ ExploreResultSet explore( @GraphQLName(FilterArgument.ARGUMENT_NAME) List filterBy, @GraphQLName(OrderArgument.ARGUMENT_NAME) List orderBy, @GraphQLName(GroupByArgument.ARGUMENT_NAME) GroupByArgument groupBy, - @GraphQLName(IntervalArgument.ARGUMENT_NAME) IntervalArgument interval); + @GraphQLName(IntervalArgument.ARGUMENT_NAME) IntervalArgument interval, + @GraphQLName(EntityContextOptions.ARGUMENT_NAME) EntityContextOptions entityContextOptions); } diff --git a/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/argument/EntityContextOptions.java b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/argument/EntityContextOptions.java new file mode 100644 index 00000000..1abdf9ed --- /dev/null +++ b/hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/argument/EntityContextOptions.java @@ -0,0 +1,17 @@ +package org.hypertrace.graphql.explorer.schema.argument; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.annotations.annotationTypes.GraphQLNonNull; + +@GraphQLName(EntityContextOptions.TYPE_NAME) +public interface EntityContextOptions { + String TYPE_NAME = "EntityContextOptions"; + String ARGUMENT_NAME = "entityContextOptions"; + String INCLUDE_NON_LIVE_ENTITIES = "includeNonLiveEntities"; + + @GraphQLField + @GraphQLNonNull + @GraphQLName(INCLUDE_NON_LIVE_ENTITIES) + boolean includeNonLiveEntities(); +} diff --git a/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDao.java b/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDao.java index 48ee0cac..c85fce1b 100644 --- a/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDao.java +++ b/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDao.java @@ -33,6 +33,7 @@ import org.hypertrace.graphql.explorer.request.ExploreRequest; import org.hypertrace.graphql.explorer.schema.ExploreResultSet; import org.hypertrace.graphql.explorer.schema.Selection; +import org.hypertrace.graphql.explorer.schema.argument.EntityContextOptions; import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; import org.hypertrace.graphql.metric.request.MetricAggregationRequestBuilder; @@ -149,6 +150,7 @@ private static class ActiveSpaceExploreRequest implements ExploreRequest { Set attributeRequests = emptySet(); List> filterArguments = emptyList(); Optional timeInterval = Optional.empty(); + Optional entityContextOptions = Optional.empty(); boolean includeRest = false; Optional spaceId = Optional.empty(); Optional groupLimit = Optional.of(MAX_SPACES);