Skip to content

Commit

Permalink
[8.x] [ES|QL] Disable field stats panel in Dashboard if ES|QL is disa…
Browse files Browse the repository at this point in the history
…bled (#193587) (#193643)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Disable field stats panel in Dashboard if ES|QL is disabled
(#193587)](#193587)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Quynh Nguyen
(Quinn)","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-20T21:37:34Z","message":"[ES|QL]
Disable field stats panel in Dashboard if ES|QL is disabled
(#193587)\n\n## Summary\r\n\r\nThis PR disables field stats panel in
Dashboard if ES|QL is disabled. In\r\naddition, it adds a bit of safety
check for panels that have already\r\nbeen added.\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"decbdfaa4ce43755270ae516987cd92337e54439","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","v9.0.0","backport:prev-major","v8.16.0"],"title":"[ES|QL]
Disable field stats panel in Dashboard if ES|QL is
disabled","number":193587,"url":"https://github.com/elastic/kibana/pull/193587","mergeCommit":{"message":"[ES|QL]
Disable field stats panel in Dashboard if ES|QL is disabled
(#193587)\n\n## Summary\r\n\r\nThis PR disables field stats panel in
Dashboard if ES|QL is disabled. In\r\naddition, it adds a bit of safety
check for panels that have already\r\nbeen added.\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"decbdfaa4ce43755270ae516987cd92337e54439"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193587","number":193587,"mergeCommit":{"message":"[ES|QL]
Disable field stats panel in Dashboard if ES|QL is disabled
(#193587)\n\n## Summary\r\n\r\nThis PR disables field stats panel in
Dashboard if ES|QL is disabled. In\r\naddition, it adds a bit of safety
check for panels that have already\r\nbeen added.\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"decbdfaa4ce43755270ae516987cd92337e54439"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Quynh Nguyen (Quinn) <[email protected]>
  • Loading branch information
kibanamachine and qn895 authored Sep 20, 2024
1 parent 22a51e9 commit 1acb27e
Show file tree
Hide file tree
Showing 8 changed files with 804 additions and 736 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ import {
import type { DataView } from '@kbn/data-views-plugin/public';
import { dynamic } from '@kbn/shared-ux-utility';
import { isDefined } from '@kbn/ml-is-defined';
import { EuiFlexItem } from '@elastic/eui';
import { EuiCallOut, EuiEmptyPrompt, EuiFlexItem } from '@elastic/eui';
import { css } from '@emotion/react';
import type { ActionExecutionContext } from '@kbn/ui-actions-plugin/public';
import type { Filter } from '@kbn/es-query';
import { FilterStateStore } from '@kbn/es-query';
import { getESQLAdHocDataview } from '@kbn/esql-utils';
import { ENABLE_ESQL, getESQLAdHocDataview } from '@kbn/esql-utils';
import { ACTION_GLOBAL_APPLY_FILTER } from '@kbn/unified-search-plugin/public';
import { FormattedMessage } from '@kbn/i18n-react';
import type { DataVisualizerTableState } from '../../../../../common/types';
import type { DataVisualizerPluginStart } from '../../../../plugin';
import type { FieldStatisticsTableEmbeddableState } from '../grid_embeddable/types';
Expand Down Expand Up @@ -153,39 +154,40 @@ export const getFieldStatsChartEmbeddableFactory = (
serializeFieldStatsChartState,
onFieldStatsTableDestroy,
resetData$,
} = initializeFieldStatsControls(state);
} = initializeFieldStatsControls(state, deps.uiSettings);
const { onError, dataLoading, blockingError } = dataLoadingApi;

const defaultDataViewId = await deps.data.dataViews.getDefaultId();
const validDataViewId: string =
isDefined(state.dataViewId) && state.dataViewId !== ''
? state.dataViewId
: defaultDataViewId ?? '';
let initialDataView: DataView[] | undefined;
const validDataViewId: string | undefined =
isDefined(state.dataViewId) && state.dataViewId !== '' ? state.dataViewId : undefined;
let initialDataView: DataView | undefined;
try {
const dataView = isESQLQuery(state.query)
? await getESQLAdHocDataview(state.query.esql, deps.data.dataViews)
: await deps.data.dataViews.get(validDataViewId);
initialDataView = [dataView];
: validDataViewId
? await deps.data.dataViews.get(validDataViewId)
: undefined;
initialDataView = dataView;
} catch (error) {
// Only need to publish blocking error if viewtype is data view, and no data view found
if (state.viewType === FieldStatsInitializerViewType.DATA_VIEW) {
onError(error);
}
}

const dataViews$ = new BehaviorSubject<DataView[] | undefined>(initialDataView);
const dataViews$ = new BehaviorSubject<DataView[] | undefined>(
initialDataView ? [initialDataView] : undefined
);

const subscriptions = new Subscription();
if (fieldStatsControlsApi.dataViewId$) {
subscriptions.add(
fieldStatsControlsApi.dataViewId$
.pipe(
skip(1),
skipWhile((dataViewId) => !dataViewId && !defaultDataViewId),
skipWhile((dataViewId) => !dataViewId),
switchMap(async (dataViewId) => {
try {
return await deps.data.dataViews.get(dataViewId ?? defaultDataViewId);
return await deps.data.dataViews.get(dataViewId);
} catch (error) {
return undefined;
}
Expand Down Expand Up @@ -324,6 +326,8 @@ export const getFieldStatsChartEmbeddableFactory = (
api.viewType$,
api.showDistributions$
);
const isEsqlEnabled = deps.uiSettings.get(ENABLE_ESQL);

const lastReloadRequestTime = useObservable(reload$, Date.now());

const isEsqlMode = viewType === FieldStatsInitializerViewType.ESQL;
Expand Down Expand Up @@ -362,6 +366,49 @@ export const getFieldStatsChartEmbeddableFactory = (
};
}, []);

if (viewType === FieldStatsInitializerViewType.DATA_VIEW && !dataViews) {
return (
<EuiEmptyPrompt
color="primary"
title={
<h3>
<FormattedMessage
id="xpack.dataVisualizer.dashboard.fieldStats.noDataViewSelected"
defaultMessage="No data view selected"
/>
</h3>
}
body={
<p>
<FormattedMessage
id="xpack.dataVisualizer.dashboard.fieldStats.noDataViewSelectedDescription"
defaultMessage="Pick a data view to view field statistics."
/>
</p>
}
/>
);
}

if (isEsqlMode && !isEsqlEnabled) {
return (
<EuiFlexItem css={statsTableCss} data-test-subj="dashboardFieldStatsEmbeddedContent">
<EuiCallOut
title={
<h3>
<FormattedMessage
id="xpack.dataVisualizer.fieldStats.noDataViewSelected"
defaultMessage="ES|QL is disabled"
/>
</h3>
}
color="warning"
iconType="alert"
/>
</EuiFlexItem>
);
}

return (
<EuiFlexItem css={statsTableCss} data-test-subj="dashboardFieldStatsEmbeddedContent">
<FieldStatisticsWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const FieldStatisticsInitializer: FC<FieldStatsInitializerProps> = ({
defaultMessage: 'Data view',
}
)}
css={css({ padding: euiThemeVars.euiSizeM })}
>
<IndexPatternSelect
autoFocus={!dataViewId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ import type { AggregateQuery } from '@kbn/es-query';
import type { StateComparators } from '@kbn/presentation-publishing';
import { BehaviorSubject } from 'rxjs';
import fastIsEqual from 'fast-deep-equal';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import { ENABLE_ESQL } from '@kbn/esql-utils';
import { FieldStatsInitializerViewType } from '../grid_embeddable/types';
import type { FieldStatsInitialState } from '../grid_embeddable/types';
import type { FieldStatsControlsApi } from './types';

export const initializeFieldStatsControls = (rawState: FieldStatsInitialState) => {
export const initializeFieldStatsControls = (
rawState: FieldStatsInitialState,
uiSettings: IUiSettingsClient
) => {
const isEsqlEnabled = uiSettings.get(ENABLE_ESQL);
const defaultType = isEsqlEnabled
? FieldStatsInitializerViewType.ESQL
: FieldStatsInitializerViewType.DATA_VIEW;
const viewType$ = new BehaviorSubject<FieldStatsInitializerViewType | undefined>(
rawState.viewType ?? FieldStatsInitializerViewType.ESQL
rawState.viewType ?? defaultType
);
const dataViewId$ = new BehaviorSubject<string | undefined>(rawState.dataViewId);
const query$ = new BehaviorSubject<AggregateQuery | undefined>(rawState.query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import React from 'react';
import { isDefined } from '@kbn/ml-is-defined';
import { COMMON_VISUALIZATION_GROUPING } from '@kbn/visualizations-plugin/public';
import { ENABLE_ESQL } from '@kbn/esql-utils';
import { FIELD_STATS_EMBEDDABLE_TYPE } from '../embeddables/field_stats/constants';
import type { DataVisualizerStartDependencies } from '../../common/types/data_visualizer_plugin';
import type {
Expand Down Expand Up @@ -139,22 +140,31 @@ export function createAddFieldStatsTableAction(
i18n.translate('xpack.dataVisualizer.fieldStatistics.displayName', {
defaultMessage: 'Field statistics',
}),
disabled: !coreStart.uiSettings.get(ENABLE_ESQL),
async isCompatible(context: EmbeddableApiContext) {
return Boolean(await parentApiIsCompatible(context.embeddable));
return (
Boolean(await parentApiIsCompatible(context.embeddable)) &&
coreStart.uiSettings.get(ENABLE_ESQL)
);
},
async execute(context) {
const presentationContainerParent = await parentApiIsCompatible(context.embeddable);
if (!presentationContainerParent) throw new IncompatibleActionError();

const isEsqlEnabled = coreStart.uiSettings.get(ENABLE_ESQL);
try {
const defaultIndexPattern = await pluginStart.data.dataViews.getDefault();
const defaultInitialState: FieldStatsInitialState = {
viewType: FieldStatsInitializerViewType.ESQL,
query: {
// Initial default query
esql: `from ${defaultIndexPattern?.getIndexPattern()} | limit 10`,
},
};
const defaultInitialState: FieldStatsInitialState = isEsqlEnabled
? {
viewType: FieldStatsInitializerViewType.ESQL,
query: {
// Initial default query
esql: `from ${defaultIndexPattern?.getIndexPattern()} | limit 10`,
},
}
: {
viewType: FieldStatsInitializerViewType.DATA_VIEW,
};
const embeddable = await presentationContainerParent.addNewPanel<
object,
FieldStatisticsTableEmbeddableApi
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/data_visualizer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"@kbn/core-lifecycle-browser",
"@kbn/presentation-containers",
"@kbn/react-kibana-mount",
"@kbn/visualizations-plugin"
"@kbn/visualizations-plugin",
"@kbn/core-ui-settings-browser"
],
"exclude": [
"target/**/*",
Expand Down
Loading

0 comments on commit 1acb27e

Please sign in to comment.