Skip to content

Commit

Permalink
Add observability-devservices-lgtm dependency to opentelmetry, to sta…
Browse files Browse the repository at this point in the history
…rt devservices by default
  • Loading branch information
The-Huginn committed Jun 26, 2024
1 parent a5ffb89 commit 60c8913
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 13 deletions.
5 changes: 5 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,11 @@
<artifactId>quarkus-observability-devservices</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-lgtm</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.observability.deployment;

import java.time.Duration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -12,6 +13,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.quarkus.deployment.Feature;
Expand All @@ -37,12 +39,17 @@
import io.quarkus.observability.devresource.DevResources;
import io.quarkus.observability.runtime.config.ObservabilityConfiguration;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.smallrye.config.SmallRyeConfig;

@BuildSteps(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class,
ObservabilityDevServiceProcessor.IsEnabled.class })
class ObservabilityDevServiceProcessor {
private static final Logger log = Logger.getLogger(ObservabilityDevServiceProcessor.class);

private static final String OTEL_COLLECTOR_URL = "quarkus.otel-collector.url";
private static final String OTEL_COLLECTOR_URL_EXPRESSION = "http://${%s}".formatted(OTEL_COLLECTOR_URL);
private static final String OTLP_TRACES_ENDPOINT = "quarkus.otel.exporter.otlp.traces.endpoint";
private static final Map<String, DevServicesResultBuildItem.RunningDevService> devServices = new ConcurrentHashMap<>();
private static final Map<String, ContainerConfig> capturedDevServicesConfigurations = new ConcurrentHashMap<>();
private static final Map<String, Boolean> firstStart = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -76,6 +83,14 @@ public void startContainers(LaunchModeBuildItem launchMode,
GlobalDevServicesConfig devServicesConfig,
BuildProducer<DevServicesResultBuildItem> services) {

// To keep backwards compatibility we want to allow "http://${quarkus.otel-collector.url}" expression as a value
if (ConfigUtils.isPropertyPresent(OTLP_TRACES_ENDPOINT) &&
!ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).getConfigValue(OTLP_TRACES_ENDPOINT).getRawValue()
.equals(OTEL_COLLECTOR_URL_EXPRESSION)) {
log.infof("Observability dev services won't start due to property [%s] being defined", OTLP_TRACES_ENDPOINT);
return;
}

if (!configuration.enabled()) {
log.infof("Observability dev services are disabled in config");
return;
Expand Down Expand Up @@ -193,7 +208,8 @@ private DevServicesResultBuildItem.RunningDevService startContainer(
final Supplier<DevServicesResultBuildItem.RunningDevService> defaultContainerSupplier = () -> {
Container<?> container = dev.container(capturedDevServicesConfiguration, root);
timeout.ifPresent(container::withStartupTimeout);
Map<String, String> config = dev.start();
Map<String, String> config = new HashMap<>(dev.start());
addCollectorUrlProperty(config);
log.infof("Dev Service %s started, config: %s", devId, config);
return new DevServicesResultBuildItem.RunningDevService(
Feature.OBSERVABILITY.getName(), container.getContainerId(),
Expand All @@ -205,12 +221,31 @@ private DevServicesResultBuildItem.RunningDevService startContainer(
return containerLocator
.locateContainer(
capturedDevServicesConfiguration.serviceName(), capturedDevServicesConfiguration.shared(),
LaunchMode.current(), (p, ca) -> config.putAll(dev.config(p, ca.getHost(), ca.getPort())))
LaunchMode.current(), (p, ca) -> {
config.putAll(dev.config(p, ca.getHost(), ca.getPort()));
addCollectorUrlProperty(config);
})
.map(cid -> {
log.infof("Dev Service %s re-used, config: %s", devId, config);
return new DevServicesResultBuildItem.RunningDevService(Feature.OBSERVABILITY.getName(), cid,
null, config);
})
.orElseGet(defaultContainerSupplier);
}

/**
* Adds property {@code OTEL_COLLECTOR_URL} to keep backwards compatibility if {@code OTLP_TRACES_ENDPOINT} is defined
* i.e. previously this was possible "quarkus.otel.exporter.otlp.traces.endpoint=http://${quarkus.otel-collector.url}"
* and now we set {@code OTLP_TRACES_ENDPOINT} directly and we set {@code OTEL_COLLECTOR_URL} in case this is still
* referenced.
*
* @param config
* @return
*/
private static void addCollectorUrlProperty(Map<String, String> config) {
// Remove leading http:// from the variable
if (config.containsKey(OTLP_TRACES_ENDPOINT)) {
config.put(OTEL_COLLECTOR_URL, config.get(OTLP_TRACES_ENDPOINT).substring("http://".length()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

public class LgtmResource extends ContainerResource<LgtmContainer, LgtmConfig> {

private static final String OTLP_TRACES_PROTOCOL = "quarkus.otel.exporter.otlp.traces.protocol";
private static final String HTTP_PROTOBUF = "http/protobuf";
private static final String OTLP_TRACES_ENDPOINT = "quarkus.otel.exporter.otlp.traces.endpoint";
private static final String OTLP_TRACES_ENDPOINT_CONVERTER = "http://%s:%s";
private static final String GRAFANA_URL = "quarkus.grafana.url";

@Override
public LgtmConfig config(ModulesConfiguration configuration) {
return configuration.lgtm();
Expand All @@ -26,10 +32,11 @@ public Container<LgtmConfig> container(LgtmConfig config, ModulesConfiguration r
public Map<String, String> config(int privatePort, String host, int publicPort) {
switch (privatePort) {
case ContainerConstants.GRAFANA_PORT:
return Map.of("quarkus.grafana.url", String.format("%s:%s", host, publicPort));
return Map.of(GRAFANA_URL, String.format("%s:%s", host, publicPort));
case ContainerConstants.OTEL_GRPC_EXPORTER_PORT:
case ContainerConstants.OTEL_HTTP_EXPORTER_PORT:
return Map.of("quarkus.otel-collector.url", String.format("%s:%s", host, publicPort));
return Map.of(OTLP_TRACES_ENDPOINT, OTLP_TRACES_ENDPOINT_CONVERTER.formatted(host, publicPort),
OTLP_TRACES_PROTOCOL, HTTP_PROTOBUF);
}
return Map.of();
}
Expand All @@ -43,8 +50,9 @@ protected LgtmContainer defaultContainer() {
public Map<String, String> doStart() {
String host = container.getHost();
return Map.of(
"quarkus.grafana.url", String.format("%s:%s", host, container.getGrafanaPort()),
"quarkus.otel-collector.url", String.format("%s:%s", host, container.getOtlpPort()));
GRAFANA_URL, String.format("%s:%s", host, container.getGrafanaPort()),
OTLP_TRACES_ENDPOINT, OTLP_TRACES_ENDPOINT_CONVERTER.formatted(host, container.getOtlpPort()),
OTLP_TRACES_PROTOCOL, HTTP_PROTOBUF);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions extensions/opentelemetry/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-deployment</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
quarkus.otel.traces.exporter=test-span-exporter
quarkus.otel.bsp.schedule.delay=50
quarkus.otel.bsp.export.timeout=1s
quarkus.otel.bsp.export.timeout=1s
quarkus.observability.enabled=false
16 changes: 16 additions & 0 deletions extensions/opentelemetry/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices</artifactId>
<exclusions>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devresource-lgtm</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tls-registry</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
quarkus.native.monitoring=jfr
quarkus.native.monitoring=jfr

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ quarkus.grpc.clients.hello.host=localhost
%test.quarkus.grpc.clients.hello.port=9001

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
quarkus.otel.bsp.export.timeout=5s

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ quarkus.application.version=999-SNAPSHOT
quarkus.otel.traces.sampler=jaeger_remote
quarkus.otel.traces.sampler.arg=endpoint=http://localhost:14250,pollingInterval=5000,initialSamplingRate=1.0
quarkus.otel.traces.exporter=jaeger

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s

quarkus.scheduler.tracing.enabled=true
quarkus.scheduler.tracing.enabled=true

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# speed up build
quarkus.otel.bsp.schedule.delay=0
quarkus.otel.bsp.export.timeout=5s

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ mp.messaging.incoming.traces-in2.topic=traces2
mp.messaging.incoming.traces-in2.auto.offset.reset=earliest

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
quarkus.otel.bsp.export.timeout=5s

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ quarkus.http.auth.permission.secured.policy=authenticated
quarkus.http.auth.permission.secured.paths=/secured/*

quarkus.otel.security-events.enabled=true

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ quarkus.redis.devservices.port=16379
# speed up build
quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s

quarkus.scheduler.tracing.enabled=true
quarkus.scheduler.tracing.enabled=true

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ quarkus.otel.bsp.export.timeout=5s

pingpong/mp-rest/url=${test.url}
simple/mp-rest/url=${test.url}

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
quarkus.application.name=integration test

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ quarkus.micrometer.enabled=true
quarkus.micrometer.binder-enabled-default=false

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
quarkus.otel.bsp.export.timeout=5s

quarkus.observability.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ quarkus.security.users.embedded.users.scott=reader
quarkus.security.users.embedded.plain-text=true
quarkus.security.users.embedded.enabled=true
quarkus.http.auth.basic=true

quarkus.observability.enabled=false

0 comments on commit 60c8913

Please sign in to comment.