-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Correlations: Add transformations to Explore Editor #75930
Conversation
Backend code coverage report for PR #75930 |
Frontend code coverage report for PR #75930
|
bd6473d
to
a9e6b07
Compare
…na/correlations-editor-transform
…na/correlations-editor-transform
…na/correlations-editor-transform
…na/correlations-editor-transform
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.
Transformations vars are not interpolated inside the editor
After adding transformations I was not able to use vars inside the editor / right pane. After saving everything works fine. It looks like only when we're inside the editor, then transformation vars are not used when interpolating.
interpolation.mov
Also probably not related to this PR but worth checking:
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${true} | ${true} | ${false} | ${'Closing the pane will cause the correlation in progress to be lost. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${true} | ${false} | ${true} | ${'Closing the pane will cause the query in the right pane to be re-ran and links added to that data. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${true} | ${true} | ${true} | ${'Closing the pane will cause the correlation in progress to be lost. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${false} | ${false} | ${false} | ${undefined} |
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.
It may not happen with each data source but sometimes changing the data source without making any changes causes the modal to appear. Could it be because the editor calls onChange
?
change-ds-triggers-the-prompt.mov
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.
Yeah :/ and I'm not quite sure what the solution is.
The order of events is this
- User changes the datasource to cloudwatch. This completes. The onChange function that we use to track a dirty query is passed into the query editor
- Cloudwatch's query editor internally runs a function that calls the onChange function passed in https://github.com/grafana/grafana/blob/main/public/app/plugins/datasource/cloudwatch/components/QueryEditor/QueryEditor.tsx#L28 - If you look at the queries before and after the change, it sets up the data structure for CW with log groups, region, an empty logGroups array, etc.
- The onChange function is executed and the query gets marked as dirty even without any user interaction interacting with the editor.
I need to investigate some more, but I don't know how to make the distinction between a user performed query change and an automatic one, when the editor itself doesn't make that distinction at all. I thought that ensuring the query was not marked as dirty after the DS changed would be enough, but the query editor for the plugin is mounted after and I don't think there's any sort of state change that happens after that mount occurs.
I feel like this is sorta similar to #52213 in that both situations would be very much improved if we knew when the query editor was done doing whatever it needed to do.
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${true} | ${true} | ${true} | ${'Changing the datasource will cause the correlation in progress to be lost. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_EDITOR} | ${false} | ${false} | ${false} | ${undefined} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_EDITOR} | ${false} | ${true} | ${false} | ${'Closing the editor will cause the correlation in progress to be lost. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_EDITOR} | ${false} | ${false} | ${true} | ${'Closing the editor will lose the changed query. Would you like to save before continuing?'} |
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.
In what sense "the query is lost"? I tried closing the right pane after changing the query and it seems to run exactly the same query without losing anything:
losing-the-query.mov
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.
Ah this is true. I might change this to say "Closing the editor will remove the variables, and your changed query may no longer be valid. Would you like to save before continuing?" in this instance
Fixed!
it.each` | ||
action | isLeft | dirCor | dirQuer | expected | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${false} | ${false} | ${false} | ${undefined} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${false} | ${true} | ${false} | ${'Closing the pane will cause the correlation in progress to be lost. Would you like to save before continuing?'} |
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.
Changing the label doesn't mark a correlation as dirty. Is it expected?
Screen.Recording.2023-10-23.at.11.38.28.mov
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.
No - changing the label means the correlation dirty state is true. This was a regression when I used the default value as a default value instead of the default value being blank and only using the default value on save.
And actually I think I'll be able to tackle this and the mixed datasource problem at the same time, so I'll be looking into this more.
Fixed!
…na/correlations-editor-transform
fixed!
Fixed (finally...)
I did this on purpose to increase the likelihood that people will have matches and I'd like to keep it that way for now. I added it to the tooltip. |
1533148
to
f473dd6
Compare
…na/correlations-editor-transform
…na/correlations-editor-transform
…na/correlations-editor-transform
…na/correlations-editor-transform
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.
Is documentation being added as part of this PR?
} | ||
}; | ||
|
||
export const generateDefaultLabel = async (sourcePane: ExploreItemState, targetPane: ExploreItemState) => { |
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.
Ideally correlations utils should not rely on any Explore specific types. This function could get datasourceRef
passed instead of entire ExploreItemState
.
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${false} | ${false} | ${true} | ${'Changing the datasource will lose the changed query. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${false} | ${true} | ${true} | ${'Changing the datasource will lose the changed query. Would you like to save before continuing?'} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${true} | ${false} | ${false} | ${undefined} | ||
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${true} | ${true} | ${false} | ${'Changing the datasource will cause the correlation in progress to be lost. Would you like to save before continuing?'} |
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.
Personally I find it confusing that I'm asked if I want to save the correlation at this point. I'd expect a simple question like "Your progress will be lost. Do you want to continue?". But I'll leave it up to UX.
Created #77457 and that will be my next task |
…na/correlations-editor-transform
…na/correlations-editor-transform
* Add transformation add modal and use it * Hook up saving * Add transformation vars to var list, show added transformations * Form validation * Remove type assertion, start building out transformation data in helper (WIP) * Style expression better, add delete logic * Add ability to edit, additional styling on transformation card in helper * simplify styling, conditionally run edit set up logic * Keep more field information in function, integrate it with new editor * Show default label on collapsed section, use deleteButton for confirmation of deleting transformations * Change transformation add calculations from function to hook, add label to collapsed header, add transformation tooltip * Make correlation and editor dirty state distinctive and integrate, WIP * Track action pane for more detailed messaging/actions * Better cancel modal logic * Remove changes to adminsitration transformation editor * Remove debugging line * Remove unneeded comment * Add in logic for closing editor mode * Add tests for modal logic * Use state to build vars list for helper * WIP * Fix labels and dirty state * Fix bad message and stop exiting mode if discard action is performed * Fix tests * Update to not use unstable component and tweak default label
What is this feature?
Adds the ability to create one or more correlation transformations from the Explore correlation editor.
Why do we need this feature?
Transformations are almost necessary for creating correlations on logs. Logs' data format generally has more than one piece of information per field, notably the log line field and the labels field. Transformations were created to parse out information people may want, via a regular expression or logfmt.
Who is this feature for?
People who want to create correlations where data may be within in one field amongst other data.
Which issue(s) does this PR fix?:
Fixes #75832
Special notes for your reviewer:
Testing this with devenv, using Loki is probably your best bet. Logfmt will parse the devenv line, and labels can be parsed out with the following regex expressions:
namespace":"([a-z]*)
- this is an unnamed capture groupnamespace":"(?<test2>[a-z]*)
this is a named capture groupIn the ephemeral, loki data is available in the
grafanacloud-ephemeral1511182175930gelicia-usage-insights
Loki datasource. Doing a logfmt transformation against a Line field adds a lot of variables. Adding a regex transformation on labels works with the followinginstance_type":"([a-z]*)
- this is an unnamed capture groupinstance_type":"(?<name>[a-z]*)
- this is a named capture groupPlease check that: