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

Alerting: Enable preview for recording rules #63260

Merged
merged 19 commits into from Mar 22, 2023

Conversation

VikaCep
Copy link
Contributor

@VikaCep VikaCep commented Feb 10, 2023

What is this feature?

Allows to preview queries when creating/editing Recording Rules.

Why do we need this feature?

Previously, it was only possible to do it for Alerting rules.

Who is this feature for?

All users.

Which issue(s) does this PR fix?:

Fixes #35699

Special notes for your reviewer:

2023-03-17 19 30 44

@VikaCep
Copy link
Contributor Author

VikaCep commented Feb 24, 2023

@gillesdemey I'm still working on this PR, but I'd like to have your input so far if you don't mind.
I've been struggling to get the Editor from the datasource itself to work with our queries (I've made some commits trying out that solution in this other branch but couldn't get the query to be visualized) so in the end it was easier to use the alerting QueryEditor component as it handles effectively creating a model for the new query and also displaying it using the visualization component.
The problem I'm facing now is displaying the recording rule query properly in the edit screen as the format that comes from the API for recording queries consists of just a string expression which is not compatible with what the QueryEditor expects. But before investing more time on this I wanted to have your opinion on the current implementation. I'd appreciate any feedback, thank you!

@gillesdemey
Copy link
Member

🍐-ed up with @VikaCep on this one and we think we have a good way forward that allows us to render the <QueryEditor /> as long as we pass the right information in to the query.model.

@VikaCep VikaCep force-pushed the alerting/enable-preview-for-recording-rules branch 2 times, most recently from 8a0ae14 to 4335e52 Compare March 6, 2023 12:40
@VikaCep VikaCep changed the title [WIP] Alerting: enable preview for recording rules Alerting: enable preview for recording rules Mar 6, 2023
@VikaCep VikaCep added this to the 9.5.0 milestone Mar 6, 2023
@VikaCep VikaCep added the no-backport Skip backport of PR label Mar 6, 2023
@VikaCep VikaCep self-assigned this Mar 6, 2023
@VikaCep VikaCep marked this pull request as ready for review March 6, 2023 12:56
@VikaCep VikaCep requested review from a team as code owners March 6, 2023 12:56
@VikaCep VikaCep requested review from axelavargas and polibb and removed request for a team March 6, 2023 12:56
It reuses QueryEditor and propagates a few properties to allow to filter the visible datasources and customize what's shown in the editor header
Otherwise it would get mixed up with the alert rules queries when switching back and forth from this option. This also allows me to initialize these queries with the right datasource
As now we use the query editor for recording rules which already includes a datasource picker within
@VikaCep VikaCep force-pushed the alerting/enable-preview-for-recording-rules branch from 4335e52 to 158e721 Compare March 6, 2023 16:50
Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron left a comment

Choose a reason for hiding this comment

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

Very nice!!, I added some comments 👀

@axelavargas axelavargas removed their request for review March 8, 2023 11:06
Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron left a comment

Choose a reason for hiding this comment

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

Nice one! 🎉

@konrad147
Copy link
Contributor

konrad147 commented Mar 10, 2023

I would try to avoid using the QueryEditor component. It renders a few components that might be misleading for users (collapse, query name, re-order handler). It also diverges from Prometheus' rules experience.
Could we try to use PanelRenderer for the visualization part? You can also take a look at public/app/features/alerting/unified/components/rule-viewer/RuleViewerVisualization.tsx to see how it works

Alternatively, we should tweak the query editor to also work for Prometheus rules so the experience is consistent

@VikaCep VikaCep removed the request for review from polibb March 17, 2023 22:31
Copy link
Contributor

@konrad147 konrad147 left a comment

Choose a reason for hiding this comment

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

Looks nice! 🎉 one nit: I'd add a bit of margin between the query editor and the viz wrapper

@gillesdemey
Copy link
Member

I think this one still needs the tests to be updated, code LGTM!

@gillesdemey gillesdemey changed the title Alerting: enable preview for recording rules Alerting: Enable preview for recording rules Mar 21, 2023
@VikaCep
Copy link
Contributor Author

VikaCep commented Mar 21, 2023

Failing tests have been addressed and I applied some margin to the VizWrapper component as suggested by Konrad ✅

@VikaCep VikaCep merged commit a1fc515 into main Mar 22, 2023
6 checks passed
@VikaCep VikaCep deleted the alerting/enable-preview-for-recording-rules branch March 22, 2023 12:21
gotjosh pushed a commit that referenced this pull request Mar 27, 2023
* Create RecordingRuleEditor component

It reuses QueryEditor and propagates a few properties to allow to filter the visible datasources and customize what's shown in the editor header

* Set recording rules queries as a new state prop

Otherwise it would get mixed up with the alert rules queries when switching back and forth from this option. This also allows me to initialize these queries with the right datasource

* Show CloudRulesSourcePicker only for Loki/Mimir rules

As now we use the query editor for recording rules which already includes a datasource picker within

* Fix lint and tests

* Fix saving a recording rule

* Show expression when editing the recording rule

* Show query editor back for cloud rules

* Fix duplicated import

* Tweak after rebase

* Remove ts-ignore

* Refactor to use queries state instead of recordingRuleQueries

* Refacrtor RecordingRuleEditor to use ds QueryEditor

* Revert extra properties previously added to QueryEditor components

* Remove console.log

* Fix saving/editing a recording rule

* Fix tests

* Add margin to vizwrapper component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Alerting: Preview recording rules in the rule editor
5 participants