Repository navigation
fix(metrics): remove cleared default dimensions from the next flush - #8916
Draft
cleissonom wants to merge 2 commits into
Draft
cleissonom wants to merge 2 commits into
cleissonom wants to merge 2 commits into
Conversation
|
This branch has not been deployed
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.



Issue number:
closes #8899
Summary
Changes
set_default_dimensions()also adds each default to the provider'sdimension_set, which holds the dimensions for the next flush.clear_default_dimensions()only emptieddefault_dimensions, so the next flush still carried the cleared dimensions.clear_metrics()stages the defaults again after each flush, so the testing example, which calls it beforeclear_default_dimensions(), leaked them too.Metrics.clear_default_dimensions()now removes each default fromdimension_setwhile it still holds the default value, as suggested in the issue. A dimension thatadd_dimension()set to another value after the default is kept; one set to the same value is removed. The change stays inMetricsbecauseAmazonCloudWatchEMFProvider, exported asEphemeralMetrics, has noclear_default_dimensions(), and adding one would be new public API. Dimension sets created earlier withadd_dimensions()keep the defaults they copied. I can extend the change to them if you prefer.User experience
set_default_dimensions(environment="dev"),clear_default_dimensions(),add_metric(...), flush"Dimensions": [["environment", "service"]]and"environment": "dev""Dimensions": [["service"]]set_default_dimensions(tenant="a"),add_metric(...),clear_default_dimensions(), flush"Dimensions": [["tenant", "service"]]"Dimensions": [["service"]]Both rows change the output. ADR 0006 allows that for a bug fix the PR calls out: the docs say
clear_default_dimensions()removes the defaults, with no exception for metrics that haven't been flushed yet. Dimensions apply to the whole flush, which is why the second row changes too. For a dimension that belongs to a single flush,add_dimension()is the method to use. Flushes after the first one were already correct.Verification
I used an AI coding assistant to write the change, the tests and this description. It ran the checks below; I'll repeat them myself before marking this ready for review.
test_clear_default_dimensions_removes_them_from_next_flushsets a default, clears it, flushes a metric and checks the emitted dimensions. The existingtest_clear_default_dimensionsonly checks the dictionary, so it passed with the bug; it is unchanged.test_clear_default_dimensions_keeps_dimension_added_with_another_valuecovers the value check.On macOS arm64 with CPython 3.14.10 and locked dependencies,
uv run --locked pytest --disable-socket -q tests/functional/metrics/required_dependencies/test_metrics_cloudwatch_emf.py -k "removes_them_from_next_flush or keeps_dimension_added_with_another_value"gave 1 failed, 1 passed ondevelop(0bbc252e) with only the tests added ([['environment', 'service']] == [['service']]), and 2 passed with the change.[['service']]instead of[['environment', 'service']].make prwithoutlint-docs, which needs Docker (no Markdown changed): ruff, mypy, bandit, xenon and pre-commit pass, with 4,359 passed and 73 skipped. Two timing-based tests,test_data_masking_encrypt_with_json_blobandtest_tracer_init, failed on import-time limits in every run on this branch, and ondeveloptoo, while the machine was under heavy load.The tests read the EMF output from stdout; nothing was sent to CloudWatch. Until a maintainer triages #8899, this stays a draft.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.