Skip to content

Commit 0f60667

Browse files
feat: add request transformation (#94)
1 parent d5b0454 commit 0f60667

10 files changed

Lines changed: 22 additions & 13 deletions

File tree

hypertrace-core-graphql

hypertrace-graphql-explorer-schema/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-deserialization")
2727
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-schema-utils")
2828
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-rx-utils")
29+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-request-transformation")
2930

3031
testImplementation("org.junit.jupiter:junit-jupiter")
3132
testImplementation("org.mockito:mockito-core")

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hypertrace.core.graphql.common.schema.attributes.MetricAggregationType;
1717
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
1818
import org.hypertrace.core.graphql.common.utils.Converter;
19+
import org.hypertrace.core.graphql.request.transformation.RequestTransformer;
1920
import org.hypertrace.core.graphql.rx.BoundedIoScheduler;
2021
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
2122
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
@@ -41,6 +42,7 @@ protected void configure() {
4142
requireBinding(Key.get(Scheduler.class, BoundedIoScheduler.class));
4243
requireBinding(Key.get(new TypeLiteral<Converter<Value, Object>>() {}));
4344
requireBinding(Key.get(new TypeLiteral<Converter<AttributeModelType, AttributeType>>() {}));
45+
requireBinding(RequestTransformer.class);
4446
requireBinding(
4547
Key.get(
4648
new TypeLiteral<

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.inject.Inject;
99
import javax.inject.Singleton;
1010
import org.hypertrace.core.graphql.context.GraphQlRequestContext;
11+
import org.hypertrace.core.graphql.request.transformation.RequestTransformer;
1112
import org.hypertrace.core.graphql.rx.BoundedIoScheduler;
1213
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
1314
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
@@ -26,6 +27,7 @@ class GatewayServiceExplorerDao implements ExplorerDao {
2627
private final GatewayServiceExploreResponseConverter responseConverter;
2728
private final GraphQlServiceConfig serviceConfig;
2829
private final Scheduler boundedIoScheduler;
30+
private final RequestTransformer requestTransformer;
2931

3032
@Inject
3133
GatewayServiceExplorerDao(
@@ -35,12 +37,14 @@ class GatewayServiceExplorerDao implements ExplorerDao {
3537
GrpcChannelRegistry grpcChannelRegistry,
3638
GatewayServiceExploreRequestBuilder requestBuilder,
3739
GatewayServiceExploreResponseConverter responseConverter,
38-
@BoundedIoScheduler Scheduler boundedIoScheduler) {
40+
@BoundedIoScheduler Scheduler boundedIoScheduler,
41+
RequestTransformer requestTransformer) {
3942
this.grpcContextBuilder = grpcContextBuilder;
4043
this.requestBuilder = requestBuilder;
4144
this.responseConverter = responseConverter;
4245
this.serviceConfig = serviceConfig;
4346
this.boundedIoScheduler = boundedIoScheduler;
47+
this.requestTransformer = requestTransformer;
4448

4549
this.gatewayServiceStub =
4650
GatewayServiceGrpc.newFutureStub(
@@ -51,10 +55,11 @@ class GatewayServiceExplorerDao implements ExplorerDao {
5155

5256
@Override
5357
public Single<ExploreResultSet> explore(ExploreRequest request) {
54-
return this.requestBuilder
55-
.buildRequest(request)
58+
return this.requestTransformer
59+
.transform(request)
60+
.flatMap(this.requestBuilder::buildRequest)
5661
.subscribeOn(this.boundedIoScheduler)
57-
.flatMap(serverRequest -> this.makeRequest(request.requestContext(), serverRequest))
62+
.flatMap(serverRequest -> this.makeRequest(request.context(), serverRequest))
5863
.flatMap(serverResponse -> this.responseConverter.convert(request, serverResponse));
5964
}
6065

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private Single<Set<AttributeRequest>> buildGroupByAttributes(
177177
@Value
178178
@Accessors(fluent = true)
179179
private static class DefaultExploreRequest implements ExploreRequest {
180-
GraphQlRequestContext requestContext;
180+
GraphQlRequestContext context;
181181
String scope;
182182
TimeRangeArgument timeRange;
183183
int limit;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
import java.util.Set;
66
import org.hypertrace.core.graphql.common.request.AttributeAssociation;
77
import org.hypertrace.core.graphql.common.request.AttributeRequest;
8+
import org.hypertrace.core.graphql.common.request.ContextualRequest;
89
import org.hypertrace.core.graphql.common.schema.arguments.TimeRangeArgument;
910
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
10-
import org.hypertrace.core.graphql.context.GraphQlRequestContext;
1111
import org.hypertrace.graphql.explorer.schema.argument.IntervalArgument;
1212
import org.hypertrace.graphql.metric.request.MetricAggregationRequest;
1313

14-
public interface ExploreRequest {
15-
GraphQlRequestContext requestContext();
16-
14+
public interface ExploreRequest extends ContextualRequest {
1715
String scope();
1816

1917
TimeRangeArgument timeRange();

hypertrace-graphql-impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-span-schema")
2626
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-log-event-schema")
2727
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-trace-schema")
28+
implementation("org.hypertrace.core.graphql:hypertrace-core-graphql-request-transformation")
2829
implementation(project(":hypertrace-graphql-entity-schema"))
2930
implementation(project(":hypertrace-graphql-explorer-schema"))
3031
implementation(project(":hypertrace-graphql-explorer-context"))

hypertrace-graphql-impl/src/main/java/org/hypertrace/graphql/impl/GraphQlModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hypertrace.core.graphql.deserialization.GraphQlDeserializationRegistryModule;
1010
import org.hypertrace.core.graphql.log.event.LogEventSchemaModule;
1111
import org.hypertrace.core.graphql.metadata.MetadataSchemaModule;
12+
import org.hypertrace.core.graphql.request.transformation.RequestTransformationModule;
1213
import org.hypertrace.core.graphql.rx.RxUtilModule;
1314
import org.hypertrace.core.graphql.schema.registry.GraphQlSchemaRegistryModule;
1415
import org.hypertrace.core.graphql.span.SpanSchemaModule;
@@ -69,5 +70,6 @@ protected void configure() {
6970
install(new RxUtilModule());
7071
install(new EntityIdModule());
7172
install(new SpacesSchemaModule());
73+
install(new RequestTransformationModule());
7274
}
7375
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static class ActiveSpaceExploreRequest implements ExploreRequest {
140140
private static final String SPACE_IDS_SCOPE = "EVENT";
141141
private static final int MAX_SPACES = 100;
142142

143-
GraphQlRequestContext requestContext;
143+
GraphQlRequestContext context;
144144
String scope = SPACE_IDS_SCOPE;
145145
int limit = MAX_SPACES;
146146
int offset = 0;
@@ -161,7 +161,7 @@ private static class ActiveSpaceExploreRequest implements ExploreRequest {
161161
TimeRangeArgument timeRange,
162162
AttributeRequest spaceIdRequest,
163163
MetricAggregationRequest spaceIdCountRequest) {
164-
this.requestContext = context;
164+
this.context = context;
165165
this.timeRange = timeRange;
166166
// Aggregation needed to pass explorer validation - a no agg request is not valid
167167
this.aggregationRequests = Set.of(spaceIdCountRequest);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void makesAppropriateRequest() {
8080
.explore(
8181
argThat(
8282
request ->
83-
request.requestContext().equals(this.mockContext)
83+
request.context().equals(this.mockContext)
8484
&& request.scope().equals("EVENT")
8585
&& request.limit() == 100
8686
&& request.offset() == 0

0 commit comments

Comments
 (0)