metrics: add dyncfg-driven export filter for environmentd metrics - #38616
Open
bosconi wants to merge 1 commit into
Open
metrics: add dyncfg-driven export filter for environmentd metrics#38616bosconi wants to merge 1 commit into
bosconi wants to merge 1 commit into
Conversation
bosconi
force-pushed
the
jc/incident-general
branch
from
September 2, 2026 06:34
bc95e0f to
90b7a7c
Compare
A single environmentd `/metrics` response grows with the catalog: many
families carry one series per object, persist shard, replica or cluster.
Scrapers reject oversized responses outright, which loses every metric of
the process at once, and until now the only lever was a code change and a
rollout.
Add a gather-time postprocessor on the metrics registry, installed once per
environmentd instance from `serve`, that drops families and scopes series
according to four new dyncfgs:
* `metrics_export_disabled_families`: comma-separated family names with an
optional trailing `*` prefix glob.
* `metrics_export_cluster_allowlist`: when set, series carrying an
`instance_id`, `cluster_id` or `compute_instance` label are exported only
for these clusters.
* `metrics_export_replica_allowlist`: the same for `replica_id`.
* `metrics_export_max_series_per_family`: a family with more exported
samples than this is dropped whole rather than truncated, so a dashboard
sees an absent family instead of a partial one that looks complete.
All default to no filtering. Counts are exported samples as the text
encoder emits them, so histogram-heavy families are not undercounted. The
filter reads its configuration from the live system dyncfg set environmentd
already holds, re-parsing only on change, so there is no per-scrape catalog
round-trip and no process-global state.
The filter records what it did in `mz_metrics_export_series{family}`,
`mz_metrics_export_dropped_series_total{family,reason}` and
`mz_metrics_export_encoded_bytes`, which are themselves exempt from
filtering so the operator can always see what was dropped.
Filtering is export-side only: the series still exist in the registry, so
re-enabling a family restores its current values, and the process still
pays for maintaining them. Emission-side gating per family is follow-up
work tracked in DB-199. The design doc in doc/developer/design covers the
alternatives.
Tests: unit tests for parsing, each rule, the cap, histogram sample
counting, self-metric exemption, stale gauge children and live dyncfg
updates in `mz_metrics::export_filter`; an environmentd integration test
`test_metrics_export_filter` that flips each dyncfg via `ALTER SYSTEM` and
scrapes `/metrics`. CI defaults exercise the filter path with a
non-existent probe family and a high cap.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
bosconi
marked this pull request as ready for review
September 2, 2026 06:34
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
In INC-1252 a single environmentd
/metricsresponse (~58 MB, ~450k samples) exceeded the AMP scraper's 50 MiB body-size limit, so every scrape failed and all environmentd metrics for the environment disappeared for hours, twice. Many families carry one series per catalog object, persist shard, replica or cluster, so the response grows with the catalog, and until now the only lever was a code change and a rollout.Tracking issue: DB-199. Design:
doc/developer/design/20260902_metrics_export_filter.mdin this PR.Description
Adds a gather-time postprocessor on the metrics registry, installed once per environmentd instance from
mz_environmentd::serve, that drops families and scopes series at export time according to four new dyncfgs. All default to no filtering.metrics_export_disabled_families*matches a prefix. Matching families are removed.metrics_export_cluster_allowlistinstance_id,cluster_idorcompute_instanceare exported only for the listed clusters.metrics_export_replica_allowlistreplica_id.metrics_export_max_series_per_familyThe filter records what it did in
mz_metrics_export_series{family},mz_metrics_export_dropped_series_total{family,reason}andmz_metrics_export_encoded_bytes. Its own families are exempt from filtering so the operator can always see what was dropped. The per-family sample gauge and the encoded-bytes gauge are the leading indicators we lacked during the incident.Design notes:
+Inf,_countand_sum, and histogram-heavy families dominated the incident.application_namelabel) is follow-up work in DB-199./metrics/publicgathers environmentd's own families through the filter and then merges clusterd-sourced series it fetches separately, so the filter governs environmentd's own series only.Tests
mz_metrics::export_filterfor list parsing, each rule, the cap, histogram sample counting, self-metric exemption, stale gauge children, and live dyncfg updates.test_metrics_export_filterinsrc/environmentd/tests/server.rsflips each dyncfg viaALTER SYSTEMon a running environmentd and scrapes/metrics.Tips for reviewer
Start with
src/metrics/src/export_filter.rs; everything else is wiring. The design doc covers the alternatives considered, including the process-global variant this PR replaced.Checklist
$T ⇔ Proto$Tmapping (possibly in a backwards-incompatible way), then it is tagged with aT-protolabel.🤖 Generated with Claude Code