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

(cloudwatch): GaugeWidget cannot handle nested annotations #29104

Open
fokkobucys opened this issue Feb 14, 2024 · 0 comments
Open

(cloudwatch): GaugeWidget cannot handle nested annotations #29104

fokkobucys opened this issue Feb 14, 2024 · 0 comments
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@fokkobucys
Copy link

fokkobucys commented Feb 14, 2024

Describe the bug

After the solution of #27720 for #25496, we can use annotations for GaugeWidgets. However, if we try to configure slightly more complex annotations, it seems not to be possible so far with CDK. In our use case, the target design of the GaugeWidget shall be like this:
grafik
This can be easily configured using the Management Console:
grafik
However, using the current allowed CDK code, constructs something like this:
grafik

Expected Behavior

The mentioned manual deployment via Management Console generates the following configuration for the annotation:

"annotations": {
  "horizontal": [
    {
      "color": "#d62728",
      "label": "Critical area",
      "value": 80,
      "fill": "above"
    },
    [
      {
        "color": "#f89256",
        "label": "Heavy load area",
        "value": 60
      },
      {
        "value": 80,
        "label": "Heavy load area"
      }
    ],
    {
      "color": "#2ca02c",
      "label": "Ok",
      "value": 60,
      "fill": "below"
    }
  ]
}

Hence, I'd expect that this configuration is valid in the CDK code as well. So that this will be okay:

const widget_ecs_cpu = new cw.GaugeWidget({
  title: 'CPU',
  width: 6,
  height: 6,
  leftYAxis: {
    min: 0,
    max: 100
  },
  legendPosition: cw.LegendPosition.HIDDEN,
  metrics: [ecsMetrics_cpu],
  liveData: true,
  annotations: [
    {
      color: "#d62728",
      label: 'Critical area',
      value: 80,
      fill: cw.Shading.ABOVE
    },
    [
      {
        color: "#f89256",
        label: "Heavy load area",
        value: 60
      },
      {
        value: 80,
        label: "Heavy load area"
      }
    ],
    {
      color: "#2ca02c",
      label: "OK",
      value: 60,
      fill: cw.Shading.BELOW
    }
  ]
});

Current Behavior

The actual problem is that the CDK does not support subordinated lists of annotations in the annotations list although this is accepted by CloudWatch itself. Trying this leads to the following syntax error:
grafik
Placing the annotations like this:

const widget_ecs_docGeneration_cpu = new cw.GaugeWidget({
  title: 'DocGen CPU',
  width: 6,
  height: 6,
  leftYAxis: {
    min: 0,
    max: 100
  },
  legendPosition: cw.LegendPosition.HIDDEN,
  metrics: [ecsMetrics_documentGeneration_cpu],
  liveData: true,
  annotations: [
    {
      color: "#d62728",
      label: 'Critical area',
      value: 80,
      fill: cw.Shading.ABOVE
    },
    {
      color: "#f89256",
      label: "Heavy load area",
      value: 60
    },
    {
      color: "#f89256",
      value: 80,
      label: "Heavy load area"
    },
    {
      color: "#2ca02c",
      label: "OK",
      value: 60,
      fill: cw.Shading.BELOW
    }
  ]
});

solves the syntax error but leads to the wrong display in the CloudWatch Dashboard as described above.

Reproduction Steps

This can be reproduced by using the above provided code snippets. The GaugeWidget needs a metric and a Dashboard where it is included.

Possible Solution

I think this might be quite straightforward as the allowed elements in the annotations array should not only be of type HorizontalAnnotation but also allow arrays of HorizontalAnnotations to reflect at least this special use case. At the moment I'm not aware of other formats of horizontal annotation allowed by CloudWatch.

Additional Information/Context

No response

CDK CLI Version

2.117.0

Framework Version

2.117.0

Node.js Version

v18.17.1

OS

Windows 11

Language

TypeScript

Language Version

TypeScript 4.9.5

Other information

We also tried raising the CDK library to the newest 2.127.0. This leads to the same behavior.

@fokkobucys fokkobucys added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch label Feb 14, 2024
@pahud pahud added feature-request A feature should be added or improved. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants