Skip to content

Commit

Permalink
Use updated labels API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Jan 31, 2024
1 parent fd39ac2 commit e66edfd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions core/src/main/scala/io/chrisdavenport/epimetheus/Histogram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import cats.effect._
import cats.implicits._
import io.prometheus.metrics.core.datapoints.DistributionDataPoint
import io.prometheus.metrics.core.metrics.{Histogram => JHistogram}
import io.prometheus.metrics.model.snapshots.Labels

import scala.annotation.tailrec
import scala.concurrent.duration._
import scala.jdk.CollectionConverters.MapHasAsJava

/** Histogram metric, to track distributions of events.
*
Expand Down Expand Up @@ -263,8 +263,11 @@ object Histogram {
) extends Histogram[F] {
def observe(d: Double): F[Unit] = Sync[F].delay(underlying.observe(d))

def observeWithExemplar(d: Double, exemplarLabels: Map[String, String]): F[Unit] =
Sync[F].delay(underlying.observeWithExemplar(d, exemplarLabels.asJava))
def observeWithExemplar(d: Double, exemplarLabels: Map[String, String]): F[Unit] = {
val labels = exemplarLabels.toList.flatMap { case (k, v) => List(k, v) }
val jLabels = Labels.of(labels:_*)
Sync[F].delay(underlying.observeWithExemplar(d, jLabels))
}

override private[epimetheus] def asJava: F[JHistogram] = underlying.pure[F]
}
Expand All @@ -274,8 +277,11 @@ object Histogram {
) extends Histogram[F] {
def observe(d: Double): F[Unit] = Sync[F].delay(underlying.observe(d))

def observeWithExemplar(d: Double, exemplarLabels: Map[String, String]): F[Unit] =
Sync[F].delay(underlying.observeWithExemplar(d, exemplarLabels.asJava))
def observeWithExemplar(d: Double, exemplarLabels: Map[String, String]): F[Unit] = {
val labels = exemplarLabels.toList.flatMap { case (k, v) => List(k, v) }
val jLabels = Labels.of(labels:_*)
Sync[F].delay(underlying.observeWithExemplar(d, jLabels))
}

override private[epimetheus] def asJava: F[JHistogram] =
ApplicativeThrow[F].raiseError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HistogramSpec extends munit.CatsEffectSuite {

test("Histogram: observe with exemplars (map)") {
val setup = for {
cr <- CollectorRegistry.build[IO]
cr <- PrometheusRegistry.build[IO]
h <- Histogram.noLabels(cr, Name("boo"), "Boo ")
} yield h

Expand All @@ -38,7 +38,7 @@ class HistogramSpec extends munit.CatsEffectSuite {

test("Histogram: observe with exemplars (tuples)") {
val setup = for {
cr <- CollectorRegistry.build[IO]
cr <- PrometheusRegistry.build[IO]
h <- Histogram.noLabels(cr, Name("boo"), "Boo ")
} yield h

Expand Down

0 comments on commit e66edfd

Please sign in to comment.