@@ -18,7 +18,6 @@ package kamon.influxdb
18
18
19
19
import java .time .Instant
20
20
import java .util .concurrent .TimeUnit
21
-
22
21
import com .typesafe .config .Config
23
22
import kamon .influxdb .InfluxDBReporter .Settings
24
23
import kamon .metric .{MetricSnapshot , PeriodSnapshot }
@@ -27,8 +26,10 @@ import kamon.module.{MetricReporter, ModuleFactory}
27
26
import kamon .tag .{Tag , TagSet }
28
27
import kamon .util .{EnvironmentTags , Filter }
29
28
import okhttp3 .{Credentials , Interceptor , MediaType , OkHttpClient , Request , RequestBody , Response }
29
+ import okio .ByteString
30
30
import org .slf4j .LoggerFactory
31
31
32
+ import java .nio .charset .StandardCharsets .ISO_8859_1
32
33
import scala .util .Try
33
34
34
35
@@ -226,19 +227,25 @@ object InfluxDBReporter {
226
227
227
228
def readSettings (config : Config ): Settings = {
228
229
import scala .collection .JavaConverters ._
229
- val root = config.getConfig(" kamon.influxdb" )
230
- val host = root.getString(" hostname" )
231
- val credentials = if (root.hasPath(" authentication" )) {
232
- Some (Credentials .basic(root.getString(" authentication.user" ), root.getString(" authentication.password" )))
230
+ val influxDBConfig = config.getConfig(" kamon.influxdb" )
231
+ val host = influxDBConfig.getString(" hostname" )
232
+ val credentials = if (influxDBConfig.hasPath(" authentication" )) {
233
+ if (influxDBConfig.hasPath(" token" ))
234
+ Some (" Token " + ByteString .encodeString(influxDBConfig.getString(" token" ), ISO_8859_1 ))
235
+ else
236
+ Some (Credentials .basic(
237
+ influxDBConfig.getString(" authentication.user" ),
238
+ influxDBConfig.getString(" authentication.password" )
239
+ ))
233
240
} else {
234
241
None
235
242
}
236
- val port = root .getInt(" port" )
237
- val database = root .getString(" database" )
238
- val protocol = root .getString(" protocol" ).toLowerCase
239
- val additionalTags = EnvironmentTags .from(Kamon .environment, root .getConfig(" environment-tags" ))
243
+ val port = influxDBConfig .getInt(" port" )
244
+ val database = influxDBConfig .getString(" database" )
245
+ val protocol = influxDBConfig .getString(" protocol" ).toLowerCase
246
+ val additionalTags = EnvironmentTags .from(Kamon .environment, influxDBConfig .getConfig(" environment-tags" ))
240
247
241
- val precision = root .getString(" precision" )
248
+ val precision = influxDBConfig .getString(" precision" )
242
249
243
250
if (! Set (" ns" ," u" ," µ" ," ms" ," s" ).contains(precision)){
244
251
throw new RuntimeException (" Precision must be one of `[ns,u,µ,ms,s]` to match https://docs.influxdata.com/influxdb/v1.7/tools/api/#query-string-parameters-1" )
@@ -249,10 +256,10 @@ object InfluxDBReporter {
249
256
250
257
Settings (
251
258
url,
252
- root .getDoubleList(" percentiles" ).asScala.toList.map(_.toDouble),
259
+ influxDBConfig .getDoubleList(" percentiles" ).asScala.toList.map(_.toDouble),
253
260
credentials,
254
261
Filter .from(" kamon.influxdb.tag-filter" ),
255
- root .getBoolean(" post-empty-distributions" ),
262
+ influxDBConfig .getBoolean(" post-empty-distributions" ),
256
263
additionalTags,
257
264
precision
258
265
)
0 commit comments