Skip to content

Commit

Permalink
Add autometrics version to build_info
Browse files Browse the repository at this point in the history
  • Loading branch information
actualwitch committed Nov 14, 2023
1 parent c3d23b7 commit e6880bc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Description

> Please give context of this change for reviewers. **What did you change, and why?**
## Checklist

- [ ] Describe what you're doing, to help give context for reviewer(s)
- [ ] Link to any helpful documentation (Github issues, linear, Slack discussions, etc)
- [ ] Create test cases
- [ ] Update changelog
<!-- Use these for release PRs:
- [ ] Update package version in `pyprojevt.toml`
- [ ] Update spec version in `constants.py`
- [ ] Move changes to a new section in `CHANGELOG.md` -->
4 changes: 4 additions & 0 deletions src/autometrics/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Constants used by autometrics"""

SPEC_VERSION = "1.0.0"

COUNTER_NAME = "function.calls"
HISTOGRAM_NAME = "function.calls.duration"
CONCURRENCY_NAME = "function.calls.concurrent"
Expand All @@ -8,6 +10,7 @@
SERVICE_NAME = "service.name"
REPOSITORY_URL = "repository.url"
REPOSITORY_PROVIDER = "repository.provider"
AUTOMETRICS_VERSION = "autometrics.version"


COUNTER_NAME_PROMETHEUS = COUNTER_NAME.replace(".", "_")
Expand All @@ -16,6 +19,7 @@
SERVICE_NAME_PROMETHEUS = SERVICE_NAME.replace(".", "_")
REPOSITORY_URL_PROMETHEUS = REPOSITORY_URL.replace(".", "_")
REPOSITORY_PROVIDER_PROMETHEUS = REPOSITORY_PROVIDER.replace(".", "_")
AUTOMETRICS_VERSION_PROMETHEUS = AUTOMETRICS_VERSION.replace(".", "_")

COUNTER_DESCRIPTION = "Autometrics counter for tracking function calls"
HISTOGRAM_DESCRIPTION = "Autometrics histogram for tracking function call duration"
Expand Down
3 changes: 3 additions & 0 deletions src/autometrics/tracker/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .types import Result
from ..objectives import Objective, ObjectiveLatency
from ..constants import (
AUTOMETRICS_VERSION,
CONCURRENCY_NAME,
CONCURRENCY_DESCRIPTION,
COUNTER_DESCRIPTION,
Expand All @@ -33,6 +34,7 @@
OBJECTIVE_NAME,
OBJECTIVE_PERCENTILE,
OBJECTIVE_LATENCY_THRESHOLD,
SPEC_VERSION,
)
from ..settings import get_settings

Expand Down Expand Up @@ -165,6 +167,7 @@ def set_build_info(self, commit: str, version: str, branch: str):
SERVICE_NAME: get_settings()["service_name"],
REPOSITORY_URL: get_settings()["repository_url"],
REPOSITORY_PROVIDER: get_settings()["repository_provider"],
AUTOMETRICS_VERSION: SPEC_VERSION,
},
)

Expand Down
4 changes: 4 additions & 0 deletions src/autometrics/tracker/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from prometheus_client import Counter, Histogram, Gauge

from ..constants import (
AUTOMETRICS_VERSION_PROMETHEUS,
COUNTER_NAME_PROMETHEUS,
HISTOGRAM_NAME_PROMETHEUS,
CONCURRENCY_NAME_PROMETHEUS,
Expand All @@ -18,6 +19,7 @@
OBJECTIVE_PERCENTILE_PROMETHEUS,
OBJECTIVE_LATENCY_THRESHOLD_PROMETHEUS,
COMMIT_KEY,
SPEC_VERSION,
VERSION_KEY,
BRANCH_KEY,
)
Expand Down Expand Up @@ -69,6 +71,7 @@ class PrometheusTracker:
SERVICE_NAME_PROMETHEUS,
REPOSITORY_URL_PROMETHEUS,
REPOSITORY_PROVIDER_PROMETHEUS,
AUTOMETRICS_VERSION_PROMETHEUS,
],
)
prom_gauge_concurrency = Gauge(
Expand Down Expand Up @@ -156,6 +159,7 @@ def set_build_info(self, commit: str, version: str, branch: str):
service_name,
repository_url,
repository_provider,
SPEC_VERSION,
).set(1)

def start(
Expand Down
4 changes: 2 additions & 2 deletions src/autometrics/tracker/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_init_prometheus_tracker_set_build_info(monkeypatch):
assert blob is not None
data = blob.decode("utf-8")

prom_build_info = f"""build_info{{branch="{branch}",commit="{commit}",repository_provider="github",repository_url="git@github.com:autometrics-dev/autometrics-py.git",service_name="autometrics",version="{version}"}} 1.0"""
prom_build_info = f"""build_info{{autometrics_version="1.0.0",branch="{branch}",commit="{commit}",repository_provider="github",repository_url="git@github.com:autometrics-dev/autometrics-py.git",service_name="autometrics",version="{version}"}} 1.0"""
assert prom_build_info in data

monkeypatch.delenv("AUTOMETRICS_VERSION", raising=False)
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_init_otel_tracker_set_build_info(monkeypatch):
assert blob is not None
data = blob.decode("utf-8")

otel_build_info = f"""build_info{{branch="{branch}",commit="{commit}",repository_provider="github",repository_url="git@github.com:autometrics-dev/autometrics-py.git",service_name="autometrics",version="{version}"}} 1.0"""
otel_build_info = f"""build_info{{autometrics_version="1.0.0",branch="{branch}",commit="{commit}",repository_provider="github",repository_url="git@github.com:autometrics-dev/autometrics-py.git",service_name="autometrics",version="{version}"}} 1.0"""
assert otel_build_info in data

monkeypatch.delenv("AUTOMETRICS_VERSION", raising=False)
Expand Down

0 comments on commit e6880bc

Please sign in to comment.