Skip to content

Commit eff5a7d

Browse files
authored
make time range optional in explore query (#143)
make time range optional
1 parent f6c5b03 commit eff5a7d

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/dao/GatewayServiceExploreRequestBuilder.java

+26-17
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hypertrace.gateway.service.v1.common.Expression;
2222
import org.hypertrace.gateway.service.v1.common.Filter;
2323
import org.hypertrace.gateway.service.v1.common.TimeAggregation;
24+
import org.hypertrace.gateway.service.v1.explore.ExploreRequest.Builder;
2425
import org.hypertrace.graphql.explorer.request.ExploreRequest;
2526
import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument;
2627
import org.hypertrace.graphql.metric.request.MetricAggregationRequest;
@@ -58,23 +59,31 @@ Single<org.hypertrace.gateway.service.v1.explore.ExploreRequest> buildRequest(
5859
this.filterConverter.convert(request.filterArguments()),
5960
this.buildAnyAggregations(request),
6061
this.buildAnyTimeAggregations(request),
61-
(attributes, orderBys, groupBys, filter, aggregations, series) ->
62-
org.hypertrace.gateway.service.v1.explore.ExploreRequest.newBuilder()
63-
.setContext(request.scope())
64-
.setStartTimeMillis(request.timeRange().startTime().toEpochMilli())
65-
.setEndTimeMillis(request.timeRange().endTime().toEpochMilli())
66-
.addAllSelection(attributes)
67-
.addAllSelection(aggregations)
68-
.addAllTimeAggregation(series)
69-
.addAllOrderBy(orderBys)
70-
.addAllGroupBy(groupBys)
71-
.setLimit(request.limit())
72-
.setIncludeRestGroup(request.includeRest())
73-
.setOffset(request.offset())
74-
.setFilter(filter)
75-
.setSpaceId(request.spaceId().orElse("")) // String proto default value
76-
.setGroupLimit(request.groupLimit().orElse(0)) // Int proto default value
77-
.build());
62+
(attributes, orderBys, groupBys, filter, aggregations, series) -> {
63+
Builder builder =
64+
org.hypertrace.gateway.service.v1.explore.ExploreRequest.newBuilder()
65+
.setContext(request.scope())
66+
.addAllSelection(attributes)
67+
.addAllSelection(aggregations)
68+
.addAllTimeAggregation(series)
69+
.addAllOrderBy(orderBys)
70+
.addAllGroupBy(groupBys)
71+
.setLimit(request.limit())
72+
.setIncludeRestGroup(request.includeRest())
73+
.setOffset(request.offset())
74+
.setFilter(filter)
75+
.setSpaceId(request.spaceId().orElse("")) // String proto default value
76+
.setGroupLimit(request.groupLimit().orElse(0)); // Int proto default value
77+
request
78+
.timeRange()
79+
.ifPresent(
80+
timeRangeArgument -> {
81+
builder.setStartTimeMillis(timeRangeArgument.startTime().toEpochMilli());
82+
builder.setEndTimeMillis(timeRangeArgument.startTime().toEpochMilli());
83+
});
84+
85+
return builder.build();
86+
});
7887
}
7988

