Skip to content

Commit 9b3a579

Browse files
committed
+ prometheus: add configuration parameters to the accumulator
1 parent f4898d9 commit 9b3a579

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

reporters/kamon-prometheus/src/main/resources/reference.conf

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
kamon.prometheus {
66

7-
# Enable or disable publishing the Prometheus scraping enpoint using a embedded server.
7+
# Enable or disable publishing the Prometheus scraping endpoint using a embedded server.
88
start-embedded-http-server = yes
99

1010
# Enable or disable including tags from kamon.environment.tags as labels
@@ -98,6 +98,13 @@ kamon.prometheus {
9898
]
9999
}
100100

101+
periods {
102+
# Period over which to accumulate snapshots in the reporter
103+
accumulation = "1825d"
104+
# Period after which metrics are considered stale and are removed from the prometheus exported data
105+
stale = "1825d"
106+
}
107+
101108
embedded-server {
102109

103110
# Hostname and port used by the embedded web server to publish the scraping enpoint.

reporters/kamon-prometheus/src/main/scala/kamon/prometheus/PrometheusPushgatewayReporter.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ class PrometheusPushgatewayReporter(
3131
) extends MetricReporter {
3232

3333
private val _logger = LoggerFactory.getLogger(classOf[PrometheusPushgatewayReporter])
34+
private val _initialSettings = PrometheusSettings.readSettings(Kamon.config().getConfig(configPath))
3435
private val _snapshotAccumulator =
35-
PeriodSnapshot.accumulator(Duration.ofDays(365 * 5), Duration.ZERO, Duration.ofDays(365 * 5))
36+
PeriodSnapshot.accumulator(
37+
_initialSettings.periodSettings.accumulationPeriod,
38+
Duration.ZERO,
39+
_initialSettings.periodSettings.stalePeriod
40+
)
3641

3742
@volatile private var httpClient: HttpClient = _
3843
@volatile private var settings: PrometheusSettings.Generic = _

reporters/kamon-prometheus/src/main/scala/kamon/prometheus/PrometheusReporter.scala

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ class PrometheusReporter(configPath: String = DefaultConfigPath, initialConfig:
3434

3535
private val _logger = LoggerFactory.getLogger(classOf[PrometheusReporter])
3636
private var _embeddedHttpServer: Option[EmbeddedHttpServer] = None
37-
private val _snapshotAccumulator =
38-
PeriodSnapshot.accumulator(Duration.ofDays(365 * 5), Duration.ZERO, Duration.ofDays(365 * 5))
3937

4038
@volatile private var _preparedScrapeData: String =
4139
"# The kamon-prometheus module didn't receive any data just yet.\n"
4240

4341
@volatile private var _config = initialConfig
4442
@volatile private var _reporterSettings = readSettings(initialConfig.getConfig(configPath))
4543

44+
private val _snapshotAccumulator =
45+
PeriodSnapshot.accumulator(
46+
_reporterSettings.generic.periodSettings.accumulationPeriod,
47+
Duration.ZERO,
48+
_reporterSettings.generic.periodSettings.stalePeriod
49+
)
50+
4651
{
4752
startEmbeddedServerIfEnabled()
4853
}

reporters/kamon-prometheus/src/main/scala/kamon/prometheus/PrometheusSettings.scala

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import kamon.tag.TagSet
2121
import kamon.util.Filter.Glob
2222
import kamon.{Kamon, UtilsOnConfig}
2323

24+
import java.time.Duration
25+
2426
import scala.collection.JavaConverters._
2527

2628
object PrometheusSettings {
@@ -33,14 +35,20 @@ object PrometheusSettings {
3335
customBuckets: Map[String, Seq[java.lang.Double]],
3436
includeEnvironmentTags: Boolean,
3537
summarySettings: SummarySettings,
36-
gaugeSettings: GaugeSettings
38+
gaugeSettings: GaugeSettings,
39+
periodSettings: PeriodSettings
3740
)
3841

3942
case class SummarySettings(
4043
quantiles: Seq[java.lang.Double],
4144
metricMatchers: Seq[Glob]
4245
)
4346

47+
case class PeriodSettings(
48+
accumulationPeriod: Duration,
49+
stalePeriod: Duration
50+
)
51+
4452
case class GaugeSettings(metricMatchers: Seq[Glob])
4553

4654
def readSettings(prometheusConfig: Config): Generic = {
@@ -57,6 +65,10 @@ object PrometheusSettings {
5765
),
5866
gaugeSettings = GaugeSettings(
5967
metricMatchers = prometheusConfig.getStringList("gauges.metrics").asScala.map(Glob).toSeq
68+
),
69+
periodSettings = PeriodSettings(
70+
accumulationPeriod = prometheusConfig.getDuration("periods.accumulation"),
71+
stalePeriod = prometheusConfig.getDuration("periods.stale")
6072
)
6173
)
6274
}

0 commit comments

Comments
 (0)