Repository navigation
fix(aws-cloudwatch): validate metric Period on GetMetricData and GetMetricStatistics - #1703
Merged
Merged
Conversation
…etricStatistics An invalid or huge Period overflowed the bucket step and crashed the server with a divide by zero. Period now follows the AWS rule and returns InvalidParameterValue, buckets are counted in int64 seconds, and the math alarm lookback check no longer overflows.
Satyam-Trivedi-ZS
added a commit
to Satyam-Trivedi-ZS/cloudemu
that referenced
this pull request
Oct 24, 2026
…verflow-safe A SEARCH period argument past the time.Duration range made the FILL grid step wrap negative (endless loop) or to exactly zero (divide by zero). - SEARCH's period argument now follows the MetricStat Period rule (1, 5, 10, 20, 30 or a multiple of 60, up to the Integer maximum), checked on the float before the int conversion. The rule moves to metricmath.ValidPeriod and the provider's ValidatePeriod from stackshy#1703 uses it, so there is a single definition. - GetMetricData rejects such an expression with a ValidationError ("Error in expression 'e1': Invalid SEARCH period. ..."). - The FILL grid counts in whole seconds and never turns the period itself into a Duration, so it ends for any period, including an entry Period passed by a library caller. - Arithmetic over a SEARCH keeps the SEARCH period, so FILL around it fills every period when the query sets no Period. - The arithmetic wire test now checks every expected row comes back.
6 of 10 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.
GetMetricData never validated the Period of a MetricStat or MetricDataQuery, and GetMetricStatistics never validated its Period. A huge Period overflowed
time.Duration(p) * time.Second. A zero step panicked with a divide by zero, and a negative step produced garbage buckets. For example, a MetricStat Period of 540431955284459520 is a multiple of 60 that wraps to a zero step.Changes:
ValidatePeriod, which applies the AWS rule from the MetricStat, MetricDataQuery and GetMetricStatistics references. Period is at least 1 and fits an Integer. Valid values are 1, 5, 10, 20, 30, 60 or any multiple of 60. An invalid value returns InvalidArgument with an AWS-style message that names the parameter, for exampleMetricDataQueries.member.1.MetricStat.Period.GetMetricDatarejects any non-zero invalid Period. Zero still means the one-minute default for library callers. Buckets are counted in int64 seconds, and a non-positive step returns no points.Verified with:
cloudemu serve: the huge, zero, negative and 61 periods return InvalidParameterValue, and a valid query returns its data.aws_cloudwatch_metric_alarm(single-metric and metric math) applies, plans with no changes and destroys cleanly.Closes #1701