aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.5k stars 3.84k forks source link

synthetics: alarm for the metric not linked in the console #24387

Closed npvisual closed 1 year ago

npvisual commented 1 year ago

Describe the bug

I have created a canary synthetic : simple heartbeat monitoring. I have then linked this canary to a new alarm that is sending notifications to a SNS topic.

Everything works as expected : canary is all setup and alarm will send a notification to the topic when the endpoint is failing.

However I am not seeing the alarm in the console under the canary configuration

Screenshot 2023-02-28 at 5 41 12 PM

However if I create this via the console, I see the alarm in that configuration screen (note it's different base : using nodejs) :

Screenshot 2023-02-28 at 5 43 30 PM

This is pretty convenient because it links the canary to its alarm. Is there something I am missing that would allow the alarm to be displayed in the configuration screen of the canary ?

Expected Behavior

I would expect to see the canary in the console (so maybe I am missing a step ?).

Screenshot 2023-02-28 at 5 43 30 PM

Current Behavior

See illustration below and description above :

Screenshot 2023-02-28 at 5 41 12 PM

Reproduction Steps

Here's the code snippet I am using (python) :

                canary = synthetics.Canary(
                    self,
                    f"{tenant_name}-hb",
                    canary_name=f"{tenant_name}-hb",
                    schedule=synthetics.Schedule.rate(
                        Duration.minutes(tenant_canaryhb_schedule)
                    ),
                    runtime=synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_3,
                    environment_variables={"url": tenant_url},
                    enable_auto_delete_lambdas=True,
                    test=synthetics.Test.custom(
                        code=synthetics.Code.from_asset(
                            path.join(path.dirname(__file__), "./canary")
                        ),
                        handler="index.handler",
                    ),
                )
                topic = Fn.import_value("PodTopicDevopsArn")
                if topic:
                    sns_topic = sns.Topic.from_topic_arn(
                        self,
                        f"{tenant_name}-snstopic",
                        topic_arn=topic,
                    )
                    alarm = cloudwatch.Alarm(
                        self,
                        f"{tenant_name}-hb-alarm",
                        metric=canary.metric_success_percent(),
                        threshold=tenant_canaryhb_treshold,
                        comparison_operator=cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
                        evaluation_periods=tenant_canaryhb_period,
                        alarm_name=f"{tenant_name}-hb-alarm",
                        alarm_description=f"Hearbeat monitoring for {tenant_name}",
                    )
                    alarm.add_alarm_action(actions.SnsAction(sns_topic))

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.66.1 (build 539d036)

Framework Version

"aws-cdk-lib" = "2.66..1"

Node.js Version

whatever is installed as part of synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_3

OS

whatever is used for synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_3

Language

Python

Language Version

3.9 I guess (installed base for synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_1_3)

Other information

No response

pahud commented 1 year ago

Hi

I noticed the alarm created from the console will be in the CloudWatchSynthetics namespace. Maybe you can specify this namespace for your alarm created with CDK?

image
github-actions[bot] commented 1 year ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

npvisual commented 1 year ago

@pahud : thanks for the suggestion.

I looked at the alarm that was created as part of the CDK stack and it seems to already have the proper Namespace :

Screenshot 2023-03-09 at 1 20 44 PM

But it's still not showing up linked under the Canary configuration page.

sujee81 commented 1 year ago

Hi @npvisual I had the same issue and upon further investigation found out from here that the alarm name should be named "Synthetics-Alarm-canary_name" to make it appears in the Canary console. Hope it helps.

good92 commented 10 months ago

@sujee81 Thanks, it solved my issue in Terraform configuration.

resource "aws_cloudwatch_metric_alarm" "canary_alarm" {
  # alarm_name                          = "${local.name_prefix}-synthetics-canary-endpoint" # Synthetics-Alarm-canary_name
  alarm_name                            = "Synthetics-Alarm-${aws_synthetics_canary.canary_api_calls.name}" # https://github.com/aws/aws-cdk/issues/24387