feat(metrics/otel): add histogram bucket views per metric-name pattern#66805
Open
1fanwang wants to merge 1 commit into
Open
feat(metrics/otel): add histogram bucket views per metric-name pattern#668051fanwang wants to merge 1 commit into
1fanwang wants to merge 1 commit into
Conversation
Follow-up to apache#64207, which set ExponentialBucketHistogramAggregation as the instrument-type default for OTel histograms. Non-timer histograms (*_count, *_duration, *_delay) still pick bucket boundaries at each call site. This change moves that decision into a single declarative map keyed by metric-name suffix glob, and layers the resulting Views on top of the existing instrument-type baseline. Closes apache#66801 Signed-off-by: 1fanwang <1fannnw@gmail.com>
2 tasks
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.
Fix for the one-size-fits-all OTel histogram bucketing called out in #66801. Histogram-eligible Airflow metrics all share the default boundaries today, which makes the tails of some of our LinkedIn DI dashboards useless — task duration buckets fine, scheduler-loop duration needs finer resolution at the low end. This PR adds a config-driven
metric-name pattern → bucketsmapping so we can tune per metric without touching code.Problem
Follow-up to #64207, which set
ExponentialBucketHistogramAggregationas thedefault for every OTel
Histograminstrument. That covers timer/timing.Non-timer histograms (
*_count,*_durationon directStats.histogram(),custom
*_delaymetrics) still pick bucket boundaries at each call site,so the same family of metrics can end up with different bucket shapes
depending on which module created the instrument.
Fix
New
shared/observability/.../metrics/histogram_buckets.pymodule that:LATENCY_BUCKETS(exponential),COUNT_BUCKETS(small linear),DELAY_BUCKETS(large-range).DEFAULT_PATTERN_BUCKETSmapping*_duration/*_delay/*_countto those aggregations.build_views_for_patterns()returning OTelViewobjects keyedby instrument-name glob. Deployments can pass an override dict.
otel_logger.get_otel_logger()layers the pattern views on top of theexisting instrument-type baseline view — the per-instrument-type
exponential default still applies, the pattern views only refine it for
matching names.
Tests
test_histogram_buckets.pycovers the default pattern map, the per-patternaggregation resolution, custom-mapping override, and that
build_views_for_patterns()returns oneViewper entry with the rightinstrument_name.test_otel_logger.py::test_get_otel_logger_uses_exponential_histogram_viewupdated to assert the layered shape (baseline view + pattern views).
Design note
Flagging this as a design discussion. A reasonable counter-proposal is
"let each call site pass its bucket boundaries" rather than centralising
the map. Happy to take that direction if maintainers prefer.
Closes #66801
Reproducer
Captured before/after via the updated test
The discriminating test is
shared/observability/tests/observability/metrics/test_otel_logger.py::TestOtelMetrics::test_get_otel_logger_uses_exponential_histogram_view. It collects theviews=passed to theMeterProvider, checks the first one is the instrument-type exponential baseline, and checks the remaining views'_instrument_nameset equals{"*_count", "*_duration", "*_delay"}.Before the fix (
git checkout upstream/main -- shared/observability/src/airflow_shared/observability/metrics/otel_logger.py):The pre-fix
get_otel_loggerbuilds a single instrument-type baseline view and nothing else, soviews[1:]is empty and the pattern-name set does not match.After restoring the fix:
The full
test_histogram_buckets.pysuite plus the modifiedtest_get_otel_logger_uses_exponential_histogram_viewgo 10/10 green.End-to-end repro outside the test harness
The script below builds a
MeterProviderwithviews=build_views_for_patterns()plus anInMemoryMetricReader, emits one sample per default pattern, and reads back which aggregation the SDK resolved per instrument:Output:
task_durationis collected throughExponentialBucketHistogramAggregation(matches*_duration);schedule_delayandretry_countare collected as fixed-boundaryHistogramDataPointwith the configured(1, 5, 15, 60, 300, 900, 1800, 3600, 7200, 21600)and(1, 2, 5, 10, 25, 50, 100, 250, 500, 1000)boundaries respectively. Without the patch, all three would fall through to the instrument-type exponential default regardless of name.