Skip to content

Commit f4d787a

Browse files
committed
add textformats dependency
1 parent 918fc68 commit f4d787a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ lazy val `pekko-http-metrics-prometheus` = (project in file("prometheus"))
131131
libraryDependencies ++= Seq(
132132
Dependencies.PrometheusCore,
133133
Dependencies.PrometheusExpositionFormats,
134+
Dependencies.PrometheusExpositionTextFormats,
134135
Dependencies.Provided.PekkoStream,
135136
Dependencies.Test.Logback,
136137
Dependencies.Test.PekkoHttpTestkit,

project/Dependencies.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ object Dependencies {
2727
val PrometheusCore = "io.prometheus" % "prometheus-metrics-core" % Versions.Prometheus
2828
val PrometheusExpositionFormats =
2929
"io.prometheus" % "prometheus-metrics-exposition-formats" % Versions.Prometheus
30+
val PrometheusExpositionTextFormats =
31+
"io.prometheus" % "prometheus-metrics-exposition-textformats" % Versions.Prometheus
3032
val ScalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % Versions.ScalaLogging
3133

3234
object Provided {

prometheus/src/main/scala/fr/davit/pekko/http/metrics/prometheus/marshalling/PrometheusMarshallers.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ trait PrometheusMarshallers {
3333
.applicationWithFixedCharset("openmetrics-text", HttpCharsets.`UTF-8`)
3434
.withParams(Map("version" -> "1.0.0"))
3535

36-
val OpenMetricsMarshaller: ToEntityMarshaller[PrometheusRegistry] = openMetricsMarshaller(false, false)
36+
val OpenMetricsMarshaller: ToEntityMarshaller[PrometheusRegistry] = openMetricsMarshaller()
3737
def openMetricsMarshaller(
38-
createdTimestampsEnabled: Boolean,
39-
exemplarsOnAllMetricTypesEnabled: Boolean
38+
createdTimestampsEnabled: Boolean = false,
39+
exemplarsOnAllMetricTypesEnabled: Boolean = false
4040
): ToEntityMarshaller[PrometheusRegistry] = {
41-
val writer = new OpenMetricsTextFormatWriter(createdTimestampsEnabled, exemplarsOnAllMetricTypesEnabled)
41+
val writer = OpenMetricsTextFormatWriter
42+
.builder()
43+
.setCreatedTimestampsEnabled(createdTimestampsEnabled)
44+
.setExemplarsOnAllMetricTypesEnabled(exemplarsOnAllMetricTypesEnabled)
45+
.build()
4246
Marshaller
4347
.byteArrayMarshaller(OpenMetricsContentType)
4448
.compose { registry =>
@@ -52,9 +56,12 @@ trait PrometheusMarshallers {
5256
.withParams(Map("version" -> "0.0.4"))
5357
.withCharset(HttpCharsets.`UTF-8`)
5458

55-
val TextMarshaller: ToEntityMarshaller[PrometheusRegistry] = textMarshaller(false)
56-
def textMarshaller(writeCreatedTimestamps: Boolean): ToEntityMarshaller[PrometheusRegistry] = {
57-
val writer = new PrometheusTextFormatWriter(writeCreatedTimestamps)
59+
val TextMarshaller: ToEntityMarshaller[PrometheusRegistry] = textMarshaller()
60+
def textMarshaller(includeCreatedTimestamps: Boolean = false): ToEntityMarshaller[PrometheusRegistry] = {
61+
val writer = PrometheusTextFormatWriter
62+
.builder()
63+
.setIncludeCreatedTimestamps(includeCreatedTimestamps)
64+
.build()
5865
Marshaller
5966
.byteArrayMarshaller(TextContentType)
6067
.compose { registry =>

0 commit comments

Comments
 (0)