@@ -14,10 +14,12 @@ import { Construct } from "constructs";
1414
1515import {
1616 AddAlarmProps ,
17+ AlarmActionStrategyProps ,
1718 AlarmFactory ,
1819 AlarmFactoryDefaults ,
1920 AlarmNamingInput ,
2021 CompositeAlarmOperator ,
22+ IAlarmActionStrategy ,
2123 IAlarmNamingStrategy ,
2224 MetricFactoryDefaults ,
2325 MetricStatistic ,
@@ -32,6 +34,16 @@ const construct = new Construct(stack, "SampleConstruct");
3234const snsAction = new SnsAlarmActionStrategy ( {
3335 onAlarmTopic : new Topic ( stack , "Dummy2" ) ,
3436} ) ;
37+
38+ class SampleAlarmActionStrategy implements IAlarmActionStrategy {
39+ readonly prop = "Sample" ;
40+
41+ addAlarmActions ( _props : AlarmActionStrategyProps ) : void {
42+ // No-op
43+ }
44+ }
45+ const sampleAction = new SampleAlarmActionStrategy ( ) ;
46+
3547const globalMetricDefaults : MetricFactoryDefaults = {
3648 namespace : "DummyNamespace" ,
3749} ;
@@ -722,11 +734,18 @@ test("addAlarm: custom alarm naming strategy", () => {
722734 const disambiguator = "Critical" ;
723735 const stack = new Stack ( ) ;
724736 const customNamingStrategy : IAlarmNamingStrategy = {
725- getName : ( props : AlarmNamingInput ) => `${ alarmName } -${ props . disambiguator } ` ,
737+ getName : ( props : AlarmNamingInput ) =>
738+ `${ alarmName } -${ props . disambiguator } -${
739+ ( props . action as SampleAlarmActionStrategy ) . prop
740+ } `,
726741 getWidgetLabel : ( props : AlarmNamingInput ) =>
727- `${ alarmLabel } -${ props . disambiguator } ` ,
742+ `${ alarmLabel } -${ props . disambiguator } -${
743+ ( props . action as SampleAlarmActionStrategy ) . prop
744+ } `,
728745 getDedupeString : ( props : AlarmNamingInput ) =>
729- `${ alarmDedupe } -${ props . disambiguator } ` ,
746+ `${ alarmDedupe } -${ props . disambiguator } -${
747+ ( props . action as SampleAlarmActionStrategy ) . prop
748+ } `,
730749 } ;
731750 const factory = new AlarmFactory ( stack , {
732751 globalMetricDefaults,
@@ -736,13 +755,15 @@ test("addAlarm: custom alarm naming strategy", () => {
736755 } ,
737756 localAlarmNamePrefix : "prefix" ,
738757 } ) ;
758+ const action = sampleAction ;
739759 const alarm = factory . addAlarm ( metric , {
740760 ...props ,
741761 disambiguator,
762+ actionOverride : action ,
742763 } ) ;
743- expect ( alarm . alarmName ) . toBe ( `${ alarmName } -${ disambiguator } ` ) ;
744- expect ( alarm . alarmLabel ) . toBe ( `${ alarmLabel } -${ disambiguator } ` ) ;
745- expect ( alarm . dedupeString ) . toBe ( `${ alarmDedupe } -${ disambiguator } ` ) ;
764+ expect ( alarm . alarmName ) . toBe ( `${ alarmName } -${ disambiguator } -Sample ` ) ;
765+ expect ( alarm . alarmLabel ) . toBe ( `${ alarmLabel } -${ disambiguator } -Sample ` ) ;
766+ expect ( alarm . dedupeString ) . toBe ( `${ alarmDedupe } -${ disambiguator } -Sample ` ) ;
746767} ) ;
747768
748769test ( "addAlarm: custom metric adjuster, applies it and DefaultMetricAdjuster after it" , ( ) => {
0 commit comments