From 3da8ac27563dc9afc190e4e17f231ee18fe7f8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Schabas?= Date: Fri, 17 Nov 2023 19:50:21 -0300 Subject: [PATCH] #3315 - updated docs for prometheus to match with the new packages due to the upgrade of the java client --- doc/server/observability.md | 16 ++++++++-------- .../observability/PrometheusMetricsExample.scala | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/server/observability.md b/doc/server/observability.md index c1a043ee8e..fc1cd7b68f 100644 --- a/doc/server/observability.md +++ b/doc/server/observability.md @@ -52,7 +52,7 @@ Add the following dependency: "com.softwaremill.sttp.tapir" %% "tapir-prometheus-metrics" % "@VERSION@" ``` -`PrometheusMetrics` encapsulates `CollectorReqistry` and `Metric` instances. It provides several ready to use metrics as +`PrometheusMetrics` encapsulates `PrometheusReqistry` and `Metric` instances. It provides several ready to use metrics as well as an endpoint definition to read the metrics & expose them to the Prometheus server. For example, using `NettyFutureServerInterpreter`: @@ -92,18 +92,18 @@ To create and add custom metrics: ```scala mdoc:compile-only import sttp.tapir.server.metrics.prometheus.PrometheusMetrics import sttp.tapir.server.metrics.{EndpointMetric, Metric} -import io.prometheus.client.{CollectorRegistry, Counter} +import io.prometheus.metrics.core.metrics.{Counter, Gauge, Histogram} +import io.prometheus.metrics.model.registry.PrometheusRegistry import scala.concurrent.Future // Metric for counting responses labeled by path, method and status code val responsesTotal = Metric[Future, Counter]( Counter - .build() - .namespace("tapir") - .name("responses_total") + .builder() + .name("tapir_responses_total") .help("HTTP responses") .labelNames("path", "method", "status") - .register(CollectorRegistry.defaultRegistry), + .register(PrometheusRegistry.defaultRegistry), onRequest = { (req, counter, _) => Future.successful( EndpointMetric() @@ -112,14 +112,14 @@ val responsesTotal = Metric[Future, Counter]( val path = ep.showPathTemplate() val method = req.method.method val status = res.code.toString() - counter.labels(path, method, status).inc() + counter.labelValues(path, method, status).inc() } } ) } ) -val prometheusMetrics = PrometheusMetrics[Future]("tapir", CollectorRegistry.defaultRegistry) +val prometheusMetrics = PrometheusMetrics[Future]("tapir", PrometheusRegistry.defaultRegistry) .addCustom(responsesTotal) ``` diff --git a/examples/src/main/scala/sttp/tapir/examples/observability/PrometheusMetricsExample.scala b/examples/src/main/scala/sttp/tapir/examples/observability/PrometheusMetricsExample.scala index 2c536214ff..acbc2dd73a 100644 --- a/examples/src/main/scala/sttp/tapir/examples/observability/PrometheusMetricsExample.scala +++ b/examples/src/main/scala/sttp/tapir/examples/observability/PrometheusMetricsExample.scala @@ -38,7 +38,7 @@ object PrometheusMetricsExample extends App with StrictLogging { val endpoints = List( personEndpoint, - // Exposes GET endpoint under `metrics` path for prometheus and serializes metrics from `CollectorRegistry` to plain text response + // Exposes GET endpoint under `metrics` path for prometheus and serializes metrics from `PrometheusRegistry` to plain text response prometheusMetrics.metricsEndpoint )