Skip to content

Commit 94bfc30

Browse files
feat: add group limit to explorer api (#76)
1 parent 28b7af5 commit 94bfc30

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Single<org.hypertrace.gateway.service.v1.explore.ExploreRequest> buildRequest(
7373
.setOffset(request.offset())
7474
.setFilter(filter)
7575
.setSpaceId(request.spaceId().orElse("")) // String proto default value
76+
.setGroupLimit(request.groupLimit().orElse(0)) // Int proto default value
7677
.build());
7778
}
7879

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/deserialization/GroupByArgumentDeserializationConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ private static class DefaultGroupByArgument implements GroupByArgument {
3838

3939
@JsonProperty(GROUP_BY_INCLUDE_REST_KEY)
4040
boolean includeRest;
41+
42+
@JsonProperty(GROUP_BY_LIMIT_KEY)
43+
int groupLimit;
4144
}
4245
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ private Single<ExploreRequest> build(
163163
groupByAttribute,
164164
intervalArgument,
165165
groupBy.map(GroupByArgument::includeRest).orElse(false),
166-
spaceId));
166+
spaceId,
167+
groupBy.map(GroupByArgument::groupLimit)));
167168
}
168169

169170
private Single<Set<AttributeRequest>> buildGroupByAttributes(
@@ -189,5 +190,6 @@ private static class DefaultExploreRequest implements ExploreRequest {
189190
Optional<IntervalArgument> timeInterval;
190191
boolean includeRest;
191192
Optional<String> spaceId;
193+
Optional<Integer> groupLimit;
192194
}
193195
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ public interface ExploreRequest {
3737
boolean includeRest();
3838

3939
Optional<String> spaceId();
40+
41+
Optional<Integer> groupLimit();
4042
}

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/schema/argument/GroupByArgument.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface GroupByArgument {
1212

1313
String GROUP_BY_KEYS_KEY = "keys";
1414
String GROUP_BY_INCLUDE_REST_KEY = "includeRest";
15+
String GROUP_BY_LIMIT_KEY = "groupLimit";
1516

1617
@GraphQLField
1718
@GraphQLNonNull
@@ -21,4 +22,8 @@ public interface GroupByArgument {
2122
@GraphQLField
2223
@GraphQLName(GROUP_BY_INCLUDE_REST_KEY)
2324
boolean includeRest();
25+
26+
@GraphQLField
27+
@GraphQLName(GROUP_BY_LIMIT_KEY)
28+
int groupLimit();
2429
}

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,41 +138,36 @@ public Instant startTime() {
138138
private static class ActiveSpaceExploreRequest implements ExploreRequest {
139139
private static final String SPACE_IDS_KEY = "spaceIds";
140140
private static final String SPACE_IDS_SCOPE = "EVENT";
141+
private static final int MAX_SPACES = 100;
141142

142143
GraphQlRequestContext requestContext;
143-
String scope;
144+
String scope = SPACE_IDS_SCOPE;
145+
int limit = MAX_SPACES;
146+
int offset = 0;
147+
Set<AttributeRequest> attributeRequests = emptySet();
148+
List<AttributeAssociation<FilterArgument>> filterArguments = emptyList();
149+
Optional<IntervalArgument> timeInterval = Optional.empty();
150+
boolean includeRest = false;
151+
Optional<String> spaceId = Optional.empty();
152+
Optional<Integer> groupLimit = Optional.of(MAX_SPACES);
153+
144154
TimeRangeArgument timeRange;
145-
int limit;
146-
int offset;
147-
Set<AttributeRequest> attributeRequests;
148155
Set<MetricAggregationRequest> aggregationRequests;
149156
List<ExploreOrderArgument> orderArguments;
150-
List<AttributeAssociation<FilterArgument>> filterArguments;
151157
Set<AttributeRequest> groupByAttributeRequests;
152-
Optional<IntervalArgument> timeInterval;
153-
boolean includeRest;
154-
Optional<String> spaceId;
155158

156159
ActiveSpaceExploreRequest(
157160
GraphQlRequestContext context,
158161
TimeRangeArgument timeRange,
159162
AttributeRequest spaceIdRequest,
160163
MetricAggregationRequest spaceIdCountRequest) {
161164
this.requestContext = context;
162-
this.scope = SPACE_IDS_SCOPE;
163-
this.limit = 100;
164-
this.offset = 0;
165165
this.timeRange = timeRange;
166-
this.attributeRequests = emptySet();
167166
// Aggregation needed to pass explorer validation - a no agg request is not valid
168167
this.aggregationRequests = Set.of(spaceIdCountRequest);
169168
this.orderArguments =
170169
List.of(new SpaceExploreOrderArgument(Optional.of(spaceIdRequest.attribute())));
171-
this.filterArguments = emptyList();
172170
this.groupByAttributeRequests = Set.of(spaceIdRequest);
173-
this.timeInterval = Optional.empty();
174-
this.includeRest = false;
175-
this.spaceId = Optional.empty();
176171
}
177172
}
178173

0 commit comments

Comments
 (0)