8089
private Single<Set<Expression>> buildAnyAggregations(ExploreRequest exploreRequest) {

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/DefaultExploreRequestBuilder.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ public Single<ExploreRequest> build(
9090
.deserializePrimitive(arguments, OffsetArgument.class)
9191
.orElse(DEFAULT_OFFSET);
9292

93-
TimeRangeArgument timeRange =
94-
this.argumentDeserializer
95-
.deserializeObject(arguments, TimeRangeArgument.class)
96-
.orElseThrow();
93+
Optional<TimeRangeArgument> timeRange =
94+
this.argumentDeserializer.deserializeObject(arguments, TimeRangeArgument.class);
9795

9896
List<AggregatableOrderArgument> requestedOrders =
9997
this.argumentDeserializer
@@ -141,7 +139,7 @@ public Single<ExploreRequest> build(
141139
public Single<ExploreRequest> build(
142140
GraphQlRequestContext requestContext,
143141
String explorerScope,
144-
TimeRangeArgument timeRange,
142+
Optional<TimeRangeArgument> timeRange,
145143
Optional<String> spaceId,
146144
int limit,
147145
int offset,
@@ -214,7 +212,7 @@ private Set<AttributeExpression> resolveGroupByExpressions(GroupByArgument group
214212
private static class DefaultExploreRequest implements ExploreRequest {
215213
GraphQlRequestContext context;
216214
String scope;
217-
TimeRangeArgument timeRange;
215+
Optional<TimeRangeArgument> timeRange;
218216
int limit;
219217
int offset;
220218
Set<AttributeRequest> attributeRequests;

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public interface ExploreRequest extends ContextualRequest {
1515
String scope();
1616

17-
TimeRangeArgument timeRange();
17+
Optional<TimeRangeArgument> timeRange();
1818

1919
int limit();
2020

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/request/ExploreRequestBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Single<ExploreRequest> build(
2424
Single<ExploreRequest> build(
2525
GraphQlRequestContext requestContext,
2626
String explorerScope,
27-
TimeRangeArgument timeRange,
27+
Optional<TimeRangeArgument> timeRange,
2828
Optional<String> spaceId,
2929
int limit,
3030
int offset,

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/ExplorerSchema.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface ExplorerSchema {
3030
ExploreResultSet explore(
3131
@Deprecated @GraphQLName(ExplorerContextArgument.ARGUMENT_NAME) ExplorerContext context,
3232
@GraphQLName(ExplorerScopeArgument.ARGUMENT_NAME) String scope,
33-
@GraphQLName(TimeRangeArgument.ARGUMENT_NAME) @GraphQLNonNull TimeRangeArgument timeRange,
33+
@GraphQLName(TimeRangeArgument.ARGUMENT_NAME) TimeRangeArgument timeRange,
3434
@GraphQLName(SpaceArgument.ARGUMENT_NAME) String space,
3535
@GraphQLName(LimitArgument.ARGUMENT_NAME) int limit,
3636
@GraphQLName(OffsetArgument.ARGUMENT_NAME) int offset,

hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDao.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private Single<ExploreRequest> buildRequest(GraphQlRequestContext context) {
7575
attributeRequest ->
7676
new ActiveSpaceExploreRequest(
7777
context,
78-
new FixedTimeRange(this.clock.instant()),
78+
Optional.of(new FixedTimeRange(this.clock.instant())),
7979
attributeRequest,
8080
this.metricAggregationRequestBuilder.build(
8181
attributeRequest.attributeExpressionAssociation(),
@@ -153,14 +153,14 @@ private static class ActiveSpaceExploreRequest implements ExploreRequest {
153153
Optional<String> spaceId = Optional.empty();
154154
Optional<Integer> groupLimit = Optional.of(MAX_SPACES);
155155

156-
TimeRangeArgument timeRange;
156+
Optional<TimeRangeArgument> timeRange;
157157
Set<MetricAggregationRequest> aggregationRequests;
158158
List<ExploreOrderArgument> orderArguments;
159159
Set<AttributeRequest> groupByAttributeRequests;
160160

161161
ActiveSpaceExploreRequest(
162162
GraphQlRequestContext context,
163-
TimeRangeArgument timeRange,
163+
Optional<TimeRangeArgument> timeRange,
164164
AttributeRequest spaceIdRequest,
165165
MetricAggregationRequest spaceIdCountRequest) {
166166
this.context = context;

hypertrace-graphql-spaces-schema/src/test/java/org/hypertrace/graphql/spaces/dao/ExplorerBackedSpacesDaoTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ void makesAppropriateRequest() {
9696
&& request.offset() == 0
9797
&& request
9898
.timeRange()
99+
.get()
99100
.startTime()
100101
.equals(Instant.parse("2021-01-01T00:00:00.00Z"))
101-
&& request.timeRange().endTime().equals(this.mockEndTime)
102+
&& request.timeRange().get().endTime().equals(this.mockEndTime)
102103
&& request.attributeRequests().isEmpty()
103104
&& request.aggregationRequests().equals(Set.of(this.mockSpaceCountRequest))
104105
&& request.orderArguments().size() == 1

0 commit comments

Comments
 (0)