Skip to content

Commit

Permalink
Allow enabling/disabling _created metrics from code (#973)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Marchbanks <[email protected]>
  • Loading branch information
csmarchbanks authored Oct 27, 2023
1 parent 546599b commit ea78128
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion prometheus_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
write_to_textfile,
)
from .gc_collector import GC_COLLECTOR, GCCollector
from .metrics import Counter, Enum, Gauge, Histogram, Info, Summary
from .metrics import (
Counter, disable_created_metrics, enable_created_metrics, Enum, Gauge,
Histogram, Info, Summary,
)
from .metrics_core import Metric
from .platform_collector import PLATFORM_COLLECTOR, PlatformCollector
from .process_collector import PROCESS_COLLECTOR, ProcessCollector
Expand All @@ -27,6 +30,8 @@
'Histogram',
'Info',
'Enum',
'enable_created_metrics',
'disable_created_metrics',
'CONTENT_TYPE_LATEST',
'generate_latest',
'MetricsHandler',
Expand Down
12 changes: 12 additions & 0 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ def _get_use_created() -> bool:
_use_created = _get_use_created()


def disable_created_metrics():
"""Disable exporting _created metrics on counters, histograms, and summaries."""
global _use_created
_use_created = False


def enable_created_metrics():
"""Enable exporting _created metrics on counters, histograms, and summaries."""
global _use_created
_use_created = True


class MetricWrapperBase(Collector):
_type: Optional[str] = None
_reserved_labelnames: Sequence[str] = ()
Expand Down

0 comments on commit ea78128

Please sign in to comment.