16
16
17
17
package com .splunk .opentelemetry ;
18
18
19
+ import static com .splunk .opentelemetry .SplunkConfiguration .METRICS_ENABLED_PROPERTY ;
20
+ import static com .splunk .opentelemetry .SplunkConfiguration .METRICS_IMPLEMENTATION ;
19
21
import static com .splunk .opentelemetry .SplunkConfiguration .OTEL_EXPORTER_JAEGER_ENDPOINT ;
22
+ import static com .splunk .opentelemetry .SplunkConfiguration .PROFILER_MEMORY_ENABLED_PROPERTY ;
20
23
import static com .splunk .opentelemetry .SplunkConfiguration .SPLUNK_REALM_NONE ;
21
24
import static org .junit .jupiter .api .Assertions .assertEquals ;
25
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
26
+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
22
27
import static org .junit .jupiter .api .Assertions .assertNull ;
28
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
23
29
24
30
import io .opentelemetry .instrumentation .api .config .Config ;
31
+ import io .opentelemetry .instrumentation .api .config .ConfigBuilder ;
32
+ import java .util .function .Consumer ;
25
33
import org .junit .jupiter .api .Test ;
26
34
27
35
class SplunkConfigurationTest {
28
- private static final String TEST_REALM = "test0" ;
36
+
29
37
private static final String OTLP_ENDPOINT = "otel.exporter.otlp.endpoint" ;
30
38
31
39
@ Test
32
- void usesRealmIngestUrlsIfRealmDefined () {
33
- assertRealmDefaults (configuration (TEST_REALM ));
40
+ void usesLocalIngestIfNoRealmIsConfigured () {
41
+ Config config = configuration ();
42
+
43
+ assertEquals ("http://localhost:9080/v1/trace" , config .getString (OTEL_EXPORTER_JAEGER_ENDPOINT ));
44
+ assertNull (config .getString (OTLP_ENDPOINT ));
34
45
}
35
46
36
47
@ Test
37
- void usesLocalIngestIfRealmIsNullOrNone () {
38
- assertLocalDefaults (configuration (null ));
39
- assertLocalDefaults (configuration (SPLUNK_REALM_NONE ));
48
+ void usesLocalIngestIfRealmIsNone () {
49
+ Config config =
50
+ configuration (
51
+ builder ->
52
+ builder .addProperty (SplunkConfiguration .SPLUNK_REALM_PROPERTY , SPLUNK_REALM_NONE ));
53
+
54
+ assertEquals ("http://localhost:9080/v1/trace" , config .getString (OTEL_EXPORTER_JAEGER_ENDPOINT ));
55
+ assertNull (config .getString (OTLP_ENDPOINT ));
40
56
}
41
57
42
58
@ Test
43
59
void realmIsNotHardcoded () {
44
- var config = configuration ("test1" );
60
+ var config =
61
+ configuration (
62
+ builder -> builder .addProperty (SplunkConfiguration .SPLUNK_REALM_PROPERTY , "test1" ));
63
+
45
64
assertEquals (
46
65
"https://ingest.test1.signalfx.com/v2/trace" ,
47
66
config .getString (OTEL_EXPORTER_JAEGER_ENDPOINT ));
@@ -50,52 +69,101 @@ void realmIsNotHardcoded() {
50
69
51
70
@ Test
52
71
void shouldSetOtlpHeader () {
53
- SplunkConfiguration splunkConfiguration = new SplunkConfiguration ();
54
72
Config config =
55
- Config .builder ()
56
- .addProperties (splunkConfiguration .defaultProperties ())
57
- .addProperty (SplunkConfiguration .SPLUNK_ACCESS_TOKEN , "token" )
58
- .build ();
59
-
60
- config = splunkConfiguration .customize (config );
73
+ configuration (
74
+ builder -> builder .addProperty (SplunkConfiguration .SPLUNK_ACCESS_TOKEN , "token" ));
61
75
62
76
assertEquals ("X-SF-TOKEN=token" , config .getString ("otel.exporter.otlp.headers" ));
63
77
}
64
78
65
79
@ Test
66
80
void shouldAppendToOtlpHeaders () {
67
- SplunkConfiguration splunkConfiguration = new SplunkConfiguration ();
68
81
Config config =
69
- Config .builder ()
70
- .addProperties (splunkConfiguration .defaultProperties ())
71
- .addProperty (SplunkConfiguration .SPLUNK_ACCESS_TOKEN , "token" )
72
- .addProperty ("otel.exporter.otlp.headers" , "key=value" )
73
- .build ();
74
-
75
- config = splunkConfiguration .customize (config );
82
+ configuration (
83
+ builder ->
84
+ builder
85
+ .addProperty (SplunkConfiguration .SPLUNK_ACCESS_TOKEN , "token" )
86
+ .addProperty ("otel.exporter.otlp.headers" , "key=value" ));
76
87
77
88
assertEquals ("key=value,X-SF-TOKEN=token" , config .getString ("otel.exporter.otlp.headers" ));
78
89
}
79
90
80
- private static void assertLocalDefaults (Config config ) {
81
- assertEquals ("http://localhost:9080/v1/trace" , config .getString (OTEL_EXPORTER_JAEGER_ENDPOINT ));
82
- assertNull (config .getString (OTLP_ENDPOINT ));
91
+ @ Test
92
+ void memoryProfilerEnablesMetrics () {
93
+ Config config =
94
+ configuration (builder -> builder .addProperty (PROFILER_MEMORY_ENABLED_PROPERTY , "true" ));
95
+
96
+ assertTrue (config .getBoolean (METRICS_ENABLED_PROPERTY , false ));
83
97
}
84
98
85
- private static void assertRealmDefaults (Config config ) {
86
- assertEquals (
87
- "https://ingest.test0.signalfx.com/v2/trace" ,
88
- config .getString (OTEL_EXPORTER_JAEGER_ENDPOINT ));
89
- assertEquals ("https://ingest.test0.signalfx.com" , config .getString (OTLP_ENDPOINT ));
99
+ @ Test
100
+ void shouldDisableMetricsByDefault () {
101
+ Config config = configuration ();
102
+
103
+ assertFalse (config .getBoolean (METRICS_ENABLED_PROPERTY , false ));
104
+ assertEquals ("none" , config .getString ("otel.metrics.exporter" ));
105
+
106
+ verifyThatOtelMetricsInstrumentationsAreDisabled (config );
90
107
}
91
108
92
- private static Config configuration (String realm ) {
93
- SplunkConfiguration splunkConfiguration = new SplunkConfiguration ();
109
+ @ Test
110
+ void shouldChooseMicrometerAsTheDefaultMetricsImplementation () {
111
+ Config config = configuration (builder -> builder .addProperty (METRICS_ENABLED_PROPERTY , "true" ));
112
+
113
+ assertTrue (config .getBoolean (METRICS_ENABLED_PROPERTY , false ));
114
+ assertEquals ("micrometer" , config .getString (METRICS_IMPLEMENTATION ));
115
+ assertEquals ("none" , config .getString ("otel.metrics.exporter" ));
116
+
117
+ verifyThatOtelMetricsInstrumentationsAreDisabled (config );
118
+ }
119
+
120
+ @ Test
121
+ void shouldDisableMicrometerMetricsIfOtelImplementationIsChosen () {
94
122
Config config =
95
- Config .builder ()
96
- .addProperties (splunkConfiguration .defaultProperties ())
97
- .addProperty (SplunkConfiguration .SPLUNK_REALM_PROPERTY , realm )
98
- .build ();
99
- return splunkConfiguration .customize (config );
123
+ configuration (
124
+ builder ->
125
+ builder
126
+ .addProperty (METRICS_ENABLED_PROPERTY , "true" )
127
+ .addProperty (METRICS_IMPLEMENTATION , "opentelemetry" ));
128
+
129
+ assertTrue (config .getBoolean (METRICS_ENABLED_PROPERTY , false ));
130
+ assertEquals ("opentelemetry" , config .getString (METRICS_IMPLEMENTATION ));
131
+ assertNotEquals ("none" , config .getString ("otel.metrics.exporter" ));
132
+
133
+ verifyThatMicrometerInstrumentationsAreDisabled (config );
134
+ }
135
+
136
+ private static Config configuration () {
137
+ return configuration (b -> {});
138
+ }
139
+
140
+ private static Config configuration (Consumer <ConfigBuilder > customizer ) {
141
+ SplunkConfiguration splunkConfiguration = new SplunkConfiguration ();
142
+ ConfigBuilder configBuilder =
143
+ Config .builder ().addProperties (splunkConfiguration .defaultProperties ());
144
+ customizer .accept (configBuilder );
145
+ return splunkConfiguration .customize (configBuilder .build ());
146
+ }
147
+
148
+ private static void verifyThatOtelMetricsInstrumentationsAreDisabled (Config config ) {
149
+ assertFalse (config .getBoolean ("otel.instrumentation.apache-dbcp.enabled" , false ));
150
+ assertFalse (config .getBoolean ("otel.instrumentation.c3p0.enabled" , false ));
151
+ assertFalse (config .getBoolean ("otel.instrumentation.hikaricp.enabled" , false ));
152
+ assertFalse (config .getBoolean ("otel.instrumentation.micrometer.enabled" , false ));
153
+ assertFalse (config .getBoolean ("otel.instrumentation.oracle-ucp.enabled" , false ));
154
+ assertFalse (config .getBoolean ("otel.instrumentation.oshi.enabled" , false ));
155
+ assertFalse (config .getBoolean ("otel.instrumentation.runtime-metrics.enabled" , false ));
156
+ assertFalse (config .getBoolean ("otel.instrumentation.tomcat-jdbc.enabled" , false ));
157
+ assertFalse (config .getBoolean ("otel.instrumentation.vibur-dbcp.enabled" , false ));
158
+ }
159
+
160
+ private static void verifyThatMicrometerInstrumentationsAreDisabled (Config config ) {
161
+ assertFalse (config .getBoolean ("otel.instrumentation.c3p0-splunk.enabled" , false ));
162
+ assertFalse (config .getBoolean ("otel.instrumentation.commons-dbcp2-splunk.enabled" , false ));
163
+ assertFalse (config .getBoolean ("otel.instrumentation.hikari-splunk.enabled" , false ));
164
+ assertFalse (config .getBoolean ("otel.instrumentation.micrometer-splunk.enabled" , false ));
165
+ assertFalse (config .getBoolean ("otel.instrumentation.oracle-ucp-splunk.enabled" , false ));
166
+ assertFalse (config .getBoolean ("otel.instrumentation.tomcat-jdbc-splunk.enabled" , false ));
167
+ assertFalse (config .getBoolean ("otel.instrumentation.vibur-dbcp-splunk.enabled" , false ));
100
168
}
101
169
}
0 commit comments