From 35798a1bb44b25bb519d0b9ee41511c31edf5ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=A7?= <90313638+actualwitch@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:42:12 +0100 Subject: [PATCH] Add autometrics version to build_info (#101) * Add autometrics version to build_info * Update changelog --- .github/pull_request_template.md | 14 ++++++++++++++ CHANGELOG.md | 1 + src/autometrics/constants.py | 4 ++++ src/autometrics/tracker/opentelemetry.py | 3 +++ src/autometrics/tracker/prometheus.py | 4 ++++ src/autometrics/tracker/test_tracker.py | 4 ++-- 6 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..88a32f9 --- /dev/null +++ b/.github/pull_request_template.md @@ -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 + diff --git a/CHANGELOG.md b/CHANGELOG.md index 6459784..52ccaef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added support for `record_error_if` and `record_success_if` - Added OTLP exporters for OpenTelemetry tracker (#89) - Added `repository_url` and `repository_provider` labels to `build_info` (#97) +- Added `autometrics.version` label to `build_info` (#101) ### Changed diff --git a/src/autometrics/constants.py b/src/autometrics/constants.py index ec0a5d1..90f259a 100644 --- a/src/autometrics/constants.py +++ b/src/autometrics/constants.py @@ -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" @@ -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(".", "_") @@ -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" diff --git a/src/autometrics/tracker/opentelemetry.py b/src/autometrics/tracker/opentelemetry.py index 657f99a..d50b863 100644 --- a/src/autometrics/tracker/opentelemetry.py +++ b/src/autometrics/tracker/opentelemetry.py @@ -19,6 +19,7 @@ from .types import Result from ..objectives import Objective, ObjectiveLatency from ..constants import ( + AUTOMETRICS_VERSION, CONCURRENCY_NAME, CONCURRENCY_DESCRIPTION, COUNTER_DESCRIPTION, @@ -33,6 +34,7 @@ OBJECTIVE_NAME, OBJECTIVE_PERCENTILE, OBJECTIVE_LATENCY_THRESHOLD, + SPEC_VERSION, ) from ..settings import get_settings @@ -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, }, ) diff --git a/src/autometrics/tracker/prometheus.py b/src/autometrics/tracker/prometheus.py index be549d4..5408d90 100644 --- a/src/autometrics/tracker/prometheus.py +++ b/src/autometrics/tracker/prometheus.py @@ -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, @@ -18,6 +19,7 @@ OBJECTIVE_PERCENTILE_PROMETHEUS, OBJECTIVE_LATENCY_THRESHOLD_PROMETHEUS, COMMIT_KEY, + SPEC_VERSION, VERSION_KEY, BRANCH_KEY, ) @@ -69,6 +71,7 @@ class PrometheusTracker: SERVICE_NAME_PROMETHEUS, REPOSITORY_URL_PROMETHEUS, REPOSITORY_PROVIDER_PROMETHEUS, + AUTOMETRICS_VERSION_PROMETHEUS, ], ) prom_gauge_concurrency = Gauge( @@ -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( diff --git a/src/autometrics/tracker/test_tracker.py b/src/autometrics/tracker/test_tracker.py index 8819413..1477d98 100644 --- a/src/autometrics/tracker/test_tracker.py +++ b/src/autometrics/tracker/test_tracker.py @@ -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) @@ -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)