Skip to content

Commit bedee71

Browse files
committed
naming
Signed-off-by: Tim Li <[email protected]>
1 parent 43aac5d commit bedee71

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

cadence/_internal/visibility/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MetricType(Enum):
1313
COUNTER = "counter"
1414
GAUGE = "gauge"
1515
HISTOGRAM = "histogram"
16-
SUMMARY = "summary"
16+
TIMER = "timer"
1717

1818

1919
class MetricsHandler(Protocol):

cadence/_internal/visibility/prometheus.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
Counter,
1111
Gauge,
1212
Histogram,
13-
Summary,
1413
generate_latest,
1514
push_to_gateway,
1615
start_http_server,
@@ -55,7 +54,6 @@ def __init__(self, config: Optional[PrometheusConfig] = None):
5554
self._counters: Dict[str, Counter] = {}
5655
self._gauges: Dict[str, Gauge] = {}
5756
self._histograms: Dict[str, Histogram] = {}
58-
self._summaries: Dict[str, Summary] = {}
5957

6058
# HTTP server handle
6159
self._http_server: Optional[Any] = None
@@ -128,23 +126,23 @@ def _get_or_create_histogram(
128126

129127
return self._histograms[metric_name]
130128

131-
def _get_or_create_summary(
129+
def _get_or_create_timer(
132130
self, name: str, labels: Optional[Dict[str, str]]
133-
) -> Summary:
134-
"""Get or create a Summary metric."""
131+
) -> Histogram:
132+
"""Get or create a timer metric (implemented as histogram)."""
135133
metric_name = self._get_metric_name(name)
136134

137-
if metric_name not in self._summaries:
135+
if metric_name not in self._histograms:
138136
label_names = list(self._merge_labels(labels).keys()) if labels else []
139-
self._summaries[metric_name] = Summary(
137+
self._histograms[metric_name] = Histogram(
140138
metric_name,
141-
f"Summary metric for {name}",
139+
f"Timer metric for {name}",
142140
labelnames=label_names,
143141
registry=self.registry,
144142
)
145-
logger.debug(f"Created summary metric: {metric_name}")
143+
logger.debug(f"Created timer metric: {metric_name}")
146144

147-
return self._summaries[metric_name]
145+
return self._histograms[metric_name]
148146

149147
def counter(
150148
self, key: str, n: int = 1, tags: Optional[Dict[str, str]] = None
@@ -183,13 +181,13 @@ def timer(
183181
) -> None:
184182
"""Send a timer metric - implemented as histogram."""
185183
try:
186-
histogram = self._get_or_create_histogram(key, tags)
184+
timer = self._get_or_create_timer(key, tags)
187185
merged_tags = self._merge_labels(tags)
188186

189187
if merged_tags:
190-
histogram.labels(**merged_tags).observe(duration)
188+
timer.labels(**merged_tags).observe(duration)
191189
else:
192-
histogram.observe(duration)
190+
timer.observe(duration)
193191

194192
except Exception as e:
195193
logger.error(f"Failed to send timer {key}: {e}")

tests/cadence/_internal/visibility/test_metrics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from cadence._internal.visibility.metrics import (
77
MetricsHandler,
8+
MetricType,
89
NoOpMetricsHandler,
910
get_default_handler,
1011
set_default_handler,
@@ -79,3 +80,14 @@ def test_set_default_handler(self):
7980

8081
# Restore original for other tests
8182
set_default_handler(original_handler)
83+
84+
85+
class TestMetricType:
86+
"""Test cases for MetricType enum."""
87+
88+
def test_metric_type_values(self):
89+
"""Test that MetricType enum has correct values."""
90+
assert MetricType.COUNTER.value == "counter"
91+
assert MetricType.GAUGE.value == "gauge"
92+
assert MetricType.HISTOGRAM.value == "histogram"
93+
assert MetricType.TIMER.value == "timer"

0 commit comments

Comments
 (0)