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

fix(cloudwatch): correct CompositeAlarm.fromCompositeAlarmName ARN format #24604

Merged
merged 6 commits into from
Apr 17, 2023

Conversation

nakedible-p
Copy link
Contributor

@nakedible-p nakedible-p commented Mar 13, 2023

Fixes #24594.

@github-actions github-actions bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Mar 13, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team March 13, 2023 20:58
@nakedible-p nakedible-p marked this pull request as draft March 13, 2023 20:59
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@nakedible-p nakedible-p changed the title Fix CompositeAlarm.fromCompositeAlarmName arn format fix(aws-cloudwatch): correct CompositeAlarm.fromCompositeAlarmName ARN format Mar 13, 2023
@nakedible-p nakedible-p changed the title fix(aws-cloudwatch): correct CompositeAlarm.fromCompositeAlarmName ARN format fix(cloudwatch): correct CompositeAlarm.fromCompositeAlarmName ARN format Mar 13, 2023
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 and removed p2 labels Mar 13, 2023
@nakedible-p
Copy link
Contributor Author

Exemption Request: Fix is in resource import, which isn't visible in stack output except if doign some other usage.

All in all, not sure what is the best way to test the fix, as there were no tests for the original functionality (which is obviously why it was broken in the first place).

Somebody more knowledgeable could give me a hint.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Mar 13, 2023
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@ayush987goyal
Copy link
Contributor

@nakedible-p Can you mark this PR ready for review?

@pahud Can we create an exemption for the linter?

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@pahud
Copy link
Contributor

pahud commented Apr 5, 2023

Hi

Fixes must contain a change to an integration test file and the resulting snapshot.

You will need to submit an integration test file change and re-generate the snapshot.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

And I see some file conflicting you will need to resolve to pass the check before the maintainers can come in for initial review.

@aws-cdk-automation aws-cdk-automation added the pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run label Apr 5, 2023
@nakedible-p nakedible-p force-pushed the patch-1 branch 3 times, most recently from d2fe6fa to 9d10492 Compare April 6, 2023 01:13
@nakedible-p nakedible-p marked this pull request as ready for review April 6, 2023 01:14
@nakedible-p
Copy link
Contributor Author

Hi Pahud

Pull request now marked ready for review.

And as explained above, I don't know how to get the integration test thing fixed, as there are no integration tests for imports in this module.

Exemption Request: Fix is in resource import, which isn't visible in stack output except if doing some other usage.

All in all, not sure what is the best way to test the fix, as there were no tests for the original functionality (which is obviously why it was broken in the first place).

Somebody more knowledgeable could give me a hint.

The fix is trivial, but I do need assistance on how to write a test that didn't exist in the first place.

@nakedible-p nakedible-p changed the base branch from main to v2-release April 6, 2023 01:21
@nakedible-p nakedible-p changed the base branch from v2-release to main April 6, 2023 01:22
@nakedible-p
Copy link
Contributor Author

Neither of those is an integration test (integ.*.ts) and the linter wants me to add an integration test.

@ayush987goyal
Copy link
Contributor

@nakedible-p We should add this change for IAlarm as well to make it a consistent experience.

Regarding integration tests, you can refer this guide and an example here

On a high level it could look like what we have below where we create two stacks (one producer and one consumer)

import * as cw from 'aws-cdk-lib/aws-cloudwatch';
import * as cdk from 'aws-cdk-lib/core';
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';

const ALARM_NAME = "SomeAlarmName";
const COMPOSITE_ALARM_NAME = "SomeCompositeAlarmName";

class ProducerStack extends cdk.Stack {

  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const alarm = new cw.Alarm(this, "SomeAlarm", {...});

    const compositeAlarm = new cw.CompositeAlarm(this, "SomeCompositeAlarm", {...});
  }
}

class ConsumerStack extends cdk.Stack {

  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const importedAlarm = cw.Alarm.fromAlarmName(this, "ImportedSomeAlarm", ALARM_NAME);
    const importedCompositeAlarm = cw.CompositeAlarm.fromCompositeAlarmName(this, "ImportedSomeAlarm", COMPOSITE_ALARM_NAME);

    // create a new composite alarm from the two imported alarms above.
    const compositeAlarm = new cw.CompositeAlarm(this, "SomeCompositeAlarm", {...});
  }
}

