Skip to content

Commit

Permalink
fix(alarm): use adjustedMetric's period when using minSampleCountToEv…
Browse files Browse the repository at this point in the history
…aluateDatapoint
  • Loading branch information
miloszwatroba committed Nov 15, 2023
1 parent f1dd4a3 commit 89ded46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/common/alarm/AlarmFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export class AlarmFactory {
alarmMetric = new MathExpression({
label: `${adjustedMetric}`,
expression: `IF(sampleCount > ${props.minSampleCountToEvaluateDatapoint}, metric)`,
period: adjustedMetric.period,
usingMetrics: {
metric: adjustedMetric,
sampleCount: metricSampleCount,
Expand Down
8 changes: 6 additions & 2 deletions test/common/alarm/AlarmFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,15 @@ test("addAlarm: check created alarms when minMetricSamplesToAlarm is used", () =
alarmNameSuffix: "none",
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
minMetricSamplesToAlarm: 42,
period: Duration.minutes(15),
});

const template = Template.fromStack(stack);
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
AlarmName: "DummyServiceAlarms-prefix-none",
MetricName: "DummyMetric1",
Statistic: "Average",
Period: 900,
});
template.hasResourceProperties("AWS::CloudWatch::Alarm", {
AlarmName: "DummyServiceAlarms-prefix-none-NoSamples",
Expand All @@ -304,6 +306,7 @@ test("addAlarm: check created alarms when minMetricSamplesToAlarm is used", () =
Statistic: "SampleCount",
Threshold: 42,
TreatMissingData: "breaching",
Period: 900,
});

const alarmRuleCapture = new Capture();
Expand Down Expand Up @@ -344,6 +347,7 @@ test("addAlarm: check created alarms when minSampleCountToEvaluateDatapoint is u
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
minSampleCountToEvaluateDatapoint: 42,
minMetricSamplesToAlarm: 55, // not used if minSampleCountToEvaluateDatapoint defined
period: Duration.minutes(15),
});

const template = Template.fromStack(stack);
Expand All @@ -365,7 +369,7 @@ test("addAlarm: check created alarms when minSampleCountToEvaluateDatapoint is u
Metric: Match.objectLike({
MetricName: "DummyMetric1",
}),
Period: 300,
Period: 900,
Stat: "Average",
},
ReturnData: false,
Expand All @@ -376,7 +380,7 @@ test("addAlarm: check created alarms when minSampleCountToEvaluateDatapoint is u
Metric: Match.objectLike({
MetricName: "DummyMetric1",
}),
Period: 300,
Period: 900,
Stat: "SampleCount",
},
ReturnData: false,
Expand Down

0 comments on commit 89ded46

Please sign in to comment.