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: Allow non-integral latency thresholds and durations #587

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/common/monitoring/alarms/LatencyAlarmFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class LatencyAlarmFactory {
ComparisonOperator.GREATER_THAN_THRESHOLD,
...props,
disambiguator,
threshold: props.maxLatency.toMilliseconds(),
threshold: props.maxLatency.toMilliseconds({ integral: false }),
alarmNameSuffix,
// we will dedupe any kind of latency issue to the same ticket
alarmDedupeStringSuffix: this.alarmFactory
Expand Down Expand Up @@ -200,7 +200,7 @@ export class LatencyAlarmFactory {
ComparisonOperator.GREATER_THAN_THRESHOLD,
...props,
disambiguator,
threshold: props.maxLatency.toMilliseconds(),
threshold: props.maxLatency.toMilliseconds({ integral: false }),
alarmNameSuffix,
// we will dedupe any kind of latency issue to the same alarm
alarmDedupeStringSuffix: this.alarmFactory
Expand Down Expand Up @@ -230,7 +230,7 @@ export class LatencyAlarmFactory {
ComparisonOperator.GREATER_THAN_THRESHOLD,
...props,
disambiguator,
threshold: props.maxDuration.toMilliseconds(),
threshold: props.maxDuration.toMilliseconds({ integral: false }),
alarmNameSuffix,
// we will dedupe any kind of latency issue to the same ticket
alarmDedupeStringSuffix: this.alarmFactory
Expand Down Expand Up @@ -264,7 +264,7 @@ export class LatencyAlarmFactory {
ComparisonOperator.GREATER_THAN_THRESHOLD,
...props,
disambiguator,
threshold: props.maxDuration.toMilliseconds(),
threshold: props.maxDuration.toMilliseconds({ integral: false }),
alarmNameSuffix,
// we will dedupe any kind of latency issue to the same ticket
alarmDedupeStringSuffix: this.alarmFactory
Expand Down
67 changes: 67 additions & 0 deletions test/common/alarm/LatencyAlarmFactory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Duration, Stack } from "aws-cdk-lib";
import { Metric } from "aws-cdk-lib/aws-cloudwatch";
import { Construct } from "constructs";

import {
AlarmFactory,
AlarmFactoryDefaults,
LatencyAlarmFactory,
LatencyType,
MetricFactoryDefaults,
noopAction,
} from "../../../lib";

const stack = new Stack();
const construct = new Construct(stack, "SampleConstruct");

const globalMetricDefaults: MetricFactoryDefaults = {
namespace: "DummyNamespace",
};
const globalAlarmDefaults: AlarmFactoryDefaults = {
alarmNamePrefix: "DummyServiceAlarms",
actionsEnabled: true,
datapointsToAlarm: 6,
// we do not care about alarm actions in this test
action: noopAction(),
};
const factory = new AlarmFactory(construct, {
globalMetricDefaults,
globalAlarmDefaults,
localAlarmNamePrefix: "prefix",
});

const metric = new Metric({
metricName: "DummyMetric1",
namespace: "DummyCustomNamespace",
dimensionsMap: { CustomDimension: "CustomDimensionValue" },
});

const latencyAlarmFactory = new LatencyAlarmFactory(factory);

test("addLatencyAlarm: non-integral millisecond thresholds do not throw error", () => {
latencyAlarmFactory.addLatencyAlarm(metric, LatencyType.P99, {
maxLatency: Duration.millis(0.5),
});
});

test("addIntegrationLatencyAlarm: non-integral millisecond thresholds do not throw error", () => {
latencyAlarmFactory.addIntegrationLatencyAlarm(metric, LatencyType.P99, {
maxLatency: Duration.millis(2.5),
});
});

test("addDurationAlarm: non-integral millisecond durations do not throw error", () => {
latencyAlarmFactory.addDurationAlarm(metric, LatencyType.P99, {
maxDuration: Duration.millis(0.5),
});
});

test("addJvmGarbageCollectionDurationAlarm: non-integral millisecond durations do not throw error", () => {
latencyAlarmFactory.addJvmGarbageCollectionDurationAlarm(
metric,
LatencyType.P99,
{
maxDuration: Duration.millis(2.5),
},
);
});