Skip to content

Commit e48bfbd

Browse files
committed
Multiple endpoints reported in effective config
1 parent 72c3a22 commit e48bfbd

6 files changed

Lines changed: 124 additions & 53 deletions

File tree

‎opamp/src/main/java/com/splunk/opentelemetry/opamp/DeclarativeEffectiveConfigFileFactory.java‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanExporterModel;
3232
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanProcessorModel;
3333
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.TracerProviderModel;
34+
import java.util.ArrayList;
35+
import java.util.List;
3436
import java.util.Optional;
3537

3638
class DeclarativeEffectiveConfigFileFactory implements EffectiveConfigFactory {
@@ -66,50 +68,53 @@ void addOtelVars(
6668
EffectiveConfigBuilder builder, OpenTelemetryConfigurationModel configurationModel) {
6769
builder
6870
.add(
69-
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
70-
getTracesEndpoint(configurationModel.getTracerProvider()))
71+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS,
72+
getTracesEndpoints(configurationModel.getTracerProvider()))
7173
.add(
72-
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
73-
getMetricsEndpoint(configurationModel.getMeterProvider()))
74+
OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS,
75+
getMetricsEndpoints(configurationModel.getMeterProvider()))
7476
.add(
75-
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
76-
getLogsEndpoint(configurationModel.getLoggerProvider()));
77+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS,
78+
getLogsEndpoints(configurationModel.getLoggerProvider()));
7779
}
7880

