Skip to content

Commit

Permalink
chore(deps): update minor updates (#200)
Browse files Browse the repository at this point in the history
* chore(deps): update minor updates

* fix(deps): prometheus_client 0.16 compat

Pass through extra arguments to mmap_key after prometheus/client_python#804

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jakob van Santen <jvansanten@gmail.com>
  • Loading branch information
renovate[bot] and jvansanten committed Feb 6, 2023
1 parent 50943d8 commit 692aeee
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
poetry run sphinx-build docs/sphinx public
- name: Deploy
uses: peaceiris/actions-gh-pages@v3.9.1
uses: peaceiris/actions-gh-pages@v3.9.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
21 changes: 12 additions & 9 deletions ampel/metrics/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import glob
import os
import tempfile
from typing import Collection

from prometheus_client import (
Metric,
CollectorRegistry,
core,
generate_latest,
Expand All @@ -55,28 +57,29 @@ def collect_metrics():
return generate_latest(registry)


def prometheus_setup_worker(labels=None):
def prometheus_setup_worker(labels: None | dict[str,str] = None) -> None:
"""
Monkey-patch mmap_key and ValueClass to add implicit labels. This must be
done before any metrics are instantiated.
"""
if labels:
if labels is not None:
from prometheus_client import values

def mmap_key(metric_name, name, labelnames, labelvalues):
def mmap_key(metric_name: str, name: str, labelnames: list[str], labelvalues: list[str], help_text: str) -> str:
return mmap_dict.mmap_key(
metric_name,
name,
tuple(labels.keys()) + labelnames,
tuple(labels.values()) + labelvalues,
list(labels.keys()) + list(labelnames) if labels else labelnames,
list(labels.values()) + list(labelvalues) if labels else labelvalues,
help_text,
)

values.mmap_key = mmap_key
# synthesize a new ValueClass (captures mmap_key)
values.ValueClass = values.get_value_class()


def prometheus_cleanup_worker(pid):
def prometheus_cleanup_worker(pid: int) -> None:
"""
Aggregate dead worker's metrics into a single archive file, preventing
collection time from growing without bound as pointed out in
Expand Down Expand Up @@ -109,7 +112,7 @@ def prometheus_cleanup_worker(pid):
collect_paths = paths + archive_paths
collector = multiprocess.MultiProcessCollector(None)

metrics = collector.merge(collect_paths, accumulate=False)
metrics: Collection[Metric] = collector.merge(collect_paths, accumulate=False)

tmp_histogram = tempfile.NamedTemporaryFile(delete=False)
tmp_counter = tempfile.NamedTemporaryFile(delete=False)
Expand All @@ -124,7 +127,7 @@ def prometheus_cleanup_worker(pid):
os.unlink(path)


def write_metrics(metrics, histogram_file, counter_file):
def write_metrics(metrics: Collection[Metric], histogram_file: str, counter_file: str) -> None:

histograms = mmap_dict.MmapedDict(histogram_file)
counters = mmap_dict.MmapedDict(counter_file)
Expand All @@ -142,7 +145,7 @@ def write_metrics(metrics, histogram_file, counter_file):
# prometheus_client 0.4+ adds extra fields
name, labels, value = sample[:3]
key = mmap_dict.mmap_key(
metric.name, name, tuple(labels), tuple(labels.values()),
metric.name, name, list(labels.keys()), list(labels.values()), metric.documentation,
)
sink.write_value(key, value)
finally:
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pydantic = "^1.9.0"
sjcl = "^0.2.1"
schedule = "^1.0.0"
yq = "^3.0.0"
prometheus-client = ">=0.15,<0.16"
prometheus-client = ">=0.16,<0.17"
xxhash = "^3.0.0"
psutil = "^5.8.0"
appdirs = "^1.4.4"
Expand Down

0 comments on commit 692aeee

Please sign in to comment.