Skip to content

Commit 5a8d6d3

Browse files
authored
feat: adding consumer support for new traces/spans api (#140)
* feat: adding consumer support for new traces/spans api * updated the spans result set * addressed the comments and updated gateway lib * fixed owas issue, need to extend supression
1 parent 984a7e2 commit 5a8d6d3

File tree

13 files changed

+60
-14
lines changed

13 files changed

+60
-14
lines changed

hypertrace-core-graphql-platform/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies {
1616
api("org.hypertrace.core.grpcutils:grpc-context-utils:0.12.1")
1717
api("org.hypertrace.core.grpcutils:grpc-client-utils:0.12.1")
1818
api("org.hypertrace.core.grpcutils:grpc-client-rx-utils:0.12.1")
19-
api("org.hypertrace.gateway.service:gateway-service-api:0.2.25")
19+
api("org.hypertrace.gateway.service:gateway-service-api:0.3.0")
2020
api("org.hypertrace.core.attribute.service:caching-attribute-service-client:${attributeServiceVersion}")
2121
api("org.hypertrace.core.attribute.service:attribute-service-api:${attributeServiceVersion}")
2222

hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/GatewayServiceSpanConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GatewayServiceSpanConverter {
3434
}
3535

3636
public Single<SpanResultSet> convert(SpanRequest request, SpanLogEventsResponse response) {
37-
int total = response.spansResponse().getTotal();
37+
int total = response.spansResponse().hasTotal() ? response.spansResponse().getTotal() : 0;
3838

3939
return Observable.fromIterable(response.spansResponse().getSpansList())
4040
.flatMapSingle(spanEvent -> this.convert(request, spanEvent, response.spanIdToLogEvents()))

hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/GatewayServiceSpanRequestBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Single<SpansRequest> buildRequest(SpanRequest gqlRequest) {
5656
.spanEventsRequest()
5757
.spaceId()
5858
.orElse("")) // String proto default value
59+
.setFetchTotal(gqlRequest.fetchTotal())
5960
.build());
6061
}
6162
}

hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/request/DefaultSpanRequestBuilder.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,40 @@
1515
import org.hypertrace.core.graphql.common.request.ResultSetRequest;
1616
import org.hypertrace.core.graphql.common.request.ResultSetRequestBuilder;
1717
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeExpression;
18+
import org.hypertrace.core.graphql.common.schema.results.ResultSet;
1819
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
1920
import org.hypertrace.core.graphql.context.GraphQlRequestContext;
21+
import org.hypertrace.core.graphql.utils.schema.GraphQlSelectionFinder;
22+
import org.hypertrace.core.graphql.utils.schema.SelectionQuery;
2023

2124
class DefaultSpanRequestBuilder implements SpanRequestBuilder {
2225

2326
private final ResultSetRequestBuilder resultSetRequestBuilder;
2427
private final LogEventAttributeRequestBuilder logEventAttributeRequestBuilder;
28+
private final GraphQlSelectionFinder selectionFinder;
2529

2630
@Inject
2731
public DefaultSpanRequestBuilder(
2832
ResultSetRequestBuilder resultSetRequestBuilder,
29-
LogEventAttributeRequestBuilder logEventAttributeRequestBuilder) {
33+
LogEventAttributeRequestBuilder logEventAttributeRequestBuilder,
34+
GraphQlSelectionFinder selectionFinder) {
3035
this.resultSetRequestBuilder = resultSetRequestBuilder;
3136
this.logEventAttributeRequestBuilder = logEventAttributeRequestBuilder;
37+
this.selectionFinder = selectionFinder;
3238
}
3339

3440
@Override
3541
public Single<SpanRequest> build(
3642
GraphQlRequestContext context,
3743
Map<String, Object> arguments,
3844
DataFetchingFieldSelectionSet selectionSet) {
45+
boolean fetchTotal =
46+
this.selectionFinder
47+
.findSelections(
48+
selectionSet, SelectionQuery.namedChild(ResultSet.RESULT_SET_TOTAL_NAME))
49+
.count()
50+
> 0;
51+
3952
return zip(
4053
resultSetRequestBuilder.build(
4154
context,
@@ -45,7 +58,8 @@ public Single<SpanRequest> build(
4558
OrderArgument.class),
4659
logEventAttributeRequestBuilder.buildAttributeRequest(context, selectionSet),
4760
(resultSetRequest, logEventAttributeRequest) ->
48-
new DefaultSpanRequest(context, resultSetRequest, logEventAttributeRequest));
61+
new DefaultSpanRequest(
62+
context, resultSetRequest, logEventAttributeRequest, fetchTotal));
4963
}
5064

5165
@Override
@@ -54,12 +68,16 @@ public Single<SpanRequest> build(
5468
Map<String, Object> arguments,
5569
List<AttributeExpression> spanAttributeExpressions,
5670
List<AttributeExpression> logAttributeExpressions) {
71+
5772
return zip(
5873
resultSetRequestBuilder.build(
5974
context, HypertraceCoreAttributeScopeString.SPAN, arguments, spanAttributeExpressions),
6075
logEventAttributeRequestBuilder.buildAttributeRequest(context, logAttributeExpressions),
6176
(resultSetRequest, logEventAttributeRequest) ->
62-
new DefaultSpanRequest(context, resultSetRequest, logEventAttributeRequest));
77+
// This build method is utilized in the exportSpans API, which does not accept the total
78+
// parameter as an argument. Ref {@link ExportSpanResult}.
79+
// So, we explicitly set fetchTotal to false.
80+
new DefaultSpanRequest(context, resultSetRequest, logEventAttributeRequest, false));
6381
}
6482

