Skip to content

Commit

Permalink
Merge pull request #1160 from avast/http4s-prometheus-conflict
Browse files Browse the repository at this point in the history
Http4s prometheus conflict
  • Loading branch information
Karry authored Jun 17, 2024
2 parents 1dc5993 + fe24cbb commit f9611ca
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,12 @@ lazy val micrometerPrometheus = project
.settings(BuildSettings.common)
.settings(
name := "sst-micrometer-prometheus",
libraryDependencies += Dependencies.micrometerPrometheus
libraryDependencies ++= Seq(
Dependencies.micrometerPrometheus,
Dependencies.monixEval % Test,
Dependencies.monixExecution % Test,
Dependencies.http4sPrometheus % Test
)
)

lazy val micrometerPrometheusPureConfig = project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.avast.sst.micrometer.prometheus

import io.micrometer.prometheus.HistogramFlavor

import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration

final case class MicrometerPrometheusConfig(
step: Duration = Duration(1, TimeUnit.MINUTES),
prefix: String = "",
descriptions: Boolean = true,
histogramFlavor: HistogramFlavor = HistogramFlavor.Prometheus,
commonTags: Map[String, String] = Map.empty
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.avast.sst.micrometer.prometheus
import cats.effect.{Blocker, ContextShift, Resource, Sync}
import com.avast.sst.micrometer.PrefixMeterFilter
import io.micrometer.core.instrument.config.{MeterFilter, NamingConvention}
import io.micrometer.prometheusmetrics.{PrometheusConfig, PrometheusMeterRegistry}
import io.micrometer.prometheus.{HistogramFlavor, PrometheusConfig, PrometheusMeterRegistry}

import java.time.Duration

Expand Down Expand Up @@ -44,6 +44,7 @@ object MicrometerPrometheusModule {
override val step: Duration = java.time.Duration.ofMillis(c.step.toMillis)
override val prefix: String = c.prefix
override val descriptions: Boolean = c.descriptions
override val histogramFlavor: HistogramFlavor = c.histogramFlavor

// the method is @Nullable and we don't need to implement it here
@SuppressWarnings(Array("scalafix:DisableSyntax.null"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.avast.sst.micrometer.prometheus

import cats.effect.*
import monix.eval.Task
import monix.eval.instances.CatsConcurrentEffectForTask
import monix.execution.Scheduler
import org.http4s.metrics.prometheus.PrometheusExportService
import org.scalatest.funsuite.AnyFunSuite

import java.util.concurrent.{SynchronousQueue, ThreadPoolExecutor, TimeUnit}
import scala.concurrent.ExecutionContext

class Http4sPrometheusCompatibilityTest extends AnyFunSuite {

implicit def scheduler: Scheduler = Scheduler.global

protected def options: Task.Options = Task.defaultOptions.withSchedulerFeatures(scheduler)

protected implicit lazy val catsEffect: ConcurrentEffect[Task] =
new CatsConcurrentEffectForTask()(scheduler, options)

test("Http4s Prometheus compatibility test") {

val config = MicrometerPrometheusConfig()

val blockingExecutor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, new SynchronousQueue())
val blocker = Blocker.liftExecutionContext(ExecutionContext.fromExecutor(blockingExecutor))

val test = for {

prometheusMeterRegistry <- MicrometerPrometheusModule.make(config, blocker)
_ = PrometheusExportService(prometheusMeterRegistry.getPrometheusRegistry)
_ <- PrometheusExportService.addDefaults(prometheusMeterRegistry.getPrometheusRegistry)
} yield ()

test.use(_ => Task.unit).runSyncUnsafe()

}
}
10 changes: 6 additions & 4 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object Dependencies {
val http4sEmberServer = "org.http4s" %% "http4s-ember-server" % Versions.http4s
val http4sClient = "org.http4s" %% "http4s-client" % Versions.http4s
val http4sDsl = "org.http4s" %% "http4s-dsl" % Versions.http4s
val http4sPrometheus = "org.http4s" %% "http4s-prometheus-metrics" % Versions.http4s
val http4sServer = "org.http4s" %% "http4s-server" % Versions.http4s
val jacksonDatabind = "com.fasterxml.jackson.core" % "jackson-databind" % "2.17.1"
val jetbrainsAnnotations = "org.jetbrains" % "annotations" % "24.1.0"
Expand All @@ -30,6 +31,7 @@ object Dependencies {
val micrometerPrometheus = "io.micrometer" % "micrometer-registry-prometheus" % Versions.micrometerPrometheus
val monixCatnap = "io.monix" %% "monix-catnap" % Versions.monix
val monixEval = "io.monix" %% "monix-eval" % Versions.monix
val monixExecution = "io.monix" %% "monix-execution" % Versions.monix
val postgresql = "org.postgresql" % "postgresql" % "42.7.3"
val pureConfigCore = "com.github.pureconfig" %% "pureconfig-core" % Versions.pureConfig
val pureConfigGeneric = "com.github.pureconfig" %% "pureconfig-generic" % Versions.pureConfig
Expand All @@ -51,10 +53,10 @@ object Dependencies {
val doobie = "0.13.4"
val grpc = "1.64.0"
val http4s = "0.22.15"
val micrometerCore = "1.13.1"
val micrometerJmx = "1.13.1"
val micrometerStatsD = "1.13.1"
val micrometerPrometheus = "1.13.1"
val micrometerCore = "1.12.7"
val micrometerJmx = "1.12.7"
val micrometerStatsD = "1.12.7"
val micrometerPrometheus = "1.12.7"
val monix = "3.4.1"
val pureConfig = "0.17.1"

Expand Down

0 comments on commit f9611ca

Please sign in to comment.