79-
private String getTracesEndpoint(TracerProviderModel tracerProvider) {
81+
private List<String> getTracesEndpoints(TracerProviderModel tracerProvider) {
82+
List<String> endpoints = new ArrayList<>();
8083
if (tracerProvider != null) {
8184
for (SpanProcessorModel spanProcessor : tracerProvider.getProcessors()) {
8285
String endpoint = getEndpoint(getSpanExporter(spanProcessor));
8386
if (endpoint != null) {
84-
return endpoint;
87+
endpoints.add(endpoint);
8588
}
8689
}
8790
}
88-
return "";
91+
return endpoints;
8992
}
9093

91-
private String getMetricsEndpoint(MeterProviderModel meterProvider) {
94+
private List<String> getMetricsEndpoints(MeterProviderModel meterProvider) {
95+
List<String> endpoints = new ArrayList<>();
9296
if (meterProvider != null) {
9397
for (MetricReaderModel metricReader : meterProvider.getReaders()) {
9498
String endpoint = getEndpoint(getMetricExporter(metricReader));
9599
if (endpoint != null) {
96-
return endpoint;
100+
endpoints.add(endpoint);
97101
}
98102
}
99103
}
100-
return "";
104+
return endpoints;
101105
}
102106

103-
private String getLogsEndpoint(LoggerProviderModel loggerProvider) {
107+
private List<String> getLogsEndpoints(LoggerProviderModel loggerProvider) {
108+
List<String> endpoints = new ArrayList<>();
104109
if (loggerProvider != null) {
105110
for (LogRecordProcessorModel processor : loggerProvider.getProcessors()) {
106111
String endpoint = getEndpoint(getLogRecordExporter(processor));
107112
if (endpoint != null) {
108-
return endpoint;
113+
endpoints.add(endpoint);
109114
}
110115
}
111116
}
112-
return "";
117+
return endpoints;
113118
}
114119

115120
private static SpanExporterModel getSpanExporter(SpanProcessorModel processor) {

‎opamp/src/main/java/com/splunk/opentelemetry/opamp/EffectiveConfigBuilder.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,32 @@
1717
package com.splunk.opentelemetry.opamp;
1818

1919
import java.time.Duration;
20+
import java.util.List;
2021

2122
class EffectiveConfigBuilder {
2223
private final StringBuilder stringBuilder = new StringBuilder();
2324

25+
EffectiveConfigBuilder add(String propertyName, String value) {
26+
stringBuilder.append(propertyName).append("=\"").append(value).append("\"\n");
27+
return this;
28+
}
29+
2430
EffectiveConfigBuilder add(String propertyName, Object value) {
2531
stringBuilder.append(propertyName).append('=').append(value).append('\n');
2632
return this;
2733
}
2834

35+
EffectiveConfigBuilder add(String propertyName, List<String> valueList) {
36+
stringBuilder.append(propertyName).append('=');
37+
if (!valueList.isEmpty()) {
38+
stringBuilder.append('"');
39+
stringBuilder.append(String.join("\", \"", valueList));
40+
stringBuilder.append('"');
41+
}
42+
stringBuilder.append('\n');
43+
return this;
44+
}
45+
2946
EffectiveConfigBuilder add(String propertyName, Duration value) {
3047
return add(propertyName, value.toMillis() + "ms");
3148
}

‎opamp/src/main/java/com/splunk/opentelemetry/opamp/EffectiveConfigFactory.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ interface EffectiveConfigFactory {
2929
String SPLUNK_PROFILER_CALL_STACK_INTERVAL = "SPLUNK_PROFILER_CALL_STACK_INTERVAL";
3030
String SPLUNK_SNAPSHOT_PROFILER_ENABLED = "SPLUNK_SNAPSHOT_PROFILER_ENABLED";
3131
String SPLUNK_SNAPSHOT_PROFILER_SAMPLING_INTERVAL = "SPLUNK_SNAPSHOT_PROFILER_SAMPLING_INTERVAL";
32-
String OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT";
33-
String OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT";
34-
String OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT";
32+
String OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS = "OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS";
33+
String OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS = "OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS";
34+
String OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS = "OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS";
3535

3636
default AgentConfigFile createFile() {
3737
ByteString content = new ByteString(buildFileContent().getBytes(UTF_8));

‎opamp/src/main/java/com/splunk/opentelemetry/opamp/EnvVarsEffectiveConfigFileFactory.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ private EffectiveConfigBuilder addSplunkEnvVars(EffectiveConfigBuilder builder)
5151

5252
private EffectiveConfigBuilder addOtelEnvVars(EffectiveConfigBuilder builder) {
5353
return builder
54-
.add(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, getSignalEndpoint(config, OTLP_SIGNAL_TRACES))
55-
.add(OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, getSignalEndpoint(config, OTLP_SIGNAL_METRICS))
56-
.add(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, getSignalEndpoint(config, OTLP_SIGNAL_LOGS));
54+
.add(OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS, getSignalEndpoint(config, OTLP_SIGNAL_TRACES))
55+
.add(OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS, getSignalEndpoint(config, OTLP_SIGNAL_METRICS))
56+
.add(OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS, getSignalEndpoint(config, OTLP_SIGNAL_LOGS));
5757
}
5858

5959
private static String getSignalEndpoint(ConfigProperties config, String signal) {

‎opamp/src/test/java/com/splunk/opentelemetry/opamp/DeclarativeEffectiveConfigFileFactoryTest.java‎

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ void buildFileContent_reportsSignalEndpoints(@TempDir Path tempDir) throws Excep
108108
assertProperties(
109109
properties,
110110
Map.of(
111-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://traces.example.com",
112-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://metrics.example.com",
113-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "https://logs.example.com"));
111+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"https://traces.example.com\"",
112+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"https://metrics.example.com\"",
113+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"https://logs.example.com\""));
114114
}
115115

116116
@Test
@@ -124,9 +124,9 @@ void addOtelVars_reportsMissingEndpointAsEmptyStrings() throws Exception {
124124
assertProperties(
125125
properties,
126126
Map.of(
127-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "",
128-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "",
129-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", ""));
127+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "",
128+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "",
129+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", ""));
130130
}
131131

132132
@Test
@@ -159,9 +159,9 @@ void addOtelVars_usesDefaultHttpEndpointsWhenEndpointsAreOmitted() throws Except
159159
assertProperties(
160160
properties,
161161
Map.of(
162-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "http://localhost:4318/v1/traces",
163-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "http://localhost:4318/v1/metrics",
164-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "http://localhost:4318/v1/logs"));
162+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"http://localhost:4318/v1/traces\"",
163+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"http://localhost:4318/v1/metrics\"",
164+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"http://localhost:4318/v1/logs\""));
165165
}
166166

167167
@Test
@@ -194,9 +194,58 @@ void addOtelVars_usesDefaultGrpcEndpointsWhenEndpointsAreOmitted() throws Except
194194
assertProperties(
195195
properties,
196196
Map.of(
197-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "http://localhost:4317",
198-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "http://localhost:4317",
199-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "http://localhost:4317"));
197+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"http://localhost:4317\"",
198+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"http://localhost:4317\"",
199+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"http://localhost:4317\""));
200+
}
201+
202+
@Test
203+
void addOtelVars_whenMultipleEndpointsDefined() throws Exception {
204+
OpenTelemetryConfigurationModel model =
205+
parseModel(
206+
"""
207+
file_format: 1.0
208+
tracer_provider:
209+
processors:
210+
- batch:
211+
exporter:
212+
otlp_http:
213+
endpoint: https://traces.example.com
214+
- simple:
215+
exporter:
216+
otlp_grpc:
217+
meter_provider:
218+
readers:
219+
- periodic:
220+
exporter:
221+
otlp_grpc:
222+
endpoint: https://metrics.example.com
223+
- periodic:
224+
exporter:
225+
otlp_http:
226+
endpoint: https://acme.com/
227+
logger_provider:
228+
processors:
229+
- simple:
230+
exporter:
231+
otlp_http:
232+
endpoint: https://logs.example.com
233+
- batch:
234+
exporter:
235+
otlp_grpc:
236+
endpoint: https://acme.com
237+
""");
238+
239+
EffectiveConfigBuilder builder = new EffectiveConfigBuilder();
240+
new DeclarativeEffectiveConfigFileFactory().addOtelVars(builder, model);
241+
242+
Properties properties = loadProperties(builder.build());
243+
assertProperties(
244+
properties,
245+
Map.of(
246+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"https://traces.example.com\", \"http://localhost:4317\"",
247+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"https://metrics.example.com\", \"https://acme.com/\"",
248+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"https://logs.example.com\", \"https://acme.com\""));
200249
}
201250

202251
private static class FactoryRunner {
@@ -234,6 +283,6 @@ private static Properties loadProperties(String content) throws Exception {
234283
private static void assertProperties(Properties fileContent, Map<String, String> expectedValues) {
235284
expectedValues.forEach(
236285
(propertyName, expectedValue) ->
237-
assertThat(fileContent.getProperty(propertyName)).isEqualTo(expectedValue));
286+
assertThat(fileContent.getProperty(propertyName)).isNotNull().isEqualTo(expectedValue));
238287
}
239288
}

‎opamp/src/test/java/com/splunk/opentelemetry/opamp/EnvVarsEffectiveConfigFileFactoryTest.java‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ void buildFileContent_reportsConfiguredValues() throws IOException {
4949
"SPLUNK_PROFILER_ENABLED", "true",
5050
"SPLUNK_PROFILER_MEMORY_ENABLED", "true",
5151
"SPLUNK_SNAPSHOT_PROFILER_ENABLED", "true",
52-
"SPLUNK_SNAPSHOT_PROFILER_SAMPLING_INTERVAL", "26ms",
53-
"SPLUNK_PROFILER_CALL_STACK_INTERVAL", "1235ms",
54-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://traces.example.com",
55-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://metrics.example.com",
56-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "https://logs.example.com"));
52+
"SPLUNK_SNAPSHOT_PROFILER_SAMPLING_INTERVAL", "\"26ms\"",
53+
"SPLUNK_PROFILER_CALL_STACK_INTERVAL", "\"1235ms\"",
54+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"https://traces.example.com\"",
55+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"https://metrics.example.com\"",
56+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"https://logs.example.com\""));
5757
assertThat(fileContent.size()).isEqualTo(8);
5858
}
5959

