Open PatrykMilewski opened 1 year ago
@PatrykMilewski, I'm finding that when I call monitoring.monitorScope
on a Stack
, no alarms are created (and not returned) but they are added to the dashboard. Have you experience this behavior? Or is your only issue that the alarms aren't being returned? Could you provide example code?
From my experience they are created but not returned
Looking into this, it seems to be due to the nature of Aspect
s running during the prepare stage, and can be reproduced in a simple test like:
test("ACM", () => {
// GIVEN
const stack = new Stack();
const facade = createDummyMonitoringFacade(stack);
new acm.Certificate(stack, "DummyCertificate", {
domainName: "www.monitoring.cdk",
});
// WHEN
facade.monitorScope(stack, {
...defaultAspectProps,
acm: {
props: {
addDaysToExpiryAlarm: {
Warning: {
minDaysToExpiry: 14,
},
},
},
},
});
// THEN
expect(Template.fromStack(stack)).toMatchSnapshot();
// If this happens before the previous line that synths it, it fails
expect(facade.createdAlarms()).toHaveLength(1);
});
I'm not actually sure if there's a great way to handle that. @ayush987goyal Not sure if you have any ideas?
I will say this absence of functionality has been very frustrating. I felt like I was going insane. The AlarmActionStrategy pattern appears to be useless as far as I can tell.
My work around is to use the same Aspect
API to add the AlarmActions.
//Workaround to add Alarm actions generated by .monitorScope(...)
public class AlarmActionAspect : DeputyBase, IAspect
{
public void Visit(IConstruct node)
{
if (node is AlarmBase alarmBase)
{
alarmBase.AddAlarmAction(...); //Your alarm action
}
}
}
//Assuming a nested stack scope
var monitoringNestedStack = ...
//Configure Facade
monitoringNestedStack.monitoringFacade
.monitorScope(this, ....);
//Use aspect to add alarm actions
Aspects.Of(monitoringNestedStack).Add(new AlarmActionAspect());
Version
3.0.0
Steps and/or minimal code example to reproduce
monitoring.monitorScope(stack, { lambda: { props: <add some alarms here> }}
monitoring.monitorGlueJob( <config> )
monitoring.createdAlarms()
monitoring.monitorGlueJob( <config> )
Expected behavior
All of created alarms should be returned
Actual behavior
It doesn't return alarms created with
monitorScope
functionOther details
No response