[ES|QL Controls] Refresh "Values from a query" options on dashboard reload#225101
[ES|QL Controls] Refresh "Values from a query" options on dashboard reload#225101Zacqary merged 55 commits intoelastic:mainfrom
Conversation
| } | ||
| }; | ||
|
|
||
| esqlQueryToOptions.isSuccess = (result: unknown): result is ESQLControlOptionsSuccess => |
There was a problem hiding this comment.
I think glomming a type guard for the result onto the function itself is an elegant way to save space and imports but if this is too galaxy brain javascript to be a sustainable pattern, I'm open to changing this.
|
Pinging @elastic/kibana-presentation (Team:Presentation) |
| ESQLVariableType, | ||
| } from '@kbn/esql-types'; | ||
| import { PublishingSubject, StateComparators } from '@kbn/presentation-publishing'; | ||
| import { esqlQueryToOptions } from '@kbn/presentation-controls'; |
There was a problem hiding this comment.
Why is this placed in a package? What are the future plans for this package and method?
There was a problem hiding this comment.
We need to make this method available to the esql plugin and controls plugin without creating any new cross-dependencies, because in my experience that eventually leads to circular dependency hell. I wasn't able to find an existing kbn package that seemed to fit.
If we're going to work on combining the UI components for classic and ES|QL controls, I expect we're going to run into more cases like this.
There was a problem hiding this comment.
Thanks for the explanation. That makes sense.
Why does it need its own package and is that it important that it it has presentation-controls namespace? Would it be better to place in an existing esql package like esql-utils? That way, all esql logic is located in a single location.
There was a problem hiding this comment.
Sure, I can move it to esql-utils and hold off on creating a new package for controls until we've got a larger use case.
There was a problem hiding this comment.
I am not sure we need to move it. I only want to have the discussion and understand the why. If there are no plans that would require a separate package and no design reasons, then we can have the conversation about moving it into an existing package.
|
I think this will create conflicts with #225054 but it should be easy to solve, let me know if you need any help |
stratoula
left a comment
There was a problem hiding this comment.
I didnt go through the code but I would like to raise a concern about this feature mostly due to how ES|QL works and returns results
Let'say that the user types a query like this:
FROM logs* | STATS BY agent.name | LIMIT 5
This returns 5 values (one is null and we dont allow it)

