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

@aws-cdk/cloudwatch: bugfixes, small changes changes and workaround #194

Merged
merged 2 commits into from
Jul 2, 2018

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jun 29, 2018

  • bugfix: label/color were ignored when passed directly to the Metric
    constructor.
  • BREAKING CHANGE: ChangeMetricProps renamed to MetricCustomizations.
  • change: onAlarm()/onOk() now take variadic arguments
  • workaround: generate a dashboard name if user did not supply one.
    This fixes Handle DashboardName missing in CloudWatch #192.

By submitting this pull request, I confirm that my contribution is made under
the terms of the beta license.

- bugfix: label/color were ignored when passed directly to the Metric
  constructor.
- BREAKING CHANGE: ChangeMetricProps renamed to MetricCustomizations.
- change: onAlarm()/onOk() now take variadic arguments
- workaround: generate a dashboard name if user did not supply one.
  This fixes #192.
@rix0rrr rix0rrr requested review from RomainMuller and eladb June 29, 2018 09:48
@@ -175,38 +175,38 @@ export class Alarm extends Construct {
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public onAlarm(action: IAlarmAction) {
public onAlarm(...actions: IAlarmAction[]) {
if (this.alarmActions === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this can happen, since it's a variadic method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're thinking of the parameter. This is about the instance member.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 🤦🏻‍♂️

}

/**
* Trigger this action if there is insufficient data to evaluate the alarm
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public onInsufficientData(action: IAlarmAction) {
public onInsufficientData(...actions: IAlarmAction[]) {
if (this.insufficientDataActions === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}

/**
* Trigger this action if the alarm returns from breaching state into ok state
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public onOk(action: IAlarmAction) {
public onOk(...actions: IAlarmAction[]) {
if (this.okActions === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also here

// WORKAROUND -- Dashboard cannot be updated if the DashboardName is missing.
// This is a bug in CloudFormation, but we don't want CDK users to have a bad
// experience. We'll generate a name here if you did not supply one.
const dashboardName = (props && props.dashboardName) || this.generateDashboardName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make dashboard naming mandatory? It's one of those things that are expressly targeting human interactions, so I think it's reasonable to target an optimum console experience here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that as well, but the rationale is to not make it required for all intermediate constructs that might contain the dashboard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I would expect the Construct to have a dashboardName input of some sort. But okay I get your point.

*/
private generateDashboardName(): string {
// This will include the Stack name and is hence unique
return this.path.replace('/', '-');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above comment about making the name required in props stands even more true here as:

  1. This will not be a console-friendly string
  2. This might very well be longer than the maximum dashboard name size (255 characters)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be. Unlikely though, and in that case you can still pass a proper name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless someone hid it somewhere in their construct and gave you no way to name it yourself?

@@ -21,8 +21,13 @@ export class Dashboard extends Construct {
constructor(parent: Construct, name: string, props?: DashboardProps) {
super(parent, name);

// WORKAROUND -- Dashboard cannot be updated if the DashboardName is missing.
// This is a bug in CloudFormation, but we don't want CDK users to have a bad
// experience. We'll generate a name here if you did not supply one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue to track the fix and revert the workaround (and reference from here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
private generateDashboardName(): string {
// This will include the Stack name and is hence unique
return this.path.replace('/', '-');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do dashboard names have a length limit? Path can be quite long. I would use the the logical ID we generate for the resource prefixed by the stack name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't. That id is only available after the DashboardResource is created, at which point the dashboardName is locked in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Token?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course. It's going to be ugly, but I guess...

*/
public toAlarmJson(): MetricAlarmJson {
public alarmInfo(): AlarmMetricInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just AlarmMetric? Whenever I see "Info" in the name of a class I die a little from the inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know.

The reason I'm dancing around it is because it's a fraction of the structure required to represent an Alarm. An AlarmMetric is not really a concept that we have, this is half of the properties of AlarmResourceProps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be a public API? If there's a way to hide it, name is not that critical.

Another option is to move this logic be part of Alarm instead of the Metric. The metric should be able to expose all this info for the Alarm to be able to use it (and not vice versa).

@@ -295,7 +304,7 @@ export enum Unit {
/**
* Properties of a metric that can be changed
*/
export interface ChangeMetricProps {
export interface MetricCustomizations {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use singular form MetricCustomization

@@ -94,6 +94,22 @@ export = {

test.done();
},

'work around CloudFormation bug'(test: Test) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure issue is referenced here as well

@rix0rrr rix0rrr merged commit 507f778 into master Jul 2, 2018
@rix0rrr rix0rrr deleted the huijbers/cloudwatch-updates branch July 2, 2018 09:28
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle DashboardName missing in CloudWatch
4 participants