feat: prometheus metrics endpoint on SN and DN nodes#447
Open
joaopaulosr95 wants to merge 1 commit into
Open
Conversation
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When running HSDS on Kubernetes there is currently no machine-readable health signal beyond the
/infoJSON endpoint. This PR adds a standard Prometheus/metricsendpoint to every node so operators can alert on service health, saturation, and storage-backend problems using the usual Prometheus/Grafana stack.What changed
New
/metricsendpoint (hsds/metrics.py), built on the officialprometheus_clientlibrary:hsds_http_requests_total{method,status}and anhsds_http_request_duration_secondshistogram for every request.hsds_node_ready), known DN count (hsds_active_dn_count), asyncio task saturation (hsds_tasks_active/hsds_tasks_max), WARN/ERROR log counts, LRU cache stats (items, dirty count, memory used/target per cache), and storage counters (errors, bytes read/written, labelled by backend).process_*/python_gc_*metrics for free./metricsis served regardless of node state, so unhealthy nodes remain observable.Storage stats bug fixes (found while validating the metrics live):
fileClient._file_stats_incrementwas missing its final increment statement, so every POSIX storage counter stayed at zero permanently (s3/azure clients have the line; the file client validated the input and returned without counting).bytes_inwas initialized but never incremented in any backend; it is now recorded onget_objectin the file, s3, and azure clients.Kubernetes manifests:
prometheus.io/scrapeannotations and named container ports (sn,dn) in the three deployment manifests so annotation-based discovery scrapes the SN and a PodMonitor can target both containers.Docs:
docs/prometheus_metrics.mdwith the metric reference, the rationale for each signal, a PodMonitor example, and suggested alert rules.Dependency:
prometheus-client(pure Python, no transitive deps) added topyproject.tomlandrequirements.txt.Testing
tests/unit/metrics_test.py(middleware counting, exposition rendering, cache/storage/node metrics, handler response, and a regression test for the fileClient stats bug), registered intestall.pyand collected by pytest in CI.python testall.py(unit + integration against a standalone server with 4 DNs, posix storage) passes./metricson SN and DN nodes during the integration run; request counters, latency buckets, cache gauges, and storage byte counters all advance as expected.flake8clean under both CI configurations.