-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
AlertNotifications: Translate notifications IDs to UIDs in Rule builder #19882
Conversation
How are you getting alert rules with notification ids? new rules should use uids. Only legacy rules should still use ids, and we convert those to uids same way we migrated them in the DB |
@torkelo We have system that generates dashboards with ID based notification channels |
Is there a migration for dashboards that point to notifications by the old IDs? I'm only seeing the migration of the grafana/pkg/services/sqlstore/migrations/alert_mig.go Lines 155 to 159 in 7a8f2cd
|
This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
any plans to solve this issue on the code base? I think a lot of people will run into this problem. I am also not sure how to solve the issue on for all dashboards. can someone point out which ID, UID need to be used for the migration? |
This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
Please check my comments for some suggested improvements.
@papagian thank you for the comments. I'll try to complete the needed changes soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for the modifications.
I have a minor comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
I have a minor request before merging, please check my inline comment!
Additionally, it would be nice to do some UID caching.
Therefore I would recommend to change the GetAlertNotifications
to save the result in the cache and check whether it exists in the cache before running the actual query. Here you can find an example of using the cache.
@papagian are you referring to caching the id->uid translation result? This makes perfect sense. |
yes! sorry for not being clear |
great! I was concerned about caching values that might change in runtime 😅 |
@papagian I'm not sure why mysql-integration-test failed but it looks like a timeout issue. Is there a way to run it locally? I can't re-run from CircleCI |
@aSapien |
@papagian Yep, it's fine now, but failing on grafana-docker-ubuntu-pr which has nothing to do with this PR. Please review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you for the modifications.
I have some suggestions for improving the tests.
Let me know if you want to work on them or you would prefer me to do it.
@@ -321,5 +321,54 @@ func TestAlertNotificationSQLAccess(t *testing.T) { | |||
So(len(query.Result), ShouldEqual, 4) | |||
}) | |||
}) | |||
|
|||
Convey("Notification Uid by Id Caching", func() { | |||
ss.CacheService.Flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer mocking the actual cache (and reverting after execution) instead of flushing:
actualCache := ss.CacheService
ss.CacheService = localcache.New(5*time.Minute, 10*time.Minute)
defer func() {
ss.CacheService = actualCache
}()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@papagian I saw that some tests initialize a separate TestDb for isolated test scopes. Perhaps I should use this technique instead? I like it because it's less verbose.
grafana/pkg/services/sqlstore/user_test.go
Lines 313 to 315 in 5aeb367
Convey("Should enable all users", func() { | |
ss = InitTestDB(t) | |
createFiveTestUsers(func(i int) *models.CreateUserCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then there's not even a need to flush :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can do that instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that important but my last impression was that you would use a separate test database for these tests and you would remove flushing.
@papagian thanks for the comments! I'll do the modifications. They help me learn idiomatic Golang :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modifications look good to me only check my last comment.
@@ -321,5 +321,54 @@ func TestAlertNotificationSQLAccess(t *testing.T) { | |||
So(len(query.Result), ShouldEqual, 4) | |||
}) | |||
}) | |||
|
|||
Convey("Notification Uid by Id Caching", func() { | |||
ss.CacheService.Flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that important but my last impression was that you would use a separate test database for these tests and you would remove flushing.
@papagian Thanks for pointing it out! It must've slipped my mind somehow... I made the necessary change |
Thank you for contributing! |
@aSapien could you synchronise your branch with master in order to trigger running the new |
@papagian yeah working on a fork's master was poor choice. I synced the branches :) |
* master: (113 commits) AlertNotifications: Translate notifications IDs to UIDs in Rule builder (#19882) CircleCI: Don't build Storybook on PR (#22865) Graphite: Rollup Indicator (#22738) Plugins: Return jsondetails as an json object instead of raw json on datasource healthchecks. (#22859) Backend plugins: Exclude plugin metrics in Grafana's metrics endpoint (#22857) Graphite: Fixed issue with query editor and next select metric now showing after selecting metric node (#22856) Webpack: Fix webpack for enterprise (#22863) Metrics: Storybook documented components (#22854) Search: Improve tags layout , #22804 (#22830) Stackdriver: Fix GCE auth bug when creating new data source (#22836) @grafana/runtime: Add cancellation of queries to DataSourceWithBackend (#22818) Rich history: Test coverage (#22852) Chore: Support Volta in package.json (#22849) CircleCI: Skip enterprise builds for forked PRs (#22851) Toolkit: docker image for plugin CI process (#22790) Revert "Explore: Add test coverage for Rich history (#22722)" (#22850) Datasource config was not mapped for datasource healthcheck (#22848) upgrades plugin sdk to 0.30.0 (#22846) Explore: Add test coverage for Rich history (#22722) Rich History: UX adjustments and fixes (#22729) ...
* master: (98 commits) NewPanelEdit: Refactor value mappings UI to work better with new panel edit (grafana#22808) FieldOverrides: Move FieldConfigSource from fieldOptions to PanelModel.fieldConfig (grafana#22600) Reporting: Update docs with correct logger name (grafana#22892) Design tweaks (grafana#22886) Remove duplicated localStorage mock (grafana#22872) Rich history UX fixes (grafana#22783) Storybook: Solve deployment issues (grafana#22873) Docs: Update templating.md (grafana#22881) AzureMonitor: support workspaces function for template variables (grafana#22882) Check if the datasource is of type loki using meta.id instead of name. (grafana#22877) Prometheus: Render missing labels in legend formats as an empty string (grafana#22355) BarGauge: Fix strict null that breaks Storybook build (grafana#22871) SQLStore: Add migration for adding index on annotation.alert_id (grafana#22876) Docs: Update export-pdf.md (grafana#22767) Variables: adds missing feature toggle in DashboardModel (grafana#22868) Devenv: adds grafana block with a customizeable version (grafana#22867) Alerting: support alerting on data.Frame (that can be time series) (grafana#22812) AlertNotifications: Translate notifications IDs to UIDs in Rule builder (grafana#19882) CircleCI: Don't build Storybook on PR (grafana#22865) Graphite: Rollup Indicator (grafana#22738) ...
What this PR does / why we need it:
Fixes alert notifications for dashboards that were saved with notification IDs
Which issue(s) this PR fixes:
Fixes #19771
Special notes for your reviewer:
I wasn't sure if
rule.go
is the correct place for this fix, but it seemed the easiest to put there. Please let me know if there's a better approach to fixing this.Bug trace:
Currently, IDs are parsed, converted to strings and included in the same slice (of UIDs):
grafana/pkg/services/alerting/rule.go
Lines 139 to 147 in c674fa1
In a later stage they are used in
grafana/pkg/services/alerting/notifier.go
Lines 161 to 162 in c674fa1
Which in turn triggers a query, however, the SQL query expects UIDs and doesn't consider "stringified" IDs:
grafana/pkg/services/sqlstore/alert_notification.go
Line 111 in c674fa1
This causes notification entities for IDs to not be returned and therefore to not be triggered.