16
16
import io .pivotal .cfenv .core .CfService ;
17
17
18
18
import java .time .Duration ;
19
+ import java .util .Locale ;
19
20
import java .util .function .Function ;
20
21
import java .util .logging .Logger ;
21
22
@@ -46,20 +47,39 @@ private static Duration getTimeOut(ConfigProperties config) {
46
47
return timeout != null ? timeout : config .getDuration ("otel.exporter.dynatrace.timeout" );
47
48
}
48
49
50
+ private static AggregationTemporalitySelector getAggregationTemporalitySelector (ConfigProperties config ) {
51
+ String temporalityStr = config .getString ("otel.exporter.dynatrace.metrics.temporality.preference" );
52
+ if (temporalityStr == null ) {
53
+ return AggregationTemporalitySelector .deltaPreferred ();
54
+ }
55
+ AggregationTemporalitySelector temporalitySelector ;
56
+ switch (temporalityStr .toLowerCase (Locale .ROOT )) {
57
+ case "cumulative" :
58
+ return AggregationTemporalitySelector .alwaysCumulative ();
59
+ case "delta" :
60
+ return AggregationTemporalitySelector .deltaPreferred ();
61
+ case "lowmemory" :
62
+ return AggregationTemporalitySelector .lowMemory ();
63
+ default :
64
+ throw new ConfigurationException ("Unrecognized aggregation temporality: " + temporalityStr );
65
+ }
66
+ }
67
+
49
68
private static DefaultAggregationSelector getDefaultAggregationSelector (ConfigProperties config ) {
50
69
String defaultHistogramAggregation =
51
70
config .getString ("otel.exporter.dynatrace.metrics.default.histogram.aggregation" );
52
71
if (defaultHistogramAggregation == null ) {
53
- return DefaultAggregationSelector .getDefault ().with (InstrumentType .HISTOGRAM , Aggregation .defaultAggregation ());
72
+ return DefaultAggregationSelector .getDefault ()
73
+ .with (InstrumentType .HISTOGRAM , Aggregation .defaultAggregation ());
54
74
}
55
75
if (AggregationUtil .aggregationName (Aggregation .base2ExponentialBucketHistogram ())
56
- .equalsIgnoreCase (defaultHistogramAggregation )) {
57
- return
58
- DefaultAggregationSelector .getDefault ()
59
- .with (InstrumentType .HISTOGRAM , Aggregation .base2ExponentialBucketHistogram ());
76
+ .equalsIgnoreCase (defaultHistogramAggregation )) {
77
+ return DefaultAggregationSelector .getDefault ().with (InstrumentType .HISTOGRAM ,
78
+ Aggregation .base2ExponentialBucketHistogram ());
60
79
} else if (AggregationUtil .aggregationName (explicitBucketHistogram ())
61
- .equalsIgnoreCase (defaultHistogramAggregation )) {
62
- return DefaultAggregationSelector .getDefault ().with (InstrumentType .HISTOGRAM , Aggregation .explicitBucketHistogram ());
80
+ .equalsIgnoreCase (defaultHistogramAggregation )) {
81
+ return DefaultAggregationSelector .getDefault ()
82
+ .with (InstrumentType .HISTOGRAM , Aggregation .explicitBucketHistogram ());
63
83
} else {
64
84
throw new ConfigurationException (
65
85
"Unrecognized default histogram aggregation: " + defaultHistogramAggregation );
@@ -83,16 +103,19 @@ public MetricExporter createExporter(ConfigProperties config) {
83
103
return NoopMetricExporter .getInstance ();
84
104
}
85
105
86
- LOG .info ("Creating metrics exporter for service binding " + cfService .getName () + " (" + cfService .getLabel () + ")" );
106
+ LOG .info (
107
+ "Creating metrics exporter for service binding " + cfService .getName () + " (" + cfService .getLabel () + ")" );
87
108
88
109
String apiUrl = cfService .getCredentials ().getString (CRED_DYNATRACE_APIURL );
89
110
if (isBlank (apiUrl )) {
90
- LOG .warning ("Credential \" " + CRED_DYNATRACE_APIURL + "\" not found. Skipping dynatrace exporter configuration" );
111
+ LOG .warning (
112
+ "Credential \" " + CRED_DYNATRACE_APIURL + "\" not found. Skipping dynatrace exporter configuration" );
91
113
return NoopMetricExporter .getInstance ();
92
114
}
93
115
String tokenName = config .getString ("otel.javaagent.extension.sap.cf.binding.dynatrace.metrics.token-name" );
94
116
if (isBlank (tokenName )) {
95
- LOG .warning ("Configuration \" otel.javaagent.extension.sap.cf.binding.dynatrace.metrics.token-name\" not found. Skipping dynatrace exporter configuration" );
117
+ LOG .warning (
118
+ "Configuration \" otel.javaagent.extension.sap.cf.binding.dynatrace.metrics.token-name\" not found. Skipping dynatrace exporter configuration" );
96
119
return NoopMetricExporter .getInstance ();
97
120
}
98
121
String apiToken = cfService .getCredentials ().getString (tokenName );
@@ -102,19 +125,18 @@ public MetricExporter createExporter(ConfigProperties config) {
102
125
}
103
126
104
127
OtlpHttpMetricExporterBuilder builder = OtlpHttpMetricExporter .builder ();
105
- builder .setEndpoint (apiUrl + DT_APIURL_METRICS_SUFFIX )
106
- .setCompression (getCompression (config ))
107
- .addHeader ("Authorization" , "Api-Token " + apiToken )
108
- .setRetryPolicy (RetryPolicy .getDefault ())
109
- .setAggregationTemporalitySelector (AggregationTemporalitySelector .alwaysCumulative ())
110
- .setDefaultAggregationSelector (getDefaultAggregationSelector (config ));
128
+ builder .setEndpoint (apiUrl + DT_APIURL_METRICS_SUFFIX ).setCompression (getCompression (config ))
129
+ .addHeader ("Authorization" , "Api-Token " + apiToken ).setRetryPolicy (RetryPolicy .getDefault ())
130
+ .setAggregationTemporalitySelector (getAggregationTemporalitySelector (config ))
131
+ .setDefaultAggregationSelector (getDefaultAggregationSelector (config ));
111
132
112
133
Duration timeOut = getTimeOut (config );
113
134
if (timeOut != null ) {
114
135
builder .setTimeout (timeOut );
115
136
}
116
137
117
- LOG .info ("Created metrics exporter for service binding " + cfService .getName () + " (" + cfService .getLabel () + ")" );
138
+ LOG .info (
139
+ "Created metrics exporter for service binding " + cfService .getName () + " (" + cfService .getLabel () + ")" );
118
140
return builder .build ();
119
141
}
120
142
0 commit comments