Fix lossiness when submitting timestamped custom metrics #527
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.
What does this PR do?
Fixes an issue in
ThreadStatsWriter.flush()
whereconstant_tags
were accumulating duplicate tags over multiple Lambda invocations, leading to metric loss for metrics with timestamps. This code was the issue:Since
self.thread_stats.constant_tags
persists across multiple invocations within the same Lambda execution context, we kept appending duplicate tags after each invocation.This issue only affected metrics with a timestamp, since they use
ThreadStatsWriter
for submission. After ~12 invocations, the payloads were too large, so custom metrics were being dropped.This PR modifies the
flush()
method to still add the provided tags, but it now resetsconstant_tags
to its original state afterward.Motivation
#514
Testing Guidelines
Manual testing showed that metrics were no longer being dropped after these changes.
Added unit tests
Additional Notes
For people who are more familiar with this library, please make sure that these changes don't have any side effects that I did not consider.
Types of Changes
Check all that apply