Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.hypertrace.core.graphql.attributes.IdMapping.forForeignId;
import static org.hypertrace.core.graphql.attributes.IdMapping.forId;
import static org.hypertrace.core.graphql.atttributes.scopes.HypertraceCoreAttributeScopeString.LOG_EVENT;
import static org.hypertrace.core.graphql.atttributes.scopes.HypertraceCoreAttributeScopeString.SPAN;
import static org.hypertrace.core.graphql.atttributes.scopes.HypertraceCoreAttributeScopeString.TRACE;

Expand All @@ -21,7 +22,7 @@ protected void configure() {
Multibinder<IdMapping> idBinder = Multibinder.newSetBinder(binder(), IdMapping.class);
idBinder.addBinding().toInstance(forId(SPAN, "id"));
idBinder.addBinding().toInstance(forForeignId(SPAN, TRACE, "traceId"));

idBinder.addBinding().toInstance(forForeignId(LOG_EVENT, SPAN, "spanId"));
idBinder.addBinding().toInstance(forId(TRACE, "id"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.hypertrace.core.graphql.common.schema.attributes.arguments.AttributeKeyArgument;

public interface AttributeQueryable {

String ATTRIBUTE_FIELD_NAME = "attribute";

@GraphQLField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
api(project(":hypertrace-core-graphql-attribute-store"))
api("io.reactivex.rxjava3:rxjava")
api(project(":hypertrace-core-graphql-common-schema"))
implementation(project(":hypertrace-core-graphql-grpc-utils"))

testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockito:mockito-core")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.hypertrace.core.graphql.utils.gateway;

import io.grpc.CallCredentials;
import javax.inject.Inject;
import javax.inject.Provider;
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
import org.hypertrace.gateway.service.GatewayServiceGrpc;
import org.hypertrace.gateway.service.GatewayServiceGrpc.GatewayServiceFutureStub;

class GatewayServiceFutureStubProvider implements Provider<GatewayServiceFutureStub> {

private final GraphQlServiceConfig serviceConfig;
private final CallCredentials credentials;
private final GrpcChannelRegistry channelRegistry;

@Inject
GatewayServiceFutureStubProvider(
GraphQlServiceConfig serviceConfig,
CallCredentials credentials,
GrpcChannelRegistry channelRegistry) {
this.serviceConfig = serviceConfig;
this.credentials = credentials;
this.channelRegistry = channelRegistry;
}

@Override
public GatewayServiceFutureStub get() {
return GatewayServiceGrpc.newFutureStub(
channelRegistry.forAddress(
serviceConfig.getGatewayServiceHost(), serviceConfig.getGatewayServicePort()))
.withCallCredentials(credentials);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.inject.AbstractModule;
import com.google.inject.Key;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import java.util.Collection;
import java.util.List;
Expand All @@ -15,6 +16,7 @@
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderDirection;
import org.hypertrace.core.graphql.common.utils.BiConverter;
import org.hypertrace.core.graphql.common.utils.Converter;
import org.hypertrace.gateway.service.GatewayServiceGrpc.GatewayServiceFutureStub;
import org.hypertrace.gateway.service.v1.common.ColumnIdentifier;
import org.hypertrace.gateway.service.v1.common.Expression;
import org.hypertrace.gateway.service.v1.common.Filter;
Expand Down Expand Up @@ -62,5 +64,9 @@ protected void configure() {

bind(Key.get(new TypeLiteral<Converter<OrderDirection, SortOrder>>() {}))
.to(SortOrderConverter.class);

bind(GatewayServiceFutureStub.class)
.toProvider(GatewayServiceFutureStubProvider.class)
.in(Singleton.class);
}
}
3 changes: 3 additions & 0 deletions hypertrace-core-graphql-log-event-schema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation(project(":hypertrace-core-graphql-gateway-service-utils"))
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")

testAnnotationProcessor("org.projectlombok:lombok")
testCompileOnly("org.projectlombok:lombok")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.hypertrace.core.graphql.log.event.dao;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import io.grpc.CallCredentials;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
Expand All @@ -18,7 +21,9 @@
import org.hypertrace.core.graphql.common.schema.results.arguments.filter.FilterArgument;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.common.utils.Converter;
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
import org.hypertrace.core.graphql.utils.gateway.GatewayUtilsModule;
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
import org.hypertrace.gateway.service.v1.common.Expression;
import org.hypertrace.gateway.service.v1.common.Filter;
import org.hypertrace.gateway.service.v1.common.OrderByExpression;
Expand All @@ -32,7 +37,17 @@ class GatewayServiceLogEventsRequestBuilderTest extends BaseDaoTest {

@BeforeEach
void setup() {
Injector injector = Guice.createInjector(new GatewayUtilsModule());
Injector injector =
Guice.createInjector(
new GatewayUtilsModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(CallCredentials.class).toInstance(mock(CallCredentials.class));
bind(GraphQlServiceConfig.class).toInstance(mock(GraphQlServiceConfig.class));
bind(GrpcChannelRegistry.class).toInstance(mock(GrpcChannelRegistry.class));
}
});

Converter<Collection<AttributeAssociation<FilterArgument>>, Filter> filterConverter =
injector.getInstance(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.hypertrace.core.graphql.log.event.dao;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import io.grpc.CallCredentials;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
Expand All @@ -16,7 +19,9 @@
import org.hypertrace.core.graphql.common.request.AttributeRequest;
import org.hypertrace.core.graphql.common.utils.BiConverter;
import org.hypertrace.core.graphql.log.event.schema.LogEventResultSet;
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
import org.hypertrace.core.graphql.utils.gateway.GatewayUtilsModule;
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
import org.hypertrace.gateway.service.v1.common.Value;
import org.hypertrace.gateway.service.v1.common.ValueType;
import org.hypertrace.gateway.service.v1.log.events.LogEvent;
Expand All @@ -30,7 +35,17 @@ class GatewayServiceLogEventsResponseConverterTest extends BaseDaoTest {

@BeforeEach
void setup() {
Injector injector = Guice.createInjector(new GatewayUtilsModule());
Injector injector =
Guice.createInjector(
new GatewayUtilsModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(CallCredentials.class).toInstance(mock(CallCredentials.class));
bind(GraphQlServiceConfig.class).toInstance(mock(GraphQlServiceConfig.class));
bind(GrpcChannelRegistry.class).toInstance(mock(GrpcChannelRegistry.class));
}
});
BiConverter<Collection<AttributeRequest>, Map<String, Value>, Map<String, Object>>
attributeMapConverter =
injector.getInstance(
Expand Down
17 changes: 17 additions & 0 deletions hypertrace-core-graphql-span-schema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@ dependencies {
implementation(project(":hypertrace-core-graphql-grpc-utils"))
implementation(project(":hypertrace-core-graphql-common-schema"))
implementation(project(":hypertrace-core-graphql-attribute-store"))
implementation(project(":hypertrace-core-graphql-log-event-schema"))
implementation(project(":hypertrace-core-graphql-deserialization"))
implementation(project(":hypertrace-core-graphql-schema-utils"))
implementation(project(":hypertrace-core-graphql-attribute-scope-constants"))

testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation(project(":hypertrace-core-graphql-gateway-service-utils"))
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")

testAnnotationProcessor("org.projectlombok:lombok")
testCompileOnly("org.projectlombok:lombok")
}

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.inject.multibindings.Multibinder;
import org.hypertrace.core.graphql.common.request.ResultSetRequestBuilder;
import org.hypertrace.core.graphql.span.dao.SpanDaoModule;
import org.hypertrace.core.graphql.span.request.SpanRequestModule;
import org.hypertrace.core.graphql.spi.schema.GraphQlSchemaFragment;

public class SpanSchemaModule extends AbstractModule {
Expand All @@ -15,5 +16,6 @@ protected void configure() {

requireBinding(ResultSetRequestBuilder.class);
install(new SpanDaoModule());
install(new SpanRequestModule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import lombok.experimental.Accessors;
import org.hypertrace.core.graphql.common.request.AttributeRequest;
import org.hypertrace.core.graphql.common.request.ResultSetRequest;
import org.hypertrace.core.graphql.common.utils.BiConverter;
import org.hypertrace.core.graphql.log.event.schema.LogEvent;
import org.hypertrace.core.graphql.log.event.schema.LogEventResultSet;
import org.hypertrace.core.graphql.span.request.SpanRequest;
import org.hypertrace.core.graphql.span.schema.Span;
import org.hypertrace.core.graphql.span.schema.SpanResultSet;
import org.hypertrace.gateway.service.v1.common.Value;
import org.hypertrace.gateway.service.v1.span.SpanEvent;
import org.hypertrace.gateway.service.v1.span.SpansResponse;

class GatewayServiceSpanConverter {

Expand All @@ -28,34 +30,46 @@ class GatewayServiceSpanConverter {
this.attributeMapConverter = attributeMapConverter;
}

public Single<SpanResultSet> convert(ResultSetRequest<?> request, SpansResponse response) {
int total = response.getTotal();
public Single<SpanResultSet> convert(SpanRequest request, SpanLogEventsResponse response) {
int total = response.spansResponse().getTotal();

return Observable.fromIterable(response.getSpansList())
.flatMapSingle(spanEvent -> this.convert(request, spanEvent))
return Observable.fromIterable(response.spansResponse().getSpansList())
.flatMapSingle(spanEvent -> this.convert(request, spanEvent, response.spanIdToLogEvents()))
.toList()
.map(spans -> new ConvertedSpanResultSet(spans, total, spans.size()));
}

private Single<Span> convert(ResultSetRequest<?> request, SpanEvent spanEvent) {
private Single<Span> convert(
SpanRequest request, SpanEvent spanEvent, Map<String, List<LogEvent>> spanIdToLogEvents) {
return this.attributeMapConverter
.convert(request.attributes(), spanEvent.getAttributesMap())
.convert(request.spanEventsRequest().attributes(), spanEvent.getAttributesMap())
.map(
attrMap ->
new ConvertedSpan(
attrMap.get(request.idAttribute().attribute().key()).toString(), attrMap));
attrMap
.get(request.spanEventsRequest().idAttribute().attribute().key())
.toString(),
attrMap,
spanIdToLogEvents));
}

@lombok.Value
@Accessors(fluent = true)
private static class ConvertedSpan implements Span {
String id;
Map<String, Object> attributeValues;
Map<String, List<LogEvent>> spanIdToLogEvents;

@Override
public Object attribute(String key) {
return this.attributeValues.get(key);
}

@Override
public LogEventResultSet logEvents() {
List<LogEvent> list = spanIdToLogEvents.getOrDefault(id, Collections.emptyList());
return new ConvertedLogEventResultSet(list, list.size(), list.size());
}
}

@lombok.Value
Expand All @@ -65,4 +79,12 @@ private static class ConvertedSpanResultSet implements SpanResultSet {
long total;
long count;
}

@lombok.Value
@Accessors(fluent = true)
private static class ConvertedLogEventResultSet implements LogEventResultSet {
List<LogEvent> results;
long total;
long count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

import static java.util.concurrent.TimeUnit.SECONDS;

import io.grpc.CallCredentials;
import io.reactivex.rxjava3.core.Single;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.hypertrace.core.graphql.common.request.ResultSetRequest;
import org.hypertrace.core.graphql.common.schema.results.arguments.order.OrderArgument;
import org.hypertrace.core.graphql.context.GraphQlRequestContext;
import org.hypertrace.core.graphql.span.request.SpanRequest;
import org.hypertrace.core.graphql.span.schema.SpanResultSet;
import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig;
import org.hypertrace.core.graphql.utils.grpc.GraphQlGrpcContextBuilder;
import org.hypertrace.core.graphql.utils.grpc.GrpcChannelRegistry;
import org.hypertrace.gateway.service.GatewayServiceGrpc;
import org.hypertrace.gateway.service.GatewayServiceGrpc.GatewayServiceFutureStub;
import org.hypertrace.gateway.service.v1.span.SpansRequest;
import org.hypertrace.gateway.service.v1.span.SpansResponse;
Expand All @@ -25,32 +20,31 @@ class GatewayServiceSpanDao implements SpanDao {
private final GraphQlGrpcContextBuilder grpcContextBuilder;
private final GatewayServiceSpanRequestBuilder requestBuilder;
private final GatewayServiceSpanConverter spanConverter;
private final SpanLogEventDao spanLogEventDao;

@Inject
GatewayServiceSpanDao(
GraphQlServiceConfig serviceConfig,
CallCredentials credentials,
GatewayServiceFutureStub gatewayServiceFutureStub,
GraphQlGrpcContextBuilder grpcContextBuilder,
GrpcChannelRegistry channelRegistry,
GatewayServiceSpanRequestBuilder requestBuilder,
GatewayServiceSpanConverter spanConverter) {
GatewayServiceSpanConverter spanConverter,
SpanLogEventDao spanLogEventDao) {
this.grpcContextBuilder = grpcContextBuilder;
this.requestBuilder = requestBuilder;
this.spanConverter = spanConverter;

this.gatewayServiceStub =
GatewayServiceGrpc.newFutureStub(
channelRegistry.forAddress(
serviceConfig.getGatewayServiceHost(), serviceConfig.getGatewayServicePort()))
.withCallCredentials(credentials);
this.spanLogEventDao = spanLogEventDao;
this.gatewayServiceStub = gatewayServiceFutureStub;
}

@Override
public Single<SpanResultSet> getSpans(ResultSetRequest<OrderArgument> request) {
public Single<SpanResultSet> getSpans(SpanRequest request) {
return this.requestBuilder
.buildRequest(request)
.flatMap(serverRequest -> this.makeRequest(request.context(), serverRequest))
.flatMap(serverResponse -> this.spanConverter.convert(request, serverResponse));
.flatMap(
serverRequest -> this.makeRequest(request.spanEventsRequest().context(), serverRequest))
.flatMap(serverResponse -> spanLogEventDao.fetchLogEvents(request, serverResponse))
.flatMap(
spanLogEventsResponse -> this.spanConverter.convert(request, spanLogEventsResponse));
}

private Single<SpansResponse> makeRequest(GraphQlRequestContext context, SpansRequest request) {
Expand Down
Loading