6583
@Value
@@ -68,5 +86,6 @@ private static class DefaultSpanRequest implements SpanRequest {
6886
GraphQlRequestContext context;
6987
ResultSetRequest<OrderArgument> spanEventsRequest;
7088
Collection<AttributeRequest> logEventAttributes;
89+
boolean fetchTotal;
7190
}
7291
}

hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/request/SpanRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public interface SpanRequest extends ContextualRequest {
1010
ResultSetRequest<OrderArgument> spanEventsRequest();
1111

1212
Collection<AttributeRequest> logEventAttributes();
13+
14+
boolean fetchTotal();
1315
}

hypertrace-core-graphql-span-schema/src/test/java/org/hypertrace/core/graphql/span/dao/DaoTestUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static class DefaultSpanRequest implements SpanRequest {
7272
GraphQlRequestContext context;
7373
ResultSetRequest<OrderArgument> spanEventsRequest;
7474
Collection<AttributeRequest> logEventAttributes;
75+
boolean fetchTotal;
7576
}
7677

7778
@Value

hypertrace-core-graphql-span-schema/src/test/java/org/hypertrace/core/graphql/span/dao/SpanLogEventRequestBuilderTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ void testBuildRequest() {
152152
List.of(),
153153
Collections.emptyList(),
154154
Optional.empty());
155-
SpanRequest spanRequest = new DefaultSpanRequest(null, resultSetRequest, logAttributeRequests);
155+
SpanRequest spanRequest =
156+
new DefaultSpanRequest(null, resultSetRequest, logAttributeRequests, true);
156157

157158
LogEventsRequest expectedLogEventsRequest =
158159
LogEventsRequest.newBuilder()
@@ -193,7 +194,8 @@ void testBuildRequest_addSpanId() {
193194
List.of(),
194195
Collections.emptyList(),
195196
Optional.empty());
196-
SpanRequest spanRequest = new DefaultSpanRequest(null, resultSetRequest, logAttributeRequests);
197+
SpanRequest spanRequest =
198+
new DefaultSpanRequest(null, resultSetRequest, logAttributeRequests, true);
197199

198200
LogEventsRequest expectedLogEventsRequest =
199201
LogEventsRequest.newBuilder()

hypertrace-core-graphql-trace-schema/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ dependencies {
2424
implementation(project(":hypertrace-core-graphql-attribute-store"))
2525
implementation(project(":hypertrace-core-graphql-deserialization"))
2626
implementation(project(":hypertrace-core-graphql-request-transformation"))
27+
implementation(project(":hypertrace-core-graphql-schema-utils"))
2728
}

hypertrace-core-graphql-trace-schema/src/main/java/org/hypertrace/core/graphql/trace/dao/GatewayServiceTraceConverter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public class GatewayServiceTraceConverter {
3030
}
3131

3232
public Single<TraceResultSet> convert(ResultSetRequest<?> request, TracesResponse response) {
33-
int total = response.getTotal();
34-
33+
int total = response.hasTotal() ? response.getTotal() : 0;
3534
return Observable.fromIterable(response.getTracesList())
3635
.flatMapSingle(trace -> this.convert(request, trace))
3736
.toList()

hypertrace-core-graphql-trace-schema/src/main/java/org/hypertrace/core/graphql/trace/dao/GatewayServiceTraceRequestBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Single<TracesRequest> buildRequest(TraceRequest request) {
5454
.setFilter(filters)
5555
.setSpaceId(
5656
request.resultSetRequest().spaceId().orElse("")) // String proto default value
57+
.setFetchTotal(request.fetchTotal())
5758
.build());
5859
}
5960
}

0 commit comments

Comments
 (0)