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: Fix - make sure dimensions are propagated to alert query editor #58281

Conversation

conorevans
Copy link
Contributor

Signed-off-by: Conor Evans coevans@tcd.ie

Which issue(s) does this PR fix?:

Fixes #58280

Special notes for your reviewer:

I'm not sure if Cloudwatch can return strings as the value for Dimensions. From what I can see, they're always arrays with a single string. However, I've kept the existing code in place and just modified it to account for that latter case.

Before:

grafana_latest_bug.mov

After:

grafana_local_fixed.mov

Signed-off-by: Conor Evans <coevans@tcd.ie>
@conorevans conorevans requested a review from a team as a code owner November 4, 2022 22:09
@conorevans conorevans requested review from iwysiu and kevinwcyu and removed request for a team November 4, 2022 22:09
@grafanabot grafanabot added datasource/CloudWatch area/frontend pr/external This PR is from external contributor labels Nov 4, 2022
@sunker
Copy link
Contributor

sunker commented Nov 7, 2022

Thanks a lot for reporting this issue and proposing a solution @conorevans!

I wonder if the problem can be solved with a different approach though. The alerting engine doesn't support template variables, so before the alerting UI is loaded, it calls interpolateVariablesInQuery in the data source file. It looks like through a pretty complicated chain of calls, expandVariableToArray is being called to interpolate any template variables in the dimension values prop. This method should not convert the dimension value to an array in case the value itself was not a template variable. Would you like to try and come up with a fix using that approach?

Thanks again!

@conorevans
Copy link
Contributor Author

Hi @sunker thanks for the review and pointing me in a helpful direction! Yeah there's quite the chaining happening here, makes for some gnarly debugging 😅 (esp as I'm no TS whiz).

I've implemented your feedback and it looks cleaner + set properly closer to source than my original tack. Please feel free to suggest any changes or apply them yourself. Cheers

Copy link
Contributor

@sunker sunker left a comment

Choose a reason for hiding this comment

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

Thanks! Added a few comments. Also, would you be able to add a test for the interpolateVariablesInQueries method? There's already a pattern for testing this method here in the datasource test file. If you could add a scenario with something like should not change structure of dimension prop if its not a template variable, that would be great!

@conorevans
Copy link
Contributor Author

@sunker implemented that batch of feedback! I tried to add a test via a few different permutations but I could not find a satisfactory way of accessing the dimensions of the interpolated queries. Do you mind taking a look? I'm happy for you to push to my PR

@sunker
Copy link
Contributor

sunker commented Nov 7, 2022

@sunker implemented that batch of feedback! I tried to add a test via a few different permutations but I could not find a satisfactory way of accessing the dimensions of the interpolated queries. Do you mind taking a look? I'm happy for you to push to my PR

Test added!

@conorevans
Copy link
Contributor Author

@sunker implemented that batch of feedback! I tried to add a test via a few different permutations but I could not find a satisfactory way of accessing the dimensions of the interpolated queries. Do you mind taking a look? I'm happy for you to push to my PR

Test added!

Thank you 😄

@conorevans conorevans requested review from sunker and removed request for iwysiu and kevinwcyu November 7, 2022 13:16
@conorevans
Copy link
Contributor Author

Sorry didn't realise that requesting re-review from @sunker would remove request for review from @iwysiu and @kevinwcyu

@sunker
Copy link
Contributor

sunker commented Nov 7, 2022

@conorevans I'll look into the failing tests as soon as I can!

@sunker sunker force-pushed the conorevans/grafana-58280-alerting-cloudwatch-dimensions branch from 8dbd485 to 0488fbb Compare December 7, 2022 08:29
@sunker
Copy link
Contributor

sunker commented Dec 7, 2022

Sorry @conorevans, dropped the ball on this PR for a while.

The path that I suggested in this PR, making changes to datasource.interpolateVariablesInQuery, had side effects that there are not easy fixes for. I rebased and removed all commits except for the first one, which includes you initial fix. Also added a unit test.

Thanks a lot for contributing and again sorry for the delay!

@sunker sunker added the type/bug label Dec 7, 2022
@sunker sunker changed the title fix(unified-alerting/cloudwatch): propagate dimensions to alert CloudWatch: Fix - make sure dimensions are propagated to alert query editor Dec 7, 2022
@sunker sunker added this to the 9.3.2 milestone Dec 7, 2022
grafanabot pushed a commit that referenced this pull request Dec 7, 2022
…editor (#58281)

* fix(unified-alerting/cloudwatch): propagate dimensions to alert

Signed-off-by: Conor Evans <coevans@tcd.ie>

* add unit test

Signed-off-by: Conor Evans <coevans@tcd.ie>
Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
(cherry picked from commit dce7f50)
sunker pushed a commit that referenced this pull request Dec 7, 2022
…rt query editor (#59933)

CloudWatch: Fix - make sure dimensions are propagated to alert query editor (#58281)

* fix(unified-alerting/cloudwatch): propagate dimensions to alert

Signed-off-by: Conor Evans <coevans@tcd.ie>

* add unit test

Signed-off-by: Conor Evans <coevans@tcd.ie>
Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
(cherry picked from commit dce7f50)

Co-authored-by: Conor Evans <43791257+conorevans@users.noreply.github.com>
@conorevans
Copy link
Contributor Author

All okay @sunker ! Thanks for your efforts

GuYounes pushed a commit to paul-wurth/BIXpert that referenced this pull request Feb 8, 2023
…rt query editor (grafana#59933)

CloudWatch: Fix - make sure dimensions are propagated to alert query editor (grafana#58281)

* fix(unified-alerting/cloudwatch): propagate dimensions to alert

Signed-off-by: Conor Evans <coevans@tcd.ie>

* add unit test

Signed-off-by: Conor Evans <coevans@tcd.ie>
Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
(cherry picked from commit dce7f50)

Co-authored-by: Conor Evans <43791257+conorevans@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

unified alerting: Cloudwatch queries do not propogate dimensions
3 participants