Skip to content

Commit c9851a7

Browse files
authored
🐛 Fix incorrect metrics endpoint (#361)
* ✅ add unit test reproducing issue where metric reporting endpoint would only default to trace reporting endpoint if trace reporting endpoint was supplied via env var * 🐛 fix bug with metric reporting endpoint not falling back to reporting endpoint when supplied via YAML * ✅ add test test for non default metrics reporting endpoint * Revert "🐛 fix bug with metric reporting endpoint not falling back to reporting endpoint when supplied via YAML" This reverts commit 2c70107. * 🐛 fix bug more simply * 💡 fix comments in tests
1 parent 35a14b0 commit c9851a7

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfig.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ private static Reporting.Builder applyReportingDefaults(Reporting.Builder builde
140140
if (!builder.hasEndpoint()) {
141141
builder.setEndpoint(StringValue.newBuilder().setValue(DEFAULT_REPORTING_ENDPOINT).build());
142142
}
143+
if (builder.getTraceReporterType().equals(TraceReporterType.UNSPECIFIED)) {
144+
builder.setTraceReporterType(TraceReporterType.OTLP);
145+
}
143146
if (!builder.hasMetricEndpoint()) {
144147
if (TraceReporterType.OTLP.equals(builder.getTraceReporterType())) {
145148
// If trace reporter type is OTLP, use the same endpoint for metrics
@@ -149,9 +152,6 @@ private static Reporting.Builder applyReportingDefaults(Reporting.Builder builde
149152
StringValue.newBuilder().setValue(DEFAULT_REPORTING_ENDPOINT).build());
150153
}
151154
}
152-
if (builder.getTraceReporterType().equals(TraceReporterType.UNSPECIFIED)) {
153-
builder.setTraceReporterType(TraceReporterType.OTLP);
154-
}
155155
if (builder
156156
.getMetricReporterType()
157157
.equals(MetricReporterType.METRIC_REPORTER_TYPE_UNSPECIFIED)) {

otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfigTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,38 @@ public void noneTraceExporter() throws IOException {
205205
HypertraceConfig.DEFAULT_REPORTING_ENDPOINT,
206206
agentConfig.getReporting().getMetricEndpoint().getValue());
207207
}
208+
209+
@Test
210+
void nonDefaultReportingEndpoint() throws IOException {
211+
// GIVEN a config file with a non-default reporting endpoint
212+
URL resource = getClass().getClassLoader().getResource("nonDefaultReportingEndpoint.yaml");
213+
// WHEN we load the config
214+
AgentConfig agentConfig = HypertraceConfig.load(resource.getPath());
215+
// VERIFY the trace reporting type is OTLP
216+
Assertions.assertEquals(
217+
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
218+
String expectedReportingEndpoint = "http://example.com:4317";
219+
// VERIFY the trace reporting and metric reporting endpoints are both the specified value
220+
Assertions.assertEquals(
221+
expectedReportingEndpoint, agentConfig.getReporting().getEndpoint().getValue());
222+
Assertions.assertEquals(
223+
expectedReportingEndpoint, agentConfig.getReporting().getMetricEndpoint().getValue());
224+
}
225+
226+
@Test
227+
void nonDefaultMetricsEndpoint() throws IOException {
228+
// GIVEN a config file with a non-default metric reporting endpoint
229+
URL resource = getClass().getClassLoader().getResource("nonDefaultMetricsEndpoint.yaml");
230+
// WHEN we load the config
231+
AgentConfig agentConfig = HypertraceConfig.load(resource.getPath());
232+
// VERIFY the trace reporting type is OTLP
233+
Assertions.assertEquals(
234+
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
235+
// VERIFY the trace reporting endpoint is still the default value
236+
Assertions.assertEquals(
237+
"http://localhost:4317", agentConfig.getReporting().getEndpoint().getValue());
238+
// VERIFY the metric reporting endpoint is the specified value
239+
Assertions.assertEquals(
240+
"http://example.com:4317", agentConfig.getReporting().getMetricEndpoint().getValue());
241+
}
208242
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_name: service
2+
reporting:
3+
metric_endpoint: http://example.com:4317
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_name: service
2+
reporting:
3+
endpoint: http://example.com:4317

0 commit comments

Comments
 (0)