Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent a single metric have more than 100 data points #312

Merged

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Jun 22, 2023

Please provide the issue number

Issue number: #311

Summary

Serialize and flush metric data set when a single metric reaches 100 data points.
Throw exception when adding a metric with 100 data points.
Dimensions etc should be kept intact.

Changes

Please provide a summary of what's being changed

Check if single metrics has more than 100 datapoints and flush.
Add tests to check first and second metrics flush.

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

…ests to check first and second metrics flush.
@boring-cyborg boring-cyborg bot added area/metrics Core metrics utility tests labels Jun 22, 2023
@auto-assign auto-assign bot requested review from amirkaws and sliedig June 22, 2023 12:06
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 22, 2023
@github-actions github-actions bot added the bug Unexpected, reproducible and unintended software behaviour label Jun 22, 2023
@hjgraca hjgraca linked an issue Jun 22, 2023 that may be closed by this pull request
@hjgraca
Copy link
Contributor Author

hjgraca commented Jun 22, 2023

cc @leandrodamascena

{
if(metric.Values.Count < PowertoolsConfigurations.MaxMetrics)
metric.AddValue(value);
else
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we will ever be in this situation (it only accepts one double not an array) but added the throwing exception for consistency with the bellow throw


if (i == 100)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make sure and test that the first flush would happen and what are the values

# Conflicts:
#	libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricDirective.cs
@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: +0.04 🎉

Comparison is base (6298b82) 69.14% compared to head (546caaa) 69.19%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #312      +/-   ##
===========================================
+ Coverage    69.14%   69.19%   +0.04%     
===========================================
  Files           79       79              
  Lines         3452     3464      +12     
===========================================
+ Hits          2387     2397      +10     
- Misses        1065     1067       +2     
Flag Coverage Δ
unittests 69.19% <80.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...Lambda.Powertools.Metrics/Model/MetricDirective.cs 85.26% <57.14%> (-1.41%) ⬇️
...aries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs 85.81% <100.00%> (+0.74%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@amirkaws amirkaws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes to use PowertoolsConfigurations.MaxMetrics instead of hardcoded value of 100.


if (_context.GetMetrics().Count == 100) _instance.Flush(true);

if (_context.GetMetrics().Count > 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a variable var metrics = _context.GetMetrics(); instead of calling methods multiple times

@@ -140,20 +140,75 @@ public void When100MetricsAreAdded_FlushAutomatically()
for (var i = 0; i <= 100; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the config value instead of hard code

for (var i = 0; i <= PowertoolsConfigurations.MaxMetrics; i++)


if (i == 100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the config value instead of hard code

if (i == PowertoolsConfigurations.MaxMetrics)

Copy link
Contributor

@amirkaws amirkaws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@amirkaws amirkaws merged commit 0ca1252 into aws-powertools:develop Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/metrics Core metrics utility bug Unexpected, reproducible and unintended software behaviour size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
Status: 🚀 Shipped
Development

Successfully merging this pull request may close these issues.

Bug: Prevent a single metric have more than 100 data points
3 participants