cdklabs / cdk-monitoring-constructs

Easy-to-use CDK constructs for monitoring your AWS infrastructure
https://constructs.dev/packages/cdk-monitoring-constructs
Apache License 2.0
443 stars 55 forks source link

Graph Annotations Do Not Work With CloudWatch Dynamic Lables #493

Open JCKortlang opened 5 months ago

JCKortlang commented 5 months ago

Version

7.6.0

Steps and/or minimal code example to reproduce

    public static MonitoringFacade MonitorApplicationLoadBalancer(this MonitoringFacade monitoringFacade, ApplicationLoadBalancer alb, string region = "us-west-2")
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(region, nameof(region));
        var albDimensions = new Dictionary<string, string>
        {
            { "LoadBalancer", alb.LoadBalancerFullName}
        };
       //Note that the label inclucdes CloudWatch dynamic lables -- https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html
        var target5xx = (Metric) metricFactory.CreateMetric("HTTPCode_Target_5XX_Count", MetricStatistic.SUM, "${LABEL} [avg: ${AVG}, min: ${MIN}, max: ${MAX}]", albDimensions, default, AwsAlbNamespace);
        var target5xxMetricWithAlarm = new CustomMetricWithAlarm
        {
            AddAlarm = new Dictionary<string, ICustomThreshold>
            {
                { "critical", new CustomThreshold
                    {
                        Threshold = 1,
                        ComparisonOperator = ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
                        //We do not have sufficient traffic to treat as breaching
                        TreatMissingDataOverride = TreatMissingData.NOT_BREACHING
                    }
                }
            },
            AlarmFriendlyName = "5xx-alarm",
            Metric = target5xx
        };

        return monitoringFacade
            .MonitorCustom(new CustomMonitoringProps
            {
                //Each "CustomMetricGroup" is a CloudWatch graph. Each graph is composed of [1..n] metrics
                MetricGroups =
                [
                    new CustomMetricGroup
                    {
                        Metrics = [target5xxMetricWithAlarm],
                        Title = "HTTP 5XXs"
                    },
                ],
                AlarmFriendlyName = "alb",
                HumanReadableName = $"Application Load Balancer [{alb.LoadBalancerName}](https://{region}.console.aws.amazon.com/ec2/home?region={region}#LoadBalancer:loadBalancerArn={alb.LoadBalancerArn})"
            });
    }

Note that the output graph annotations contains the dynamic label placeholders.

derp

Expected behavior

Expect that the output annotation does not contain the dynamic labels. e.g. Contains the metric and thresholds being monitored.

e.g. "HTTPCode_Target_5XX_Count > 1 for 5 minutes"

Actual behavior

The output annotation contains the dynamic labels placeholders. .e.g "${LABEL} [avg: ${AVG}, min: ${MIN}, max: ${MAX}]"

derp

Other details

See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html