Skip to content

Commit

Permalink
chore | adding context options to explore query (#194)
Browse files Browse the repository at this point in the history
* chore | adding context options to explore query
  • Loading branch information
aman-bansal authored Aug 4, 2023
1 parent dc8d1d5 commit bef2cec
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hypertrace-core-graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +62,8 @@ Single<org.hypertrace.gateway.service.v1.explore.ExploreRequest> 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())
Expand All @@ -73,7 +77,8 @@ Single<org.hypertrace.gateway.service.v1.explore.ExploreRequest> 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(
Expand Down Expand Up @@ -109,6 +114,20 @@ private Single<Set<TimeAggregation>> buildAnyTimeAggregations(ExploreRequest exp
.flatMap(this.seriesConverter::convert);
}

private Single<ContextOption> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EntityContextOptions> getArgumentSchema() {
return EntityContextOptions.class;
}

@Override
public List<Module> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ protected void configure() {

deserializationConfigMultibinder.addBinding().to(GroupByArgumentDeserializationConfig.class);
deserializationConfigMultibinder.addBinding().to(IntervalArgumentDeserializationConfig.class);
deserializationConfigMultibinder
.addBinding()
.to(EntityContextOptionsDeserializationConfig.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +113,9 @@ public Single<ExploreRequest> build(
Optional<IntervalArgument> intervalArgument =
this.argumentDeserializer.deserializeObject(arguments, IntervalArgument.class);

Optional<EntityContextOptions> entityContextOptions =
this.argumentDeserializer.deserializeObject(arguments, EntityContextOptions.class);

Single<Set<AttributeRequest>> attributeSelections =
this.selectionRequestBuilder.getAttributeSelections(
requestContext, explorerScope, selectionSet);
Expand All @@ -131,6 +135,7 @@ public Single<ExploreRequest> build(
requestedOrders,
groupBy,
intervalArgument,
entityContextOptions,
attributeSelections,
aggregationSelections);
}
Expand All @@ -147,6 +152,7 @@ public Single<ExploreRequest> build(
List<AggregatableOrderArgument> requestedOrders,
Optional<GroupByArgument> groupBy,
Optional<IntervalArgument> intervalArgument,
Optional<EntityContextOptions> entityContextOptions,
Single<Set<AttributeRequest>> attributeSelections,
Single<Set<MetricAggregationRequest>> aggregationSelections) {

Expand Down Expand Up @@ -178,6 +184,7 @@ public Single<ExploreRequest> build(
filters,
groupByAttribute,
intervalArgument,
entityContextOptions,
groupBy.map(GroupByArgument::includeRest).orElse(false),
spaceId,
groupBy.map(GroupByArgument::groupLimit)));
Expand Down Expand Up @@ -221,6 +228,7 @@ private static class DefaultExploreRequest implements ExploreRequest {
List<AttributeAssociation<FilterArgument>> filterArguments;
Set<AttributeRequest> groupByAttributeRequests;
Optional<IntervalArgument> timeInterval;
Optional<EntityContextOptions> entityContextOptions;
boolean includeRest;
Optional<String> spaceId;
Optional<Integer> groupLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -37,4 +38,6 @@ public interface ExploreRequest extends ContextualRequest {
Optional<String> spaceId();

Optional<Integer> groupLimit();

Optional<EntityContextOptions> entityContextOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ Single<ExploreRequest> build(
List<AggregatableOrderArgument> requestedOrders,
Optional<GroupByArgument> groupBy,
Optional<IntervalArgument> intervalArgument,
Optional<EntityContextOptions> entityContextOptions,
Single<Set<AttributeRequest>> attributeSelections,
Single<Set<MetricAggregationRequest>> aggregationSelections);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,5 +38,6 @@ ExploreResultSet explore(
@GraphQLName(FilterArgument.ARGUMENT_NAME) List<FilterArgument> filterBy,
@GraphQLName(OrderArgument.ARGUMENT_NAME) List<AggregatableOrderArgument> 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);
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,6 +150,7 @@ private static class ActiveSpaceExploreRequest implements ExploreRequest {
Set<AttributeRequest> attributeRequests = emptySet();
List<AttributeAssociation<FilterArgument>> filterArguments = emptyList();
Optional<IntervalArgument> timeInterval = Optional.empty();
Optional<EntityContextOptions> entityContextOptions = Optional.empty();
boolean includeRest = false;
Optional<String> spaceId = Optional.empty();
Optional<Integer> groupLimit = Optional.of(MAX_SPACES);
Expand Down

0 comments on commit bef2cec

Please sign in to comment.