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 7b6d200a..057563c6 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,6 +21,7 @@ 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.ExploreRequest.Builder; import org.hypertrace.graphql.explorer.request.ExploreRequest; import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; @@ -58,23 +59,31 @@ Single buildRequest( this.filterConverter.convert(request.filterArguments()), this.buildAnyAggregations(request), this.buildAnyTimeAggregations(request), - (attributes, orderBys, groupBys, filter, aggregations, series) -> - org.hypertrace.gateway.service.v1.explore.ExploreRequest.newBuilder() - .setContext(request.scope()) - .setStartTimeMillis(request.timeRange().startTime().toEpochMilli()) - .setEndTimeMillis(request.timeRange().endTime().toEpochMilli()) - .addAllSelection(attributes) - .addAllSelection(aggregations) - .addAllTimeAggregation(series) - .addAllOrderBy(orderBys) - .addAllGroupBy(groupBys) - .setLimit(request.limit()) - .setIncludeRestGroup(request.includeRest()) - .setOffset(request.offset()) - .setFilter(filter) - .setSpaceId(request.spaceId().orElse("")) // String proto default value - .setGroupLimit(request.groupLimit().orElse(0)) // Int proto default value - .build()); + (attributes, orderBys, groupBys, filter, aggregations, series) -> { + Builder builder = + org.hypertrace.gateway.service.v1.explore.ExploreRequest.newBuilder() + .setContext(request.scope()) + .addAllSelection(attributes) + .addAllSelection(aggregations) + .addAllTimeAggregation(series) + .addAllOrderBy(orderBys) + .addAllGroupBy(groupBys) + .setLimit(request.limit()) + .setIncludeRestGroup(request.includeRest()) + .setOffset(request.offset()) + .setFilter(filter) + .setSpaceId(request.spaceId().orElse("")) // String proto default value + .setGroupLimit(request.groupLimit().orElse(0)); // Int proto default value + request + .timeRange() + .ifPresent( + timeRangeArgument -> { + builder.setStartTimeMillis(timeRangeArgument.startTime().toEpochMilli()); + builder.setEndTimeMillis(timeRangeArgument.startTime().toEpochMilli()); + }); + + return builder.build(); + }); } private Single> buildAnyAggregations(ExploreRequest exploreRequest) { 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 c908007d..3d12f8c2 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 @@ -90,10 +90,8 @@ public Single build( .deserializePrimitive(arguments, OffsetArgument.class) .orElse(DEFAULT_OFFSET); - TimeRangeArgument timeRange = - this.argumentDeserializer - .deserializeObject(arguments, TimeRangeArgument.class) - .orElseThrow(); + Optional timeRange = + this.argumentDeserializer.deserializeObject(arguments, TimeRangeArgument.class); List requestedOrders = this.argumentDeserializer @@ -141,7 +139,7 @@ public Single build( public Single build( GraphQlRequestContext requestContext, String explorerScope, - TimeRangeArgument timeRange, + Optional timeRange, Optional spaceId, int limit, int offset, @@ -214,7 +212,7 @@ private Set resolveGroupByExpressions(GroupByArgument group private static class DefaultExploreRequest implements ExploreRequest { GraphQlRequestContext context; String scope; - TimeRangeArgument timeRange; + Optional timeRange; int limit; int offset; Set attributeRequests; 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 f523c707..233c92d8 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 @@ -14,7 +14,7 @@ public interface ExploreRequest extends ContextualRequest { String scope(); - TimeRangeArgument timeRange(); + Optional timeRange(); int limit(); 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 b5046892..d6dfd0d1 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 @@ -24,7 +24,7 @@ Single build( Single build( GraphQlRequestContext requestContext, String explorerScope, - TimeRangeArgument timeRange, + Optional timeRange, Optional spaceId, int limit, int offset, 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 961c0620..72376133 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 @@ -30,7 +30,7 @@ public interface ExplorerSchema { ExploreResultSet explore( @Deprecated @GraphQLName(ExplorerContextArgument.ARGUMENT_NAME) ExplorerContext context, @GraphQLName(ExplorerScopeArgument.ARGUMENT_NAME) String scope, - @GraphQLName(TimeRangeArgument.ARGUMENT_NAME) @GraphQLNonNull TimeRangeArgument timeRange, + @GraphQLName(TimeRangeArgument.ARGUMENT_NAME) TimeRangeArgument timeRange, @GraphQLName(SpaceArgument.ARGUMENT_NAME) String space, @GraphQLName(LimitArgument.ARGUMENT_NAME) int limit, @GraphQLName(OffsetArgument.ARGUMENT_NAME) int offset, 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 d08e2674..48ee0cac 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 @@ -75,7 +75,7 @@ private Single buildRequest(GraphQlRequestContext context) { attributeRequest -> new ActiveSpaceExploreRequest( context, - new FixedTimeRange(this.clock.instant()), + Optional.of(new FixedTimeRange(this.clock.instant())), attributeRequest, this.metricAggregationRequestBuilder.build( attributeRequest.attributeExpressionAssociation(), @@ -153,14 +153,14 @@ private static class ActiveSpaceExploreRequest implements ExploreRequest { Optional spaceId = Optional.empty(); Optional groupLimit = Optional.of(MAX_SPACES); - TimeRangeArgument timeRange; + Optional timeRange; Set aggregationRequests; List orderArguments; Set groupByAttributeRequests; ActiveSpaceExploreRequest( GraphQlRequestContext context, - TimeRangeArgument timeRange, + Optional timeRange, AttributeRequest spaceIdRequest, MetricAggregationRequest spaceIdCountRequest) { this.context = context; diff --git a/hypertrace-graphql-spaces-schema/src/test/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDaoTest.java b/hypertrace-graphql-spaces-schema/src/test/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDaoTest.java index 88b8536b..7300f966 100644 --- a/hypertrace-graphql-spaces-schema/src/test/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDaoTest.java +++ b/hypertrace-graphql-spaces-schema/src/test/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDaoTest.java @@ -96,9 +96,10 @@ void makesAppropriateRequest() { && request.offset() == 0 && request .timeRange() + .get() .startTime() .equals(Instant.parse("2021-01-01T00:00:00.00Z")) - && request.timeRange().endTime().equals(this.mockEndTime) + && request.timeRange().get().endTime().equals(this.mockEndTime) && request.attributeRequests().isEmpty() && request.aggregationRequests().equals(Set.of(this.mockSpaceCountRequest)) && request.orderArguments().size() == 1