diff options
5 files changed, 46 insertions, 17 deletions
diff --git a/kamon-influxdb/src/main/resources/reference.conf b/kamon-influxdb/src/main/resources/reference.conf index 3f12464f..4d78c282 100644 --- a/kamon-influxdb/src/main/resources/reference.conf +++ b/kamon-influxdb/src/main/resources/reference.conf @@ -17,6 +17,10 @@ kamon { # The measurements will be named ${application-name}-timers and -counters application-name = "kamon" + # Allow users to override the name of the hostname reported by kamon. When changed, the hostname tag will be + # the value given here. + hostname-override = none + # For histograms, which percentiles to count percentiles = [50.0, 70.0, 90.0, 95.0, 99.0, 99.9] diff --git a/kamon-influxdb/src/main/scala/kamon/influxdb/TagsGenerator.scala b/kamon-influxdb/src/main/scala/kamon/influxdb/TagsGenerator.scala index cb828623..f478e61a 100644 --- a/kamon-influxdb/src/main/scala/kamon/influxdb/TagsGenerator.scala +++ b/kamon-influxdb/src/main/scala/kamon/influxdb/TagsGenerator.scala @@ -26,9 +26,18 @@ import collection.JavaConversions._ trait TagsGenerator { protected val config: Config - protected val hostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1) protected val application = config.getString("application-name") + val hostname = { + val hostnameOverride = config.getString("hostname-override") + + if (hostnameOverride.equals("none")) { + ManagementFactory.getRuntimeMXBean.getName.split('@')(1) + } else { + hostnameOverride + } + } + protected val percentiles = config.getDoubleList("percentiles").toList protected def generateTags(entity: Entity, metricKey: MetricKey): Map[String, String] = @@ -37,13 +46,13 @@ trait TagsGenerator { Map( "category" -> normalize(entity.tags("trace")), "entity" -> normalize(entity.name), - "hostname" -> normalize(hostName), + "hostname" -> normalize(hostname), "metric" -> normalize(metricKey.name)) case _ ⇒ Map( "category" -> normalize(entity.category), "entity" -> normalize(entity.name), - "hostname" -> normalize(hostName), + "hostname" -> normalize(hostname), "metric" -> normalize(metricKey.name)) } diff --git a/kamon-influxdb/src/test/resources/http_test.conf b/kamon-influxdb/src/test/resources/http_test.conf index 846375bf..8c4963a8 100644 --- a/kamon-influxdb/src/test/resources/http_test.conf +++ b/kamon-influxdb/src/test/resources/http_test.conf @@ -12,6 +12,20 @@ kamon { protocol = "http" application-name = "kamon" + hostname-override = none + + percentiles = [50.0, 70.5] + } + + influxdb-hostname-override { + hostname = "127.0.0.1" + port = 0 + max-packet-size = 1024 + database = "mydb" + protocol = "http" + + application-name = "kamon" + hostname-override = "overridden" percentiles = [50.0, 70.5] } @@ -24,6 +38,7 @@ kamon { protocol = "http" application-name = "kamon" + hostname-override = none percentiles = [50.0, 70.5] diff --git a/kamon-influxdb/src/test/resources/udp_test.conf b/kamon-influxdb/src/test/resources/udp_test.conf index 92ef9bd7..2b9a8474 100644 --- a/kamon-influxdb/src/test/resources/udp_test.conf +++ b/kamon-influxdb/src/test/resources/udp_test.conf @@ -11,21 +11,8 @@ kamon { protocol = "udp" application-name = "kamon" + hostname-override = none percentiles = [50.0, 70.5] - - subscriptions { - histogram = [ "**" ] - min-max-counter = [ "**" ] - gauge = [ "**" ] - counter = [ "**" ] - trace = [ "**" ] - trace-segment = [ "**" ] - akka-actor = [ "**" ] - akka-dispatcher = [ "**" ] - akka-router = [ "**" ] - system-metric = [ "**" ] - http-server = [ "**" ] - } } } diff --git a/kamon-influxdb/src/test/scala/kamon/influxdb/HttpBasedInfluxDBMetricSenderSpec.scala b/kamon-influxdb/src/test/scala/kamon/influxdb/HttpBasedInfluxDBMetricSenderSpec.scala index edd043f9..aa37fb1b 100644 --- a/kamon-influxdb/src/test/scala/kamon/influxdb/HttpBasedInfluxDBMetricSenderSpec.scala +++ b/kamon-influxdb/src/test/scala/kamon/influxdb/HttpBasedInfluxDBMetricSenderSpec.scala @@ -54,6 +54,20 @@ class HttpBasedInfluxDBMetricSenderSpec extends BaseKamonSpec("udp-based-influxd "the HttpSender" should { val influxDBConfig = config.getConfig("kamon.influxdb") val configWithAuthAndRetention = config.getConfig("kamon.influx-with-auth-and-rp") + val configWithHostnameOverride = config.getConfig("kamon.influxdb-hostname-override") + + "use the overriden hostname, if provided" in new HttpSenderFixture(configWithHostnameOverride) { + val testrecorder = buildRecorder("user/kamon") + testrecorder.counter.increment() + + val http = setup(Map(testEntity -> testrecorder.collect(collectionContext))) + val expectedMessage = s"kamon-counters,category=test,entity=user-kamon,hostname=overridden,metric=metric-two value=1 ${from.millis * 1000000}" + + val request = getHttpRequest(http) + val requestData = request.entity.asString.split("\n") + + requestData should contain(expectedMessage) + } "connect to the correct database" in new HttpSenderFixture(influxDBConfig) { val testrecorder = buildRecorder("user/kamon") |