Skip to content

Commit

Permalink
Merge pull request #74 from autometrics-dev/rename-metrics
Browse files Browse the repository at this point in the history
Rename metrics
  • Loading branch information
actualwitch authored Aug 9, 2023
2 parents 90e9ed4 + d16204b commit 7b6e180
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 35 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

-
- Renamed the `function.calls.count` metric to `function.calls` (which is exported
to Prometheus as `function_calls_total`) to be in line with OpenTelemetry and
OpenMetrics naming conventions. **Dashboards and alerting rules must be updated.**
- When the `function.calls.duration` histogram is exported to Prometheus, it now
includes the units (`function_calls_duration_seconds`) to be in line with
Prometheus/OpenMetrics naming conventions. **Dashboards and alerting rules must be updated.**

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion src/autometrics/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Constants used by autometrics"""

COUNTER_NAME = "function.calls.count"
COUNTER_NAME = "function.calls"
HISTOGRAM_NAME = "function.calls.duration"
CONCURRENCY_NAME = "function.calls.concurrent"
# NOTE - The Rust implementation does not use `build.info`, instead opts for just `build_info`
Expand Down
2 changes: 1 addition & 1 deletion src/autometrics/test_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def bar():
assert blob is not None
data = blob.decode("utf-8")

expected = """function_calls_count_total{caller="test_caller_detection.<locals>.bar",function="test_caller_detection.<locals>.foo",module="autometrics.test_caller",objective_name="",objective_percentile="",result="ok"} 1.0"""
expected = """function_calls_total{caller="test_caller_detection.<locals>.bar",function="test_caller_detection.<locals>.foo",module="autometrics.test_caller",objective_name="",objective_percentile="",result="ok"} 1.0"""
assert "wrapper" not in data
assert expected in data
64 changes: 32 additions & 32 deletions src/autometrics/test_decorator.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/autometrics/tracker/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self):
self.__histogram_instance = meter.create_histogram(
name=HISTOGRAM_NAME,
description=HISTOGRAM_DESCRIPTION,
unit="seconds",
)
self.__up_down_counter_build_info_instance = meter.create_up_down_counter(
name=BUILD_INFO_NAME,
Expand Down
1 change: 1 addition & 0 deletions src/autometrics/tracker/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PrometheusTracker:
OBJECTIVE_PERCENTILE_PROMETHEUS,
OBJECTIVE_LATENCY_THRESHOLD_PROMETHEUS,
],
unit="seconds",
)
prom_gauge_build_info = Gauge(
BUILD_INFO_NAME, BUILD_INFO_DESCRIPTION, [COMMIT_KEY, VERSION_KEY, BRANCH_KEY]
Expand Down
25 changes: 25 additions & 0 deletions src/autometrics/tracker/test_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from prometheus_client.exposition import generate_latest
import pytest

from . import init_tracker, TrackerType
from .opentelemetry import OpenTelemetryTracker
from ..decorator import autometrics


@pytest.mark.parametrize("tracker", TrackerType)
def test_metrics_format(tracker):
"""Test that the metrics are formatted correctly."""
init_tracker(tracker)

@autometrics
def test_function():
pass

test_function()

blob = generate_latest()
assert blob is not None
data = blob.decode("utf-8")

assert "function_calls_total{" in data
assert "function_calls_duration_seconds_bucket{" in data

0 comments on commit 7b6e180

Please sign in to comment.