@@ -67,11 +67,11 @@ void buildFileContent_reportsDefaultValuesWhenNotConfigured() throws IOException
6767
"SPLUNK_PROFILER_ENABLED", "false",
6868
"SPLUNK_PROFILER_MEMORY_ENABLED", "false",
6969
"SPLUNK_SNAPSHOT_PROFILER_ENABLED", "false",
70-
"SPLUNK_SNAPSHOT_PROFILER_SAMPLING_INTERVAL", "10ms",
71-
"SPLUNK_PROFILER_CALL_STACK_INTERVAL", "10000ms",
72-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "http://localhost:4318/v1/traces",
73-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "http://localhost:4318/v1/metrics",
74-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "http://localhost:4318/v1/logs"));
70+
"SPLUNK_SNAPSHOT_PROFILER_SAMPLING_INTERVAL", "\"10ms\"",
71+
"SPLUNK_PROFILER_CALL_STACK_INTERVAL", "\"10000ms\"",
72+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"http://localhost:4318/v1/traces\"",
73+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"http://localhost:4318/v1/metrics\"",
74+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"http://localhost:4318/v1/logs\""));
7575
assertThat(fileContent.size()).isEqualTo(8);
7676
}
7777

@@ -83,9 +83,9 @@ void buildFileContent_appendsSignalPathsToBaseHttpProtobufEndpoint() throws IOEx
8383
assertProperties(
8484
fileContent,
8585
Map.of(
86-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://collector:4318/v1/traces",
87-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://collector:4318/v1/metrics",
88-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "https://collector:4318/v1/logs"));
86+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"https://collector:4318/v1/traces\"",
87+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"https://collector:4318/v1/metrics\"",
88+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"https://collector:4318/v1/logs\""));
8989
}
9090

9191
@Test
@@ -99,9 +99,9 @@ void buildFileContent_usesBaseGrpcEndpointForAllSignals() throws IOException {
9999
assertProperties(
100100
fileContent,
101101
Map.of(
102-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://collector:4317",
103-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://collector:4317",
104-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "https://collector:4317"));
102+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"https://collector:4317\"",
103+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"https://collector:4317\"",
104+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"https://collector:4317\""));
105105
}
106106

107107
@Test
@@ -117,9 +117,9 @@ void buildFileContent_usesSignalSpecificProtocolWhenResolvingEndpoints() throws
117117
assertProperties(
118118
fileContent,
119119
Map.of(
120-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://collector:4317",
121-
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://collector:4317",
122-
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "https://collector:4317"));
120+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTS", "\"https://collector:4317\"",
121+
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINTS", "\"https://collector:4317\"",
122+
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINTS", "\"https://collector:4317\""));
123123
}
124124

125125
private static String createFileContent(Map<String, String> configMap) {

0 commit comments

Comments
 (0)