Add service connection from OpenTelemetry Collector
See gh-35082
This commit is contained in:
committed by
Moritz Halbritter
parent
4bb2e918ed
commit
6997277f75
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.otlp;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create {@link OtlpConnectionDetails}
|
||||
* for a {@code otlp} service.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
class OpenTelemetryDockerComposeConnectionDetailsFactory
|
||||
extends DockerComposeConnectionDetailsFactory<OtlpConnectionDetails> {
|
||||
|
||||
private static final int OTLP_PORT = 4318;
|
||||
|
||||
OpenTelemetryDockerComposeConnectionDetailsFactory() {
|
||||
super("otel/opentelemetry-collector-contrib",
|
||||
"org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OtlpConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new OpenTelemetryContainerConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
private static final class OpenTelemetryContainerConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements OtlpConnectionDetails {
|
||||
|
||||
private final String host;
|
||||
|
||||
private final int port;
|
||||
|
||||
private OpenTelemetryContainerConnectionDetails(RunningService source) {
|
||||
super(source);
|
||||
this.host = source.host();
|
||||
this.port = source.ports().get(OTLP_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return "http://" + this.host + ":" + this.port + "/v1/metrics";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.otlp;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create
|
||||
* {@link OtlpTracingConnectionDetails} for a {@code otlp} service.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
class OpenTelemetryTracingDockerComposeConnectionDetailsFactory
|
||||
extends DockerComposeConnectionDetailsFactory<OtlpTracingConnectionDetails> {
|
||||
|
||||
private static final int OTLP_PORT = 4318;
|
||||
|
||||
OpenTelemetryTracingDockerComposeConnectionDetailsFactory() {
|
||||
super("otel/opentelemetry-collector-contrib",
|
||||
"org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpAutoConfiguration");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OtlpTracingConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new OpenTelemetryTracingDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
private static final class OpenTelemetryTracingDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements OtlpTracingConnectionDetails {
|
||||
|
||||
private final String host;
|
||||
|
||||
private final int port;
|
||||
|
||||
private OpenTelemetryTracingDockerComposeConnectionDetails(RunningService source) {
|
||||
super(source);
|
||||
this.host = source.host();
|
||||
this.port = source.ports().get(OTLP_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEndpoint() {
|
||||
return "http://" + this.host + ":" + this.port + "/v1/traces";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support for docker compose OpenTelemetry service connections.
|
||||
*/
|
||||
package org.springframework.boot.docker.compose.service.connection.otlp;
|
||||
@@ -17,6 +17,8 @@ org.springframework.boot.docker.compose.service.connection.mysql.MySqlJdbcDocker
|
||||
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryTracingDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.postgres.PostgresJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.postgres.PostgresR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.pulsar.PulsarDockerComposeConnectionDetailsFactory,\
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.otlp;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpConnectionDetails;
|
||||
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
|
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link OpenTelemetryDockerComposeConnectionDetailsFactory}.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class OpenTelemetryDockerComposeConnectionDetailsFactoryIntegrationTests
|
||||
extends AbstractDockerComposeIntegrationTests {
|
||||
|
||||
OpenTelemetryDockerComposeConnectionDetailsFactoryIntegrationTests() {
|
||||
super("otlp-compose.yaml", DockerImageNames.opentelemetry());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runCreatesConnectionDetails() {
|
||||
OtlpConnectionDetails connectionDetails = run(OtlpConnectionDetails.class);
|
||||
assertThat(connectionDetails.getUrl()).startsWith("http://").endsWith("/v1/metrics");
|
||||
}
|
||||
|
||||
@Test
|
||||
void runCreatesTracingConnectionDetails() {
|
||||
OtlpTracingConnectionDetails connectionDetails = run(OtlpTracingConnectionDetails.class);
|
||||
assertThat(connectionDetails.getEndpoint()).startsWith("http://").endsWith("/v1/traces");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
otlp:
|
||||
image: '{imageName}'
|
||||
ports:
|
||||
- '4318'
|
||||
Reference in New Issue
Block a user