const app = new cdk.App();
const producerStack = new ProducerStack(app, 'alarm-import-producer-integ');
const consumerStack = new ConsumerStack(app, 'alarm-import-consumer-integ');
consumerStack.addDependency(producerStack);

const testCase = new IntegTest(app, 'ImportAlarms', {
  testCases: [producerStack, consumerStack],
});

// Add assertions here that the new compositeAlarm in consumerStack exists.
testCase.assertions
  .awsApiCall('CloudWatch', 'DescribeAlarms', {...})
  .expect(ExpectedResult.objectLike(...));

@nakedible-p
Copy link
Contributor Author

To clarify:

  • I'm happy to spend the 15 minutes it takes to make an obvious fix to an obvious bug.
  • I'm happy to spend the 30 minutes to write a simple regression test case that didn't exist for the feature.
  • I'm happy to spend 30 minutes more to cross the t's and dot the i's to get a pull merged.

I'm not interested in:

  • Spending hours figuring out where or how I need to run yarn integ when the docs do not really give a clue
  • Spending hours ensuring the test suite passes in GitHub Codespaces when it mysteriously freezes mid-run
  • Spending hours building a comprehensive test suite for a feature that had no tests at all
  • Spending hours refactoring also Alarm to match the API of CompositeAlarm when they were inconsistent to start with

If you can help me in exactly what commands I need to run on a freshly checked out repository in order to run integration tests on packages/aws-cdk-lib/aws-cloudwatch, I can add a simple integration test which includes the composite alarm name and ARN in the generated stack, so the snapshot will catch any inadvertent changes. Otherwise, I'm happy to leave this work continued by someone else.

(Sorry, no coffee this morning yet)

@ayush987goyal
Copy link
Contributor

I agree and that's why I requested @pahud to override that pr-rule for this change since I have typically not seen any service module having integ-tests for importing resources. I provided the above reference since you said you needed some assistance in writing them.

I am okay in not having integ-tests for this change and have appropriate coverage with just unit-tests. But I would really love to see the same API added to Alarm to be consistent even though they were not consistent to being with. Then again this is not something which should block this fix to be merged but a mere request.

@pahud What are you thoughts on this?

@nakedible-p
Copy link
Contributor Author

Hold your horses - after some coffee, I found out the following:

  • All the integration tests for aws-cdk-lib have been moved to @aws-cdk-testing/framework-integ
  • There's plenty of existing integration tests for Cloudwatch
  • I can probably manage to run the integration tests now that I found out from the build logs how they are run
  • Integration test documentation is woefully out of date on these

@aws-cdk-automation aws-cdk-automation dismissed their stale review April 8, 2023 10:02

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@nakedible-p
Copy link
Contributor Author

How about it now?

  • Added missing method on Alarm
  • Added tests on Alarm as well
  • Added tests on the ARN variants of import on both of them (so we know ARN parsing works)
  • Added integration test for composite alarm which ensures the alarmName and alarmArn stay stable by exposing them as outputs from the stack

Also, it seems that it is already known that the integration tests document is out of date: #24958

Copy link
Contributor

@ayush987goyal ayush987goyal left a comment

Choose a reason for hiding this comment

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

LGTM!
Thanks a lot for going the extra mile to add the functionality to Alarm and corresponding missing unit tests as well!

@nakedible-p
Copy link
Contributor Author

Do I need to do something else to push this through, or will the AWS reviewers just pick this up when they have the time?

corymhall
corymhall previously approved these changes Apr 17, 2023
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@corymhall corymhall self-assigned this Apr 17, 2023
@mergify
Copy link
Contributor

mergify bot commented Apr 17, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@nakedible-p
Copy link
Contributor Author

refusing to allow a GitHub App to create or update workflow .github/workflows/yarn-upgrade.yml without workflows permission
err-code: D813F

I think auto merge failed because of commit c174a49

Should I manually update the branch, or will someone else handle it from here?

@mergify mergify bot dismissed corymhall’s stale review April 17, 2023 17:45

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: bbbaca5
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Apr 17, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 3bf6adb into aws:main Apr 17, 2023
@nakedible-p nakedible-p deleted the patch-1 branch April 17, 2023 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cloudwatch: Imported composite alarm ARN incorrect
5 participants