Move code from docker-compose-all into relevant modules

This commit is contained in:
Andy Wilkinson
2025-06-06 16:37:05 +01:00
committed by Phillip Webb
parent 183a0fbdf5
commit d337c44c2f
28 changed files with 75 additions and 95 deletions

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2012-2024 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.tracing.docker.compose.otlp;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.tracing.autoconfigure.otlp.OtlpTracingConnectionDetails;
import org.springframework.boot.tracing.autoconfigure.otlp.Transport;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link OpenTelemetryTracingDockerComposeConnectionDetailsFactory}
* using {@link TestImage#GRAFANA_OTEL_LGTM}.
*
* @author Eddú Meléndez
*/
class GrafanaOpenTelemetryTracingDockerComposeConnectionDetailsFactoryIntegrationTests {
@DockerComposeTest(composeFile = "otlp-compose.yaml", image = TestImage.GRAFANA_OTEL_LGTM)
void runCreatesConnectionDetails(OtlpTracingConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUrl(Transport.HTTP)).startsWith("http://").endsWith("/v1/traces");
assertThat(connectionDetails.getUrl(Transport.GRPC)).startsWith("http://").endsWith("/v1/traces");
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2012-2024 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.tracing.docker.compose.otlp;
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.tracing.autoconfigure.otlp.OtlpTracingConnectionDetails;
import org.springframework.boot.tracing.autoconfigure.otlp.Transport;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link OpenTelemetryTracingDockerComposeConnectionDetailsFactory}
* using {@link TestImage#OPENTELEMETRY}.
*
* @author Eddú Meléndez
*/
class OpenTelemetryTracingDockerComposeConnectionDetailsFactoryIntegrationTests {
@DockerComposeTest(composeFile = "otlp-compose.yaml", image = TestImage.OPENTELEMETRY)
void runCreatesConnectionDetails(OtlpTracingConnectionDetails connectionDetails) {
assertThat(connectionDetails.getUrl(Transport.HTTP)).startsWith("http://").endsWith("/v1/traces");
assertThat(connectionDetails.getUrl(Transport.GRPC)).startsWith("http://").endsWith("/v1/traces");
}
}

View File

@@ -0,0 +1,6 @@
services:
otlp:
image: '{imageName}'
ports:
- '4317'
- '4318'

View File

@@ -0,0 +1,79 @@
/*
* Copyright 2012-2024 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.tracing.docker.compose.otlp;
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;
import org.springframework.boot.tracing.autoconfigure.otlp.OtlpTracingConnectionDetails;
import org.springframework.boot.tracing.autoconfigure.otlp.Transport;
/**
* {@link DockerComposeConnectionDetailsFactory} to create
* {@link OtlpTracingConnectionDetails} for an OTLP service.
*
* @author Eddú Meléndez
* @author Moritz Halbritter
*/
class OpenTelemetryTracingDockerComposeConnectionDetailsFactory
extends DockerComposeConnectionDetailsFactory<OtlpTracingConnectionDetails> {
private static final String[] OPENTELEMETRY_IMAGE_NAMES = { "otel/opentelemetry-collector-contrib",
"grafana/otel-lgtm" };
private static final int OTLP_GRPC_PORT = 4317;
private static final int OTLP_HTTP_PORT = 4318;
OpenTelemetryTracingDockerComposeConnectionDetailsFactory() {
super(OPENTELEMETRY_IMAGE_NAMES,
"org.springframework.boot.tracing.autoconfigure.otlp.OtlpTracingAutoConfiguration");
}
@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 grpcPort;
private final int httpPort;
private OpenTelemetryTracingDockerComposeConnectionDetails(RunningService source) {
super(source);
this.host = source.host();
this.grpcPort = source.ports().get(OTLP_GRPC_PORT);
this.httpPort = source.ports().get(OTLP_HTTP_PORT);
}
@Override
public String getUrl(Transport transport) {
int port = switch (transport) {
case HTTP -> this.httpPort;
case GRPC -> this.grpcPort;
};
return "http://%s:%d/v1/traces".formatted(this.host, port);
}
}
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2025 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 tracing service connections.
*/
package org.springframework.boot.tracing.docker.compose.otlp;

View File

@@ -1,5 +1,6 @@
# Connection Details Factories
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
org.springframework.boot.tracing.docker.compose.otlp.OpenTelemetryTracingDockerComposeConnectionDetailsFactory,\
org.springframework.boot.tracing.testcontainers.otlp.GrafanaOpenTelemetryTracingContainerConnectionDetailsFactory,\
org.springframework.boot.tracing.testcontainers.otlp.OpenTelemetryTracingContainerConnectionDetailsFactory
@@ -11,3 +12,4 @@ org.springframework.boot.tracing.autoconfigure.OpenTelemetryEventPublisherBeansA
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.tracing.autoconfigure.LogCorrelationEnvironmentPostProcessor