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: Add CDK support for 'Persistent Time Range' feature already present on CW Dashboards UI #26216

Closed
2 tasks done
hot9cups opened this issue Jul 4, 2023 · 8 comments
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@hot9cups
Copy link

hot9cups commented Jul 4, 2023

Describe the feature

Hello,
I recently read about this feature for persisting time ranges for Cloudwatch dashboard widgets, where you can pick specific time periods for different widgets and not have it be overriden regardless of the Dashboard period.

Specifically, I’m talking about "Persist time range" mentioned in here - https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/edit_graph_dashboard.html

I've come to understand this was a fairly recent addition to the UI.

I wanted to make use of this feature for the Cloudwatch dashboards I create using CDK.
I tried looking at documentation, I checked out for example the GraphWidget class since that’s what we’re using but I couldn't seem to find much there - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.GraphWidget.html

I looked at the source code on the CW Dashboards UI for a persisted time range widget, here is a sample:

{
    "height": 6,
    "width": 12,
    "y": 20,
    "x": 12,
    "type": "metric",
    "properties": {
        "view": "timeSeries",
        "title": "Lambda Throttles",
        "region": "us-east-1",
        "metrics": [
            [ "AWS/Lambda", "Throttles", "FunctionName", "MyServiceLambda", { "stat": "Sum" } ]
        ],
        "yAxis": {
            "left": {
                "label": "",
                "showUnits": false
            }
        },
        "start": "-P50D"
    }
},

And I observed the only part that was additionally present, that wasn't there in 'normal' widgets was the "start": "-P50D" part which was helping the widget maintain the persisted time range of 50 days I wanted it to.

I was able to find a 'hacky' workaround(described below) to add this 'start' field to my dashboard widgets in my CDK Code, but it would be very helpful to everyone if CDK provides an out-of-the-box function for defining the start field for dashboard widgets, to support persisted-time-range functionality not just through UI but also through CDK.

Use Case

To support persisted-time-range functionality not just through UI but also through CDK, it would be very helpful to everyone if CDK provides an out-of-the-box function for defining the start field for dashboard widgets.

Proposed Solution

Firstly, I'd like to describe the hacky workaround I used to achieve this effect through CDK, to help understand my proposed solution.

I extended the GraphWidget class that CDK provides, and basically augmented it with a 'start' field. Here's the class:

import {GraphWidget} from "aws-cdk-lib/aws-cloudwatch";
import {GraphWidgetProps} from "aws-cdk-lib/aws-cloudwatch/lib/graph";

export default class CustomGraphWidget extends GraphWidget {
  readonly start?: string;

  constructor(props: GraphWidgetProps, start?: string, end?: string) {
    super(props);
    this.start = start;
  }

  toJson(): any[] {
    let json = super.toJson()[0];
    json.properties.start = this.start;
    return [json];
  }
}

and then it was just a matter of using an instance of the CustomGraphWidget class I wrote above to populate my CW dashboard in CDK.

My proposal is to have an additional field added to the GraphWidget class, start that lets the user define the start period if they'd like.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

V2

Environment details (OS name and version, etc.)

MacOS Montery - 12.6.6

@hot9cups hot9cups added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 4, 2023
@github-actions github-actions bot added the @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch label Jul 4, 2023
@pahud
Copy link
Contributor

pahud commented Jul 5, 2023

Makes sense to me though I am not sure if we should call it start but welcome to submit the PR if it's ready.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2023
@hot9cups
Copy link
Author

Thanks for the response.

Well I called it start because that's what it's referred to in the CW Widget Json..

Sure, let me try and get a PR up soon once I have the environment setup.

@benapie
Copy link

benapie commented Aug 7, 2023

Is there any update on this? 👀

Also: you can also provide end in the CW dashboard JSON for a graph widget. The intention to add end as well as start was alluded to in the sample code you shared, but I would like to explicitly state that this PR should include both of these.

@hot9cups
Copy link
Author

hot9cups commented Aug 9, 2023

Ill get back with an update this weekend, I had trouble setting up the dev environment locally.

@hot9cups
Copy link
Author

Issues with Dev-env, posted here

@hot9cups
Copy link
Author

Posted another update highlighting my latest blocker - here

@benapie
Copy link

benapie commented Oct 2, 2023

I believe this work has been done here

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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 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

3 participants