Repository navigation
fix(metrics): remove cleared default dimensions from the next flush - #8916
Open
cleissonom wants to merge 2 commits into
Open
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. I reviewed the change and ran both commands below myself. The results shown come from the assistant's runs of the same commands on macOS arm64 with CPython 3.14.10 and locked dependencies.
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.uv run --locked pytest -q tests/functional/metrics/required_dependencies/test_metrics_cloudwatch_emf.py -k "removes_them_from_next_flush or keeps_dimension_added_with_another_value"gives 1 failed, 1 passed on3bb47f8, which adds only the tests todevelop(0bbc252e). The failure isassert [['environment', 'service']] == [['service']]. On5845d87, with the change, it gives 2 passed.make pron5845d87passes, with 4,359 passed and 73 skipped in the main test run and all 10 performance tests passing. ruff, markdownlint, mypy, bandit and xenon report no issues.The reporter also ran both snippets from #8899 against
5845d87: each now prints[['service']], whiledevelopstill prints[['environment', 'service']].The tests read the EMF output from stdout; nothing was sent to CloudWatch.
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.