Skip to content

Commit

Permalink
Add docker compose connection details
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed Sep 13, 2023
1 parent 3821162 commit 2892e3b
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 0 deletions.
@@ -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;
Expand Up @@ -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,\
Expand Down
@@ -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'

0 comments on commit 2892e3b

Please sign in to comment.