Skip to content

Commit

Permalink
Merge pull request #42901 from alesj/obs_traces1
Browse files Browse the repository at this point in the history
Add LGTM traces test / check
  • Loading branch information
gsmet authored Sep 3, 2024
2 parents 15a7158 + 883b1ed commit 839d999
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.*;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem;
import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig;
import io.quarkus.opentelemetry.runtime.config.build.exporter.OtlpExporterBuildConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfigBuilder;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
import io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterRecorder;
import io.quarkus.opentelemetry.runtime.exporter.otlp.tracing.LateBoundBatchSpanProcessor;
Expand Down Expand Up @@ -59,6 +61,11 @@ public boolean getAsBoolean() {
}
}

@BuildStep
void config(BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilderProducer) {
runTimeConfigBuilderProducer.produce(new RunTimeConfigBuilderBuildItem(OtlpExporterConfigBuilder.class));
}

@SuppressWarnings("deprecation")
@BuildStep(onlyIf = OtlpExporterProcessor.OtlpTracingExporterEnabled.class)
@Record(ExecutionTime.RUNTIME_INIT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package io.quarkus.opentelemetry.runtime.config;
package io.quarkus.opentelemetry.runtime.config.runtime.exporter;

import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfig.DEFAULT_GRPC_BASE_URI;
import static io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfig.Protocol.GRPC;

import java.util.HashMap;
import java.util.Map;

import io.quarkus.runtime.configuration.ConfigBuilder;
import io.smallrye.config.FallbackConfigSourceInterceptor;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

public class OpenTelemetryConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
/**
* Adds fallbacks to {@link OtlpExporterRuntimeConfig#traces()} and {@link OtlpExporterRuntimeConfig#metrics()} from
* the base configuration {@link OtlpExporterRuntimeConfig}. The goal is to fallback specific properties from either
* <code>tracer</code> or <code>metrics</code> to their parent configuration. For instance, if there is no value for
* <code>quarkus.otel.exporter.otlp.traces.endpoint</code> it fallbacks to
* <code>quarkus.otel.exporter.otlp.endpoint</code>.
* <p>
* Defaults are set using the {@link SmallRyeConfigBuilder#withDefaultValue(String, String)}, instead of
* {@link io.smallrye.config.WithDefault} because the mapping {@link OtlpExporterConfig} is shared between base
* (unnamed), <code>traces</code>, and <code>metrics</code>, which means that every path would always have a default,
* and it won't be possible to fallback from the specific configuration to the base configuration.
* <p>
* This builder is only set to customize the runtime configuration since the mapping {@link OtlpExporterRuntimeConfig}
* is only for runtime. The builder executes with a very high priority to ensure that it sets the default
* configuration early in the config setup to allow other configurations to override it (like Dev Services).
*/
public class OtlpExporterConfigBuilder implements ConfigBuilder {
@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
// Main defaults
builder.withDefaultValue("quarkus.otel.exporter.otlp.endpoint", DEFAULT_GRPC_BASE_URI);
builder.withDefaultValue("quarkus.otel.exporter.otlp.protocol", GRPC);
Expand Down Expand Up @@ -60,6 +76,11 @@ public void configBuilder(final SmallRyeConfigBuilder builder) {
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.host", "quarkus.otel.exporter.otlp.proxy-options.host");
fallbacks.put("quarkus.otel.exporter.otlp.metrics.proxy-options.port", "quarkus.otel.exporter.otlp.proxy-options.port");

builder.withInterceptors(new FallbackConfigSourceInterceptor(fallbacks));
return builder.withInterceptors(new FallbackConfigSourceInterceptor(fallbacks));
}

@Override
public int priority() {
return Integer.MIN_VALUE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.junit.jupiter.api.Test;

import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterConfigBuilder;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterMetricsConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterTracesConfig;
Expand All @@ -39,7 +40,7 @@ void fromBase() {
baseExporterConfig.put("quarkus.otel.exporter.otlp.proxy-options.port", "9999");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.withCustomizers(new OpenTelemetryConfigBuilderCustomizer())
.withCustomizers(builder -> new OtlpExporterConfigBuilder().configBuilder(builder))
.withMapping(OtlpExporterRuntimeConfig.class)
.withDefaultValues(baseExporterConfig)
.build();
Expand Down Expand Up @@ -160,7 +161,7 @@ void overrideTraces() {
tracesExporterConfig.put("quarkus.otel.exporter.otlp.traces.proxy-options.port", "6666");

SmallRyeConfig config = new SmallRyeConfigBuilder()
.withCustomizers(new OpenTelemetryConfigBuilderCustomizer())
.withCustomizers(builder -> new OtlpExporterConfigBuilder().configBuilder(builder))
.withMapping(OtlpExporterRuntimeConfig.class)
.withDefaultValues(baseExporterConfig)
.withDefaultValues(tracesExporterConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ quarkus.micrometer.export.otlp.enabled=true
quarkus.micrometer.export.otlp.publish=true
quarkus.micrometer.export.otlp.step=PT5S
quarkus.micrometer.export.otlp.default-registry=true
%dev.quarkus.micrometer.export.otlp.url=http://${quarkus.otel-collector.url}/v1/metrics
%prod.quarkus.micrometer.export.otlp.url=http://localhost:4318/v1/metrics

#opentelemetry
quarkus.otel.exporter.otlp.traces.protocol=http/protobuf
%dev.quarkus.otel.exporter.otlp.traces.endpoint=http://${quarkus.otel-collector.url}
%prod.quarkus.otel.exporter.otlp.traces.endpoint=http://localhost:4318

#quarkus.observability.lgtm.image-name=grafana/otel-lgtm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public void testTracing() {
Awaitility.await().atMost(61, TimeUnit.SECONDS).until(
() -> client.query("xvalue_X"),
result -> !result.data.result.isEmpty());
Awaitility.await().atMost(61, TimeUnit.SECONDS).until(
() -> client.traces("quarkus-integration-test-observability-lgtm", 20, 3),
result -> !result.traces.isEmpty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,23 @@ public QueryResult query(String query) {
});
return ref.get();
}

public TempoResult traces(String service, int limit, int spss) {
AtomicReference<TempoResult> ref = new AtomicReference<>();
String path = "/api/datasources/proxy/uid/tempo/api/search?q=%7Bresource.service.name%3D%22"
+ service + "%22%7D&limit=" + limit + "&spss=" + spss;
handle(
path,
HttpRequest.Builder::GET,
HttpResponse.BodyHandlers.ofString(),
(r, b) -> {
try {
TempoResult result = MAPPER.readValue(b, TempoResult.class);
ref.set(result);
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
});
return ref.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.observability.test.support;

import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class TempoResult {
public List<Map<Object, Object>> traces;
public Metrics metrics;

// getters and setters

@Override
public String toString() {
return "TempoResult{" +
"traces=" + traces +
", metrics=" + metrics +
'}';
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static class Metrics {
public int inspectedBytes;
public int completedJobs;
public int totalJobs;

@Override
public String toString() {
return "Metrics{" +
"inspectedBytes=" + inspectedBytes +
", completedJobs=" + completedJobs +
", totalJobs=" + totalJobs +
'}';
}
}
}

0 comments on commit 839d999

Please sign in to comment.