Now every time you refresh your dashboard this list changes
and can change so much that the selected value is not part of the list anymore
which can be weird. This happens due to the randomness of the data retrieval especially for datasets with sparse data.
A user can improve that with sorting etc but it something I wanted to raise with you before we move on with this functionality cc @ghudgins
...form/plugins/shared/esql/public/triggers/esql_controls/control_flyout/value_control_form.tsx
Outdated
Show resolved
Hide resolved
# Conflicts: # src/platform/plugins/shared/esql/public/triggers/esql_controls/control_flyout/value_control_form.tsx
| availableOptions$.next(result.values); | ||
| } | ||
| } | ||
| const fetchSubscription = controlFetch$.subscribe(updateAvailableOptions); |
There was a problem hiding this comment.
This introduces a race condition. If updateAvailableOptions does not return before controlFetch$ fires again and updateAvailableOptions from the second emit returns first, then updateAvailableOptions from the first emit will overwrite the options. to solve this, you should use a switchMap
const fetchSubscription = controlFetch$.pipe(
filter(() => controlType$.getValue() === EsqlControlType.VALUES_FROM_QUERY)
switchMap(async (fetchContext) => {
return await getESQLSingleColumnValues({
query: esqlQuery$.getValue(),
search: dataService.search.search,
timeRange: fetchContext.timeRange,
});
}),
).subscribe(results => {
if (getESQLSingleColumnValues.isSuccess(results)) {
availableOptions$.next(result.values);
}
});
| export function initializeESQLControlSelections( | ||
| initialState: ESQLControlState, | ||
| controlFetch$: ReturnType<ControlGroupApi['controlFetch$']>, | ||
| timeRange$?: PublishingSubject<TimeRange | undefined> |
There was a problem hiding this comment.
You don't need to pass in timeRange$, its provided by controlFetch$
|
@stratoula Had a conversation with @ThomThomson and we've decided just to apply these changes to the |
| return { values }; | ||
| } | ||
|
|
||
| return { columns, errors: [] }; |
There was a problem hiding this comment.
I am not sure I understand why the function would return columns when there are more then one? Would this be an error case? What consumer would use this response? Would it be better to just throw an error if multiple columns are returned?
There was a problem hiding this comment.
The flyout UI needed this because it needs to populate a dropdown list of possible columns in the error state. I can remove it for now.
There was a problem hiding this comment.
I'm anticipating we'll need this again in a followup PR so I'm going to keep the values/errors key value schema in the return type
nreese
left a comment
There was a problem hiding this comment.
kibana-presentation changes LGTM after fixing last few comments in test. Thanks for cleaning everything up
code review only
| search: searchMock, | ||
| })) as GetESQLSingleColumnValuesSuccess; | ||
| expect(getESQLSingleColumnValues.isSuccess(result)).toBe(true); | ||
| expect('columns' in result).toBe(false); |
There was a problem hiding this comment.
columns is no longer in response so this expect is not needed.
| } | ||
| `); | ||
| }); | ||
| it('returns columns and empty error on successful query that returns multiple columns', async () => { |
There was a problem hiding this comment.
how about renaming to 'returns error when query returns multiple columns'?
|
Starting backport for target branches: 8.17, 8.18, 8.19, 9.0, 9.1 |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
|
…eload (elastic#225101) ## Summary Closes elastic#222198 For "values from a query" ES|QL controls, attempts to execute the query again on dashboard page load, refresh, timerange change, etc. to get an up-to-date list of values. If the query execution fails, values cached at the previous edit time will be used. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 215a4bf)
💔 Some backports could not be createdNote: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
|
Starting backport for target branches: 8.19, 9.1 |
|
Starting backport for target branches: 8.19, 9.1 |
|
Starting backport for target branches: 8.19, 9.1 |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…eload (elastic#225101) ## Summary Closes elastic#222198 For "values from a query" ES|QL controls, attempts to execute the query again on dashboard page load, refresh, timerange change, etc. to get an up-to-date list of values. If the query execution fails, values cached at the previous edit time will be used. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 215a4bf) # Conflicts: # src/platform/plugins/shared/controls/tsconfig.json
…oard reload (#225101) (#225891) # Backport This will backport the following commits from `main` to `9.1`: - [[ES|QL Controls] Refresh "Values from a query" options on dashboard reload (#225101)](#225101) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Zac Xeper","email":"Zacqary@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-06-30T17:20:21Z","message":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload (#225101)\n\n## Summary\n\nCloses #222198 \n\nFor \"values from a query\" ES|QL controls, attempts to execute the query\nagain on dashboard page load, refresh, timerange change, etc. to get an\nup-to-date list of values.\n\nIf the query execution fails, values cached at the previous edit time\nwill be used.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"215a4bf136c201bdcb0759f137486573309526ae","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","release_note:fix","Team:Presentation","loe:medium","impact:critical","backport:all-open","v9.2.0"],"title":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload","number":225101,"url":"https://github.com/elastic/kibana/pull/225101","mergeCommit":{"message":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload (#225101)\n\n## Summary\n\nCloses #222198 \n\nFor \"values from a query\" ES|QL controls, attempts to execute the query\nagain on dashboard page load, refresh, timerange change, etc. to get an\nup-to-date list of values.\n\nIf the query execution fails, values cached at the previous edit time\nwill be used.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"215a4bf136c201bdcb0759f137486573309526ae"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/225101","number":225101,"mergeCommit":{"message":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload (#225101)\n\n## Summary\n\nCloses #222198 \n\nFor \"values from a query\" ES|QL controls, attempts to execute the query\nagain on dashboard page load, refresh, timerange change, etc. to get an\nup-to-date list of values.\n\nIf the query execution fails, values cached at the previous edit time\nwill be used.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"215a4bf136c201bdcb0759f137486573309526ae"}}]}] BACKPORT--> Co-authored-by: Zac Xeper <Zacqary@users.noreply.github.com>
…board reload (#225101) (#225903) # Backport This will backport the following commits from `main` to `8.19`: - [[ES|QL Controls] Refresh "Values from a query" options on dashboard reload (#225101)](#225101) <!--- Backport version: 10.0.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Zac Xeper","email":"Zacqary@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-06-30T17:20:21Z","message":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload (#225101)\n\n## Summary\n\nCloses #222198 \n\nFor \"values from a query\" ES|QL controls, attempts to execute the query\nagain on dashboard page load, refresh, timerange change, etc. to get an\nup-to-date list of values.\n\nIf the query execution fails, values cached at the previous edit time\nwill be used.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"215a4bf136c201bdcb0759f137486573309526ae","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","release_note:fix","Team:Presentation","loe:medium","impact:critical","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload","number":225101,"url":"https://github.com/elastic/kibana/pull/225101","mergeCommit":{"message":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload (#225101)\n\n## Summary\n\nCloses #222198 \n\nFor \"values from a query\" ES|QL controls, attempts to execute the query\nagain on dashboard page load, refresh, timerange change, etc. to get an\nup-to-date list of values.\n\nIf the query execution fails, values cached at the previous edit time\nwill be used.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"215a4bf136c201bdcb0759f137486573309526ae"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/225891","number":225891,"state":"OPEN"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/225101","number":225101,"mergeCommit":{"message":"[ES|QL Controls] Refresh \"Values from a query\" options on dashboard reload (#225101)\n\n## Summary\n\nCloses #222198 \n\nFor \"values from a query\" ES|QL controls, attempts to execute the query\nagain on dashboard page load, refresh, timerange change, etc. to get an\nup-to-date list of values.\n\nIf the query execution fails, values cached at the previous edit time\nwill be used.\n\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"215a4bf136c201bdcb0759f137486573309526ae"}}]}] BACKPORT-->
Summary
Closes #222198
For "values from a query" ES|QL controls, attempts to execute the query again on dashboard page load, refresh, timerange change, etc. to get an up-to-date list of values.
If the query execution fails, values cached at the previous edit time will be used.
Checklist