Skip to content

Commit

Permalink
configurable sending # of measurements (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBagheera authored and dpsoft committed Jun 8, 2017
1 parent c02e455 commit f3f9094
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ kamon {
# For histograms, which percentiles to count
percentiles = [50.0, 70.0, 90.0, 95.0, 99.0, 99.9]

# Include number of measurements?
include-measurements = no

# extra tags
extra-tags = {}

Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/kamon/influxdb/TagsGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ trait TagsGenerator {
}

protected val percentiles = config.getDoubleList("percentiles").toList
protected val includeMeasurements = config.getBoolean("include-measurements")

protected val extraTags = config.getObject("extra-tags").unwrapped().toSeq.sortBy(_._1).map {
case (k, v: String) (normalize(k), normalize(v))
case (k, v: Number) (normalize(k), normalize(v.toString))
case (k, v: java.lang.Boolean) (normalize(k), v.toString)
case (k, v: AnyRef) throw new IllegalArgumentException(s"Unsupported tag value type ${v.getClass.getName} for tag $k")
}


protected def generateTags(entity: Entity, metricKey: MetricKey): Map[String, String] = {
val baseTags = Seq(
"category" -> normalize(entity.category),
Expand All @@ -60,10 +63,13 @@ trait TagsGenerator {
}

protected def histogramValues(hs: Histogram.Snapshot): Map[String, BigDecimal] = {
val measurements =
if (includeMeasurements) Map("measurements" -> BigDecimal(hs.numberOfMeasurements))
else Map.empty
val defaults = Map(
"lower" -> BigDecimal(hs.min),
"mean" -> average(hs),
"upper" -> BigDecimal(hs.max))
"upper" -> BigDecimal(hs.max)) ++ measurements

percentiles.foldLeft(defaults) { (acc, p)
val fractional = p % 1
Expand Down
19 changes: 19 additions & 0 deletions src/test/resources/http_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ kamon {
hostname-override = "overridden"

percentiles = [50.0, 70.5]

include-measurements = no

extra-tags = {}
}

Expand All @@ -42,6 +45,8 @@ kamon {
hostname-override = none

percentiles = [50.0, 70.5]

include-measurements = no
extra-tags = {}

authentication {
Expand All @@ -52,6 +57,20 @@ kamon {
retention-policy = "six_month_rollup"
}


influxdb-with-measurements {
hostname = "127.0.0.1"
port = 0
max-packet-size = 1024
database = "mydb"
protocol = "http"

application-name = "kamon"
hostname-override = none

percentiles = [50.0, 70.5]
include-measurements = yes

influxdb-with-extra-tags = ${kamon.influxdb}
influxdb-with-extra-tags.extra-tags = {
tag1 = "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class HttpBasedInfluxDBMetricSenderSpec extends BaseKamonSpec("udp-based-influxd
val influxDBConfig = config.getConfig("kamon.influxdb")
val configWithAuthAndRetention = config.getConfig("kamon.influx-with-auth-and-rp")
val configWithHostnameOverride = config.getConfig("kamon.influxdb-hostname-override")
val configWithMeasurementsEnabled = config.getConfig("kamon.influxdb-with-measurements")
val configWithExtraTags= config.getConfig("kamon.influxdb-with-extra-tags")

"use the overriden hostname, if provided" in new HttpSenderFixture(configWithHostnameOverride) {
Expand Down Expand Up @@ -141,6 +142,17 @@ class HttpBasedInfluxDBMetricSenderSpec extends BaseKamonSpec("udp-based-influxd

requestData should contain(expectedMessage)
}

"send number of measurements, if enabled" in new HttpSenderFixture(configWithMeasurementsEnabled) {
val testRecorder = buildRecorder("user/kamon")

testRecorder.histogramOne.record(10L)
testRecorder.histogramOne.record(5L)

val http = setup(Map(testEntity -> testRecorder.collect(collectionContext)))
val expectedMessage = s"kamon-timers,category=test,entity=user-kamon,hostname=$hostName,metric=metric-one measurements=2,mean=7.5,lower=5,upper=10,p70.5=10,p50=5 ${from.millis * 1000000}"
}

"send extra tags, if configured" in new HttpSenderFixture(configWithExtraTags) {
val testRecorder = buildRecorder("user/kamon")
testRecorder.counter.increment()
Expand Down

0 comments on commit f3f9094

Please sign in to comment.