Skip to content

Commit

Permalink
fix(prometheus): strip period from prometheus metrics names DEVX-637 (#…
Browse files Browse the repository at this point in the history
…677)

* Make sure metrics names based on span name don't include disallowed chars for prometheus

see: https://reddit.slack.com/archives/CCM109VKM/p1654127902504289
see: https://github.com/prometheus/client_python/blob/748ffb00600dc25fbd22d37d549578e8e370d996/prometheus_client/metrics_core.py#L10

* remove spacing (linting)
  • Loading branch information
nsheaps committed Jun 2, 2022
1 parent 8be0f5c commit 94b2fc3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions baseplate/lib/prometheus_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re

from typing import Any
from typing import Dict
Expand Down Expand Up @@ -446,6 +447,11 @@ def get_active_requests_metric(cls) -> Gauge:


def get_metrics_for_prefix(prefix: str) -> PrometheusGenericSpanMetrics:
# make sure metric names don't include disallowed chars
# https://github.com/prometheus/client_python/blob/748ffb00600dc25fbd22d37d549578e8e370d996/prometheus_client/metrics_core.py#L10
prefix = prefix.replace(".", "_")
prefix = re.sub("[^0-9a-zA-Z_:]+", "", prefix)

if prefix not in generic_metrics:
# local labels and metrics
labels = [
Expand Down

0 comments on commit 94b2fc3

Please sign in to comment.