2424import java .net .URL ;
2525import java .util .Arrays ;
2626import org .hypertrace .agent .config .v1 .Config .AgentConfig ;
27+ import org .hypertrace .agent .config .v1 .Config .MetricReporterType ;
2728import org .hypertrace .agent .config .v1 .Config .PropagationFormat ;
2829import org .hypertrace .agent .config .v1 .Config .TraceReporterType ;
2930import org .junit .jupiter .api .Assertions ;
3031import org .junit .jupiter .api .Test ;
3132import org .junit .jupiter .api .io .TempDir ;
3233import org .junitpioneer .jupiter .ClearSystemProperty ;
34+ import org .junitpioneer .jupiter .SetEnvironmentVariable ;
3335
3436public class HypertraceConfigTest {
3537
@@ -41,10 +43,16 @@ public void defaultValues() throws IOException {
4143 Assertions .assertEquals ("unknown" , agentConfig .getServiceName ().getValue ());
4244 Assertions .assertEquals (
4345 TraceReporterType .OTLP , agentConfig .getReporting ().getTraceReporterType ());
46+ Assertions .assertEquals (
47+ MetricReporterType .METRIC_REPORTER_TYPE_OTLP ,
48+ agentConfig .getReporting ().getMetricReporterType ());
4449 Assertions .assertFalse (agentConfig .getReporting ().hasCertFile ());
4550 Assertions .assertEquals (
4651 HypertraceConfig .DEFAULT_REPORTING_ENDPOINT ,
4752 agentConfig .getReporting ().getEndpoint ().getValue ());
53+ Assertions .assertEquals (
54+ HypertraceConfig .DEFAULT_REPORTING_ENDPOINT ,
55+ agentConfig .getReporting ().getMetricEndpoint ().getValue ());
4856 Assertions .assertEquals (
4957 Arrays .asList (PropagationFormat .TRACECONTEXT ), agentConfig .getPropagationFormatsList ());
5058 Assertions .assertEquals (false , agentConfig .getReporting ().getSecure ().getValue ());
@@ -100,10 +108,15 @@ private void assertConfig(AgentConfig agentConfig) {
100108 Arrays .asList (PropagationFormat .B3 ), agentConfig .getPropagationFormatsList ());
101109 Assertions .assertEquals (
102110 TraceReporterType .OTLP , agentConfig .getReporting ().getTraceReporterType ());
111+ Assertions .assertEquals (
112+ MetricReporterType .METRIC_REPORTER_TYPE_OTLP ,
113+ agentConfig .getReporting ().getMetricReporterType ());
103114 Assertions .assertEquals (
104115 "/foo/bar/example.pem" , agentConfig .getReporting ().getCertFile ().getValue ());
105116 Assertions .assertEquals (
106117 "http://localhost:4317" , agentConfig .getReporting ().getEndpoint ().getValue ());
118+ Assertions .assertEquals (
119+ "http://localhost:4317" , agentConfig .getReporting ().getMetricEndpoint ().getValue ());
107120 Assertions .assertEquals (true , agentConfig .getReporting ().getSecure ().getValue ());
108121 Assertions .assertEquals (16 , agentConfig .getDataCapture ().getBodyMaxSizeBytes ().getValue ());
109122 Assertions .assertEquals (
@@ -134,4 +147,62 @@ public void configWithSystemProps() throws IOException {
134147 "http://nowhere.here" , agentConfig .getReporting ().getEndpoint ().getValue ());
135148 Assertions .assertEquals ("service" , agentConfig .getServiceName ().getValue ());
136149 }
150+
151+ @ Test
152+ @ SetEnvironmentVariable (key = "HT_REPORTING_ENDPOINT" , value = "http://oltp.hypertrace.org:4317" )
153+ public void complexConfig () throws IOException {
154+ // GIVEN a config file with a non-default reporting endpoint and an env-var with a different
155+ // non-default otlp reporting endpoint
156+ URL resource = getClass ().getClassLoader ().getResource ("config.yaml" );
157+ // WHEN we load the config
158+ AgentConfig agentConfig = HypertraceConfig .load (resource .getPath ());
159+ // VERIFY the trace and metric endpoints are the both the value of the env var
160+ String expectedEndpoint = "http://oltp.hypertrace.org:4317" ;
161+ Assertions .assertEquals (expectedEndpoint , agentConfig .getReporting ().getEndpoint ().getValue ());
162+ Assertions .assertEquals (
163+ expectedEndpoint , agentConfig .getReporting ().getMetricEndpoint ().getValue ());
164+ Assertions .assertEquals (
165+ TraceReporterType .OTLP , agentConfig .getReporting ().getTraceReporterType ());
166+ Assertions .assertEquals (
167+ MetricReporterType .METRIC_REPORTER_TYPE_OTLP ,
168+ agentConfig .getReporting ().getMetricReporterType ());
169+ }
170+
171+ @ Test
172+ public void zipkinExporter () throws IOException {
173+ // GIVEN a config file with a non-default zipkin reporting endpoint
174+ URL resource = getClass ().getClassLoader ().getResource ("zipkinConfig.yaml" );
175+ // WHEN we load the config
176+ AgentConfig agentConfig = HypertraceConfig .load (resource .getPath ());
177+ // VERIFY the trace reporting endpoint is the zipkin endpoint
178+ Assertions .assertEquals (
179+ "http://example.com:9411/api/v2/spans" ,
180+ agentConfig .getReporting ().getEndpoint ().getValue ());
181+ // VERIFY the trace reporting type is ZIPKIN
182+ Assertions .assertEquals (
183+ TraceReporterType .ZIPKIN , agentConfig .getReporting ().getTraceReporterType ());
184+ // VERIFY the metric reporting type is none
185+ Assertions .assertEquals (
186+ MetricReporterType .METRIC_REPORTER_TYPE_NONE ,
187+ agentConfig .getReporting ().getMetricReporterType ());
188+ }
189+
190+ @ Test
191+ public void noneTraceExporter () throws IOException {
192+ // GIVEN a config file with a non-default zipkin reporting endpoint
193+ URL resource = getClass ().getClassLoader ().getResource ("noneTraceReportingConfig.yaml" );
194+ // WHEN we load the config
195+ AgentConfig agentConfig = HypertraceConfig .load (resource .getPath ());
196+ // VERIFY the trace reporting type is NONE
197+ Assertions .assertEquals (
198+ TraceReporterType .NONE , agentConfig .getReporting ().getTraceReporterType ());
199+ // VERIFY the metric reporting type is OTLP
200+ Assertions .assertEquals (
201+ MetricReporterType .METRIC_REPORTER_TYPE_OTLP ,
202+ agentConfig .getReporting ().getMetricReporterType ());
203+ // VERIFY the metric reporting endpoint is default
204+ Assertions .assertEquals (
205+ HypertraceConfig .DEFAULT_REPORTING_ENDPOINT ,
206+ agentConfig .getReporting ().getMetricEndpoint ().getValue ());
207+ }
137208}
0 commit comments