From 2195c287629c8b1abc63176bfb005071cad12d8f Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:24:04 +1100 Subject: [PATCH 01/33] =?UTF-8?q?[8.x]=20[Discover]=20Use=20summary=20colu?= =?UTF-8?q?mn=20service=20name=20component=20for=20service=20name=E2=80=A6?= =?UTF-8?q?=20(#196742)=20(#197228)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[Discover] Use summary column service name component for service name… (#196742)](https://github.com/elastic/kibana/pull/196742) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: mohamedhamed-ahmed --- .../logs/service_name_cell.test.tsx | 51 +++++++++++++------ .../data_types/logs/service_name_cell.tsx | 41 ++++++++------- .../accessors/get_cell_renderers.tsx | 4 +- .../extensions/_get_cell_renderers.ts | 20 +++++--- .../extensions/_get_cell_renderers.ts | 20 +++++--- 5 files changed, 90 insertions(+), 46 deletions(-) diff --git a/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx b/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx index 8cf45be4f09e5..3171c5e61e629 100644 --- a/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx +++ b/src/plugins/discover/public/components/data_types/logs/service_name_cell.test.tsx @@ -7,15 +7,46 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import React from 'react'; import { buildDataTableRecord, DataTableRecord } from '@kbn/discover-utils'; import { dataViewMock } from '@kbn/discover-utils/src/__mocks__'; import { fieldFormatsMock } from '@kbn/field-formats-plugin/common/mocks'; import { render, screen } from '@testing-library/react'; -import React from 'react'; +import { DataGridDensity, ROWS_HEIGHT_OPTIONS } from '@kbn/unified-data-table'; import { getServiceNameCell } from './service_name_cell'; +import { CellRenderersExtensionParams } from '../../../context_awareness'; + +const core = { + application: { + capabilities: { + apm: { + show: true, + }, + }, + }, + uiSettings: { + get: () => true, + }, +}; + +jest.mock('../../../hooks/use_discover_services', () => { + const originalModule = jest.requireActual('../../../hooks/use_discover_services'); + return { + ...originalModule, + useDiscoverServices: () => ({ core, share: {} }), + }; +}); const renderCell = (serviceNameField: string, record: DataTableRecord) => { - const ServiceNameCell = getServiceNameCell(serviceNameField); + const cellRenderersExtensionParamsMock: CellRenderersExtensionParams = { + actions: { + addFilter: jest.fn(), + }, + dataView: dataViewMock, + density: DataGridDensity.COMPACT, + rowHeight: ROWS_HEIGHT_OPTIONS.single, + }; + const ServiceNameCell = getServiceNameCell(serviceNameField, cellRenderersExtensionParamsMock); render( { dataViewMock ); renderCell('service.name', record); - expect(screen.getByTestId('serviceNameCell-nodejs')).toBeInTheDocument(); - }); - - it('renders default icon with unknwon test subject if agent name is missing', () => { - const record = buildDataTableRecord( - { fields: { 'service.name': 'test-service' } }, - dataViewMock - ); - renderCell('service.name', record); - expect(screen.getByTestId('serviceNameCell-unknown')).toBeInTheDocument(); + expect(screen.getByTestId('dataTableCellActionsPopover_service.name')).toBeInTheDocument(); }); - it('does not render if service name is missing', () => { + it('does render empty div if service name is missing', () => { const record = buildDataTableRecord({ fields: { 'agent.name': 'nodejs' } }, dataViewMock); renderCell('service.name', record); - expect(screen.queryByTestId('serviceNameCell-nodejs')).not.toBeInTheDocument(); - expect(screen.queryByTestId('serviceNameCell-unknown')).not.toBeInTheDocument(); + expect(screen.queryByTestId('serviceNameCell-empty')).toBeInTheDocument(); }); }); diff --git a/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx b/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx index 39d112de5258e..cd94cd609dc69 100644 --- a/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx +++ b/src/plugins/discover/public/components/data_types/logs/service_name_cell.tsx @@ -7,19 +7,27 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; +import React from 'react'; +import { EuiToolTip } from '@elastic/eui'; import type { AgentName } from '@kbn/elastic-agent-utils'; import { dynamic } from '@kbn/shared-ux-utility'; import type { DataGridCellValueElementProps } from '@kbn/unified-data-table'; -import React from 'react'; +import { css } from '@emotion/react'; import { getFieldValue } from '@kbn/discover-utils'; +import { euiThemeVars } from '@kbn/ui-theme'; +import { CellRenderersExtensionParams } from '../../../context_awareness'; import { AGENT_NAME_FIELD } from '../../../../common/data_types/logs/constants'; +import { ServiceNameBadgeWithActions } from './service_name_badge_with_actions'; -const dataTestSubj = 'serviceNameCell'; const AgentIcon = dynamic(() => import('@kbn/custom-icons/src/components/agent_icon')); +const dataTestSubj = 'serviceNameCell'; +const agentIconStyle = css` + margin-right: ${euiThemeVars.euiSizeXS}; +`; export const getServiceNameCell = - (serviceNameField: string) => (props: DataGridCellValueElementProps) => { + (serviceNameField: string, { actions }: CellRenderersExtensionParams) => + (props: DataGridCellValueElementProps) => { const serviceNameValue = getFieldValue(props.row, serviceNameField) as string; const agentName = getFieldValue(props.row, AGENT_NAME_FIELD) as AgentName; @@ -27,19 +35,18 @@ export const getServiceNameCell = return -; } + const getIcon = () => ( + + + + ); + return ( - - - - - - - {serviceNameValue} - + ); }; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx index 9e45892070120..7e13baf8ddcf9 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx @@ -31,8 +31,8 @@ export const getCellRenderers: DataSourceProfileProvider['profile']['getCellRend ...SERVICE_NAME_FIELDS.reduce( (acc, field) => ({ ...acc, - [field]: getServiceNameCell(field), - [`${field}.keyword`]: getServiceNameCell(`${field}.keyword`), + [field]: getServiceNameCell(field, params), + [`${field}.keyword`]: getServiceNameCell(`${field}.keyword`, params), }), {} ), diff --git a/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts b/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts index cb66afc7ebc57..e18f6c5860dd2 100644 --- a/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts +++ b/test/functional/apps/discover/context_awareness/extensions/_get_cell_renderers.ts @@ -105,8 +105,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); const lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 0); - const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); - const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + const firstServiceNameCell = await firstCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); + const lastServiceNameCell = await lastCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); expect(await firstServiceNameCell.getVisibleText()).to.be('product'); expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); }); @@ -130,7 +134,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); expect(await firstCell.getVisibleText()).to.be('product'); - await testSubjects.missingOrFail('*serviceNameCell*'); + await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name'); }); }); }); @@ -278,8 +282,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1); - const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); - const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + const firstServiceNameCell = await firstCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); + const lastServiceNameCell = await lastCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); expect(await firstServiceNameCell.getVisibleText()).to.be('product'); expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); }); @@ -309,7 +317,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { expect(await firstCell.getVisibleText()).to.be('product'); expect(await lastCell.getVisibleText()).to.be('accounting'); - await testSubjects.missingOrFail('*serviceNameCell*'); + await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name'); }); }); }); diff --git a/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts b/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts index 0cf8aeedd257a..b8503e0f8dcab 100644 --- a/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts +++ b/x-pack/test_serverless/functional/test_suites/common/discover/context_awareness/extensions/_get_cell_renderers.ts @@ -105,8 +105,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); const lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 0); - const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); - const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + const firstServiceNameCell = await firstCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); + const lastServiceNameCell = await lastCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); expect(await firstServiceNameCell.getVisibleText()).to.be('product'); expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); }); @@ -130,7 +134,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0); expect(await firstCell.getVisibleText()).to.be('product'); - await testSubjects.missingOrFail('*serviceNameCell*'); + await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name'); }); }); }); @@ -277,8 +281,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1); lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1); - const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java'); - const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown'); + const firstServiceNameCell = await firstCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); + const lastServiceNameCell = await lastCell.findByTestSubject( + 'dataTableCellActionsPopover_service.name' + ); expect(await firstServiceNameCell.getVisibleText()).to.be('product'); expect(await lastServiceNameCell.getVisibleText()).to.be('accounting'); }); @@ -308,7 +316,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { expect(await firstCell.getVisibleText()).to.be('product'); expect(await lastCell.getVisibleText()).to.be('accounting'); - await testSubjects.missingOrFail('*serviceNameCell*'); + await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name'); }); }); }); From 34fb0f04d397d0e2b40dfda6a88fb2cac5300d58 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:48:12 +1100 Subject: [PATCH 02/33] [8.x] [Fleet] Improve space selector validation when not providing valid space (#197117) (#197224) # Backport This will backport the following commits from `main` to `8.x`: - [[Fleet] Improve space selector validation when not providing valid space (#197117)](https://github.com/elastic/kibana/pull/197117) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Nicolas Chaulet --- .../agent_policy_advanced_fields/index.tsx | 43 ++++----- .../space_selector.test.tsx | 90 +++++++++++++++++++ .../space_selector.tsx | 61 +++++++++---- .../components/agent_policy_form.tsx | 10 ++- .../components/settings/index.tsx | 8 +- .../components/create_agent_policy.tsx | 10 ++- 6 files changed, 176 insertions(+), 46 deletions(-) create mode 100644 x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/space_selector.test.tsx diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx index 1497b1bb0589e..6b0a7c512d197 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx @@ -53,7 +53,7 @@ import { UninstallCommandFlyout } from '../../../../../../components'; import type { ValidationResults } from '../agent_policy_validation'; import { ExperimentalFeaturesService } from '../../../../services'; - +import { useAgentPolicyFormContext } from '../agent_policy_form'; import { policyHasEndpointSecurity as hasElasticDefend } from '../../../../../../../common/services'; import { @@ -127,6 +127,8 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent = const isManagedorAgentlessPolicy = agentPolicy.is_managed === true || agentPolicy?.supports_agentless === true; + const agentPolicyFormContect = useAgentPolicyFormContext(); + const AgentTamperProtectionSectionContent = useMemo( () => ( = /> } > - - { + if (newValue.length === 0) { + return; } - onChange={(newValue) => { - if (newValue.length === 0) { - return; - } - updateAgentPolicy({ - space_ids: newValue, - }); - }} - /> - + updateAgentPolicy({ + space_ids: newValue, + }); + }} + /> ) : null} { + beforeEach(() => { + jest.mocked(useAgentPoliciesSpaces).mockReturnValue({ + data: { + items: [ + { + name: 'Default', + id: 'default', + }, + { + name: 'Test', + id: 'test', + }, + ], + }, + } as any); + }); + function render() { + const renderer = createFleetTestRendererMock(); + const onChange = jest.fn(); + const setInvalidSpaceError = jest.fn(); + const result = renderer.render( + + ); + + return { + result, + onChange, + setInvalidSpaceError, + }; + } + + it('should render invalid space errors', () => { + const { result, onChange, setInvalidSpaceError } = render(); + const inputEl = result.getByTestId('comboBoxSearchInput'); + fireEvent.change(inputEl, { + target: { value: 'invalidSpace' }, + }); + fireEvent.keyDown(inputEl, { key: 'Enter', code: 'Enter' }); + expect(result.container).toHaveTextContent('invalidSpace is not a valid space.'); + expect(onChange).not.toBeCalled(); + expect(setInvalidSpaceError).toBeCalledWith(true); + }); + + it('should clear invalid space errors', () => { + const { result, setInvalidSpaceError } = render(); + const inputEl = result.getByTestId('comboBoxSearchInput'); + fireEvent.change(inputEl, { + target: { value: 'invalidSpace' }, + }); + fireEvent.keyDown(inputEl, { key: 'Enter', code: 'Enter' }); + expect(result.container).toHaveTextContent('invalidSpace is not a valid space.'); + fireEvent.change(inputEl, { + target: { value: '' }, + }); + fireEvent.keyDown(inputEl, { key: 'Enter', code: 'Enter' }); + expect(result.container).not.toHaveTextContent('invalidSpace is not a valid space.'); + expect(setInvalidSpaceError).toBeCalledWith(false); + }); + + it('should accept valid space', () => { + const { result, onChange, setInvalidSpaceError } = render(); + const inputEl = result.getByTestId('comboBoxSearchInput'); + fireEvent.change(inputEl, { + target: { value: 'test' }, + }); + fireEvent.keyDown(inputEl, { key: 'Enter', code: 'Enter' }); + expect(result.container).not.toHaveTextContent('test is not a valid space.'); + expect(onChange).toBeCalledWith(['test']); + expect(setInvalidSpaceError).not.toBeCalledWith(true); + }); +}); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/space_selector.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/space_selector.tsx index 0532c5306d50f..53c7ed1d8226d 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/space_selector.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/space_selector.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { type EuiComboBoxOptionOption, EuiHealth } from '@elastic/eui'; +import { type EuiComboBoxOptionOption, EuiHealth, EuiFormRow } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React, { useMemo } from 'react'; @@ -16,11 +16,19 @@ export interface SpaceSelectorProps { value: string[]; onChange: (newVal: string[]) => void; isDisabled?: boolean; + setInvalidSpaceError?: (hasError: boolean) => void; } -export const SpaceSelector: React.FC = ({ value, onChange, isDisabled }) => { +export const SpaceSelector: React.FC = ({ + setInvalidSpaceError, + value, + onChange, + isDisabled, +}) => { const res = useAgentPoliciesSpaces(); + const [error, setError] = React.useState(); + const renderOption = React.useCallback( (option: any, searchValue: string, contentClassName: string) => ( @@ -57,20 +65,41 @@ export const SpaceSelector: React.FC = ({ value, onChange, i }, [options, value, res.isInitialLoading]); return ( - { - onChange(newOptions.map(({ key }) => key as string)); - }} - /> + key="space" + error={error} + isDisabled={isDisabled} + isInvalid={Boolean(error)} + > + { + const newError = + searchValue.length === 0 || hasMatchingOptions + ? undefined + : i18n.translate('xpack.fleet.agentPolicies.spaceSelectorInvalid', { + defaultMessage: '{space} is not a valid space.', + values: { space: searchValue }, + }); + setError(newError); + if (setInvalidSpaceError) { + setInvalidSpaceError(!!newError); + } + }} + onChange={(newOptions) => { + onChange(newOptions.map(({ key }) => key as string)); + }} + /> + ); }; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx index b437d61f64c58..8e97afcaa4d66 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx @@ -45,12 +45,14 @@ interface Props { isEditing?: boolean; // form error state is passed up to the form updateAdvancedSettingsHasErrors: (hasErrors: boolean) => void; + setInvalidSpaceError: (hasErrors: boolean) => void; } const AgentPolicyFormContext = React.createContext< | { agentPolicy: Partial & { [key: string]: any }; updateAgentPolicy: (u: Partial) => void; updateAdvancedSettingsHasErrors: (hasErrors: boolean) => void; + setInvalidSpaceError: (hasErrors: boolean) => void; } | undefined >(undefined); @@ -67,6 +69,7 @@ export const AgentPolicyForm: React.FunctionComponent = ({ validation, isEditing = false, updateAdvancedSettingsHasErrors, + setInvalidSpaceError, }) => { const authz = useAuthz(); const isDisabled = !authz.fleet.allAgentPolicies; @@ -97,7 +100,12 @@ export const AgentPolicyForm: React.FunctionComponent = ({ return ( {!isEditing ? ( diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx index 6e4f1e06b45a0..91cd710db4343 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx @@ -90,6 +90,7 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>( allowedNamespacePrefixes: spaceSettings?.allowedNamespacePrefixes, }); const [hasAdvancedSettingsErrors, setHasAdvancedSettingsErrors] = useState(false); + const [hasInvalidSpaceError, setInvalidSpaceError] = useState(false); const updateAgentPolicy = (updatedFields: Partial) => { setAgentPolicy({ @@ -183,6 +184,7 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>( validation={validation} isEditing={true} updateAdvancedSettingsHasErrors={setHasAdvancedSettingsErrors} + setInvalidSpaceError={setInvalidSpaceError} /> {hasChanges ? ( @@ -219,7 +221,8 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>( isDisabled={ isLoading || Object.keys(validation).length > 0 || - hasAdvancedSettingsErrors + hasAdvancedSettingsErrors || + hasInvalidSpaceError } btnProps={{ color: 'text', @@ -242,7 +245,8 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>( !hasAllAgentPoliciesPrivileges || isLoading || Object.keys(validation).length > 0 || - hasAdvancedSettingsErrors + hasAdvancedSettingsErrors || + hasInvalidSpaceError } data-test-subj="agentPolicyDetailsSaveButton" iconType="save" diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/list_page/components/create_agent_policy.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/list_page/components/create_agent_policy.tsx index f147f7e112ea1..a5538e7e0fa30 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/list_page/components/create_agent_policy.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/list_page/components/create_agent_policy.tsx @@ -61,6 +61,7 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent = ({ allowedNamespacePrefixes: spaceSettings?.allowedNamespacePrefixes, }); const [hasAdvancedSettingsErrors, setHasAdvancedSettingsErrors] = useState(false); + const [hasInvalidSpaceError, setInvalidSpaceError] = useState(false); const updateAgentPolicy = (updatedFields: Partial) => { setAgentPolicy({ @@ -104,6 +105,7 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent = ({ updateSysMonitoring={(newValue) => setWithSysMonitoring(newValue)} validation={validation} updateAdvancedSettingsHasErrors={setHasAdvancedSettingsErrors} + setInvalidSpaceError={setInvalidSpaceError} /> ); @@ -130,7 +132,10 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent = ({ 0 || hasAdvancedSettingsErrors + isLoading || + Object.keys(validation).length > 0 || + hasAdvancedSettingsErrors || + hasInvalidSpaceError } description={i18n.translate( 'xpack.fleet.createAgentPolicy.devtoolsRequestDescription', @@ -150,7 +155,8 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent = ({ !hasFleetAllAgentPoliciesPrivileges || isLoading || Object.keys(validation).length > 0 || - hasAdvancedSettingsErrors + hasAdvancedSettingsErrors || + hasInvalidSpaceError } onClick={async () => { setIsLoading(true); From d6df65e96983c8f6aa91a477513b86580afe8b0b Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:51:38 +1100 Subject: [PATCH 03/33] [8.x] [Dataset Quality] Check if Obs Logs Explorer accessible before linking Logs Explorer (#197020) (#197235) # Backport This will backport the following commits from `main` to `8.x`: - [[Dataset Quality] Check if Obs Logs Explorer accessible before linking Logs Explorer (#197020)](https://github.com/elastic/kibana/pull/197020) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Abdul Wahab Zahid --- .../public/hooks/use_redirect_link.ts | 21 +++++++++++++++++-- .../dataset_quality/tsconfig.json | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts b/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts index 638af464a87cd..d1e55d488ba5c 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts @@ -5,8 +5,12 @@ * 2.0. */ +import { map } from 'rxjs'; import { useMemo } from 'react'; +import useObservable from 'react-use/lib/useObservable'; +import { AppStatus } from '@kbn/core-application-browser'; import { + OBSERVABILITY_LOGS_EXPLORER_APP_ID, SINGLE_DATASET_LOCATOR_ID, SingleDatasetLocatorParams, } from '@kbn/deeplinks-observability'; @@ -34,7 +38,7 @@ export const useRedirectLink = ({ sendTelemetry: SendTelemetryFn; }) => { const { - services: { share }, + services: { share, application }, } = useKibanaContextForPlugin(); const { from, to } = timeRangeConfig; @@ -42,12 +46,24 @@ export const useRedirectLink = ({ const logsExplorerLocator = share.url.locators.get(SINGLE_DATASET_LOCATOR_ID); + const isLogsExplorerAppAccessible = useObservable( + application.applications$.pipe( + map( + (apps) => + (apps.get(OBSERVABILITY_LOGS_EXPLORER_APP_ID)?.status ?? AppStatus.inaccessible) === + AppStatus.accessible + ) + ), + false + ); + return useMemo<{ linkProps: RouterLinkProps; navigate: () => void; isLogsExplorerAvailable: boolean; }>(() => { - const isLogsExplorerAvailable = !!logsExplorerLocator && dataStreamStat.type === 'logs'; + const isLogsExplorerAvailable = + isLogsExplorerAppAccessible && !!logsExplorerLocator && dataStreamStat.type === 'logs'; const config = isLogsExplorerAvailable ? buildLogsExplorerConfig({ locator: logsExplorerLocator, @@ -95,6 +111,7 @@ export const useRedirectLink = ({ query, sendTelemetry, share.url.locators, + isLogsExplorerAppAccessible, ]); }; diff --git a/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json b/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json index 934c0e434d9a5..f0d82fadb54ad 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json +++ b/x-pack/plugins/observability_solution/dataset_quality/tsconfig.json @@ -59,7 +59,8 @@ "@kbn/telemetry-plugin", "@kbn/usage-collection-plugin", "@kbn/rison", - "@kbn/task-manager-plugin" + "@kbn/task-manager-plugin", + "@kbn/core-application-browser" ], "exclude": [ "target/**/*" From 6c8699f6b5473fe370af24f779f589ae1c54aca5 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 02:07:34 +1100 Subject: [PATCH 04/33] [8.x] Make sort integration test resilient to network delays. (#196516) (#197237) # Backport This will backport the following commits from `main` to `8.x`: - [Make sort integration test resilient to network delays. (#196516)](https://github.com/elastic/kibana/pull/196516) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Abdul Wahab Zahid --- .../data_source_selector.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/test_serverless/functional/test_suites/observability/observability_logs_explorer/data_source_selector.ts b/x-pack/test_serverless/functional/test_suites/observability/observability_logs_explorer/data_source_selector.ts index f571fe4e0e462..ba12ebc153ca8 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/observability_logs_explorer/data_source_selector.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/observability_logs_explorer/data_source_selector.ts @@ -214,25 +214,25 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('should sort the integrations list by the clicked sorting option', async () => { // Test ascending order - await PageObjects.observabilityLogsExplorer.clickSortButtonBy('asc'); - await retry.try(async () => { + await PageObjects.observabilityLogsExplorer.clickSortButtonBy('desc'); + await PageObjects.observabilityLogsExplorer.clickSortButtonBy('asc'); const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations(); expect(integrations).to.eql(initialPackagesTexts); }); // Test descending order - await PageObjects.observabilityLogsExplorer.clickSortButtonBy('desc'); - await retry.try(async () => { + await PageObjects.observabilityLogsExplorer.clickSortButtonBy('asc'); + await PageObjects.observabilityLogsExplorer.clickSortButtonBy('desc'); const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations(); expect(integrations).to.eql(initialPackagesTexts.slice().reverse()); }); // Test back ascending order - await PageObjects.observabilityLogsExplorer.clickSortButtonBy('asc'); - await retry.try(async () => { + await PageObjects.observabilityLogsExplorer.clickSortButtonBy('desc'); + await PageObjects.observabilityLogsExplorer.clickSortButtonBy('asc'); const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations(); expect(integrations).to.eql(initialPackagesTexts); }); From 8c9852ae917942b214d8b062b2ba510471d31c44 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 02:16:10 +1100 Subject: [PATCH 05/33] [8.x] [RCA] Events timeline improvements (#197127) (#197240) # Backport This will backport the following commits from `main` to `8.x`: - [[RCA] Events timeline improvements (#197127)](https://github.com/elastic/kibana/pull/197127) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Bena Kansara <69037875+benakansara@users.noreply.github.com> --- .../public/hooks/query_key_factory.ts | 4 ++-- .../investigate_app/public/hooks/use_fetch_events.ts | 5 ++++- .../components/events_timeline/events_timeline.tsx | 12 ++++++++++++ .../investigate_app/server/services/get_events.ts | 2 +- .../investigate_app/tsconfig.json | 1 + .../public/utils/investigation_item_helper.ts | 12 +++++++++--- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/observability_solution/investigate_app/public/hooks/query_key_factory.ts b/x-pack/plugins/observability_solution/investigate_app/public/hooks/query_key_factory.ts index 0b625c5681bcb..38e4c90aebe09 100644 --- a/x-pack/plugins/observability_solution/investigate_app/public/hooks/query_key_factory.ts +++ b/x-pack/plugins/observability_solution/investigate_app/public/hooks/query_key_factory.ts @@ -12,8 +12,8 @@ export const investigationKeys = { userProfiles: (profileIds: Set) => [...investigationKeys.all, 'userProfiles', ...profileIds] as const, tags: () => [...investigationKeys.all, 'tags'] as const, - events: (rangeFrom?: string, rangeTo?: string) => - [...investigationKeys.all, 'events', rangeFrom, rangeTo] as const, + events: (rangeFrom?: string, rangeTo?: string, filter?: string) => + [...investigationKeys.all, 'events', rangeFrom, rangeTo, filter] as const, stats: () => [...investigationKeys.all, 'stats'] as const, lists: () => [...investigationKeys.all, 'list'] as const, list: (params: { page: number; perPage: number; search?: string; filter?: string }) => diff --git a/x-pack/plugins/observability_solution/investigate_app/public/hooks/use_fetch_events.ts b/x-pack/plugins/observability_solution/investigate_app/public/hooks/use_fetch_events.ts index 61b0c441c1fc2..5b885fc664b13 100644 --- a/x-pack/plugins/observability_solution/investigate_app/public/hooks/use_fetch_events.ts +++ b/x-pack/plugins/observability_solution/investigate_app/public/hooks/use_fetch_events.ts @@ -23,9 +23,11 @@ export interface Response { export function useFetchEvents({ rangeFrom, rangeTo, + filter, }: { rangeFrom?: string; rangeTo?: string; + filter?: string; }): Response { const { core: { @@ -35,12 +37,13 @@ export function useFetchEvents({ } = useKibana(); const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({ - queryKey: investigationKeys.events(rangeFrom, rangeTo), + queryKey: investigationKeys.events(rangeFrom, rangeTo, filter), queryFn: async ({ signal }) => { return await http.get(`/api/observability/events`, { query: { rangeFrom, rangeTo, + filter, }, version: '2023-10-31', signal, diff --git a/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/events_timeline/events_timeline.tsx b/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/events_timeline/events_timeline.tsx index 70f4159924bd1..befa50bcc0e8d 100644 --- a/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/events_timeline/events_timeline.tsx +++ b/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/events_timeline/events_timeline.tsx @@ -11,6 +11,9 @@ import { Chart, Axis, AreaSeries, Position, ScaleType, Settings } from '@elastic import { useActiveCursor } from '@kbn/charts-plugin/public'; import { EuiSkeletonText } from '@elastic/eui'; import { getBrushData } from '@kbn/observability-utils/chart/utils'; +import { Group } from '@kbn/observability-alerting-rule-utils'; +import { ALERT_GROUP } from '@kbn/rule-data-utils'; +import { SERVICE_NAME } from '@kbn/observability-shared-plugin/common'; import { AnnotationEvent } from './annotation_event'; import { TIME_LINE_THEME } from './timeline_theme'; import { useFetchEvents } from '../../../../hooks/use_fetch_events'; @@ -24,10 +27,19 @@ export const EventsTimeLine = () => { const baseTheme = dependencies.start.charts.theme.useChartsBaseTheme(); const { globalParams, updateInvestigationParams } = useInvestigation(); + const { alert } = useInvestigation(); + + const filter = useMemo(() => { + const group = (alert?.[ALERT_GROUP] as unknown as Group[])?.find( + ({ field }) => field === SERVICE_NAME + ); + return group ? `{"${SERVICE_NAME}":"${alert?.[SERVICE_NAME]}"}` : ''; + }, [alert]); const { data: events, isLoading } = useFetchEvents({ rangeFrom: globalParams.timeRange.from, rangeTo: globalParams.timeRange.to, + filter, }); const chartRef = useRef(null); diff --git a/x-pack/plugins/observability_solution/investigate_app/server/services/get_events.ts b/x-pack/plugins/observability_solution/investigate_app/server/services/get_events.ts index 6b081f51dfee8..53f42f4c6c057 100644 --- a/x-pack/plugins/observability_solution/investigate_app/server/services/get_events.ts +++ b/x-pack/plugins/observability_solution/investigate_app/server/services/get_events.ts @@ -95,7 +95,7 @@ export async function getAlertEvents( id: _source[ALERT_UUID], title: `${_source[ALERT_RULE_CATEGORY]} breached`, description: _source[ALERT_REASON], - timestamp: new Date(_source['@timestamp']).getTime(), + timestamp: new Date(_source[ALERT_START] as string).getTime(), eventType: 'alert', alertStatus: _source[ALERT_STATUS], }; diff --git a/x-pack/plugins/observability_solution/investigate_app/tsconfig.json b/x-pack/plugins/observability_solution/investigate_app/tsconfig.json index 7ea8234fba670..a853456b1156c 100644 --- a/x-pack/plugins/observability_solution/investigate_app/tsconfig.json +++ b/x-pack/plugins/observability_solution/investigate_app/tsconfig.json @@ -68,5 +68,6 @@ "@kbn/ml-random-sampler-utils", "@kbn/charts-plugin", "@kbn/observability-utils", + "@kbn/observability-alerting-rule-utils", ], } diff --git a/x-pack/plugins/observability_solution/observability/public/utils/investigation_item_helper.ts b/x-pack/plugins/observability_solution/observability/public/utils/investigation_item_helper.ts index cddf3290ed370..91bfcd2ab4bb1 100644 --- a/x-pack/plugins/observability_solution/observability/public/utils/investigation_item_helper.ts +++ b/x-pack/plugins/observability_solution/observability/public/utils/investigation_item_helper.ts @@ -24,9 +24,15 @@ const genLensEqForCustomThresholdRule = (criterion: MetricExpression) => { criterion.metrics.forEach((metric: CustomThresholdExpressionMetric) => { const metricFilter = metric.filter ? `kql='${metric.filter}'` : ''; - metricNameResolver[metric.name] = `${ - AggMappingForLens[metric.aggType] ? AggMappingForLens[metric.aggType] : metric.aggType - }(${metric.field ? metric.field : metricFilter})`; + if (metric.aggType === 'rate') { + metricNameResolver[metric.name] = `counter_rate(max(${ + metric.field ? metric.field : metricFilter + }))`; + } else { + metricNameResolver[metric.name] = `${ + AggMappingForLens[metric.aggType] ? AggMappingForLens[metric.aggType] : metric.aggType + }(${metric.field ? metric.field : metricFilter})`; + } }); let equation = criterion.equation From 5ececbb7650a9a6ce8b588e93673b4565459432a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 02:24:37 +1100 Subject: [PATCH 06/33] [8.x] [Security Solution][Notes] - fix user filter not checking correct license in notes management page (#197149) (#197245) # Backport This will backport the following commits from `main` to `8.x`: - [[Security Solution][Notes] - fix user filter not checking correct license in notes management page (#197149)](https://github.com/elastic/kibana/pull/197149) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Philippe Oberti --- .../upselling/messages/index.tsx | 8 ++ .../upselling/service/types.ts | 3 +- .../user_profiles/use_suggest_users.tsx | 21 +++-- .../notes/components/search_row.test.tsx | 33 ++++---- .../public/notes/components/search_row.tsx | 44 ++--------- .../components/user_filter_dropdown.test.tsx | 69 ++++++++++++++++ .../notes/components/user_filter_dropdown.tsx | 79 +++++++++++++++++++ .../public/upselling/register_upsellings.tsx | 6 ++ 8 files changed, 202 insertions(+), 61 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/notes/components/user_filter_dropdown.test.tsx create mode 100644 x-pack/plugins/security_solution/public/notes/components/user_filter_dropdown.tsx diff --git a/x-pack/packages/security-solution/upselling/messages/index.tsx b/x-pack/packages/security-solution/upselling/messages/index.tsx index 722a711995d01..4bda9477f13c0 100644 --- a/x-pack/packages/security-solution/upselling/messages/index.tsx +++ b/x-pack/packages/security-solution/upselling/messages/index.tsx @@ -46,3 +46,11 @@ export const ALERT_SUPPRESSION_RULE_DETAILS = i18n.translate( 'Alert suppression is configured but will not be applied due to insufficient licensing', } ); + +export const UPGRADE_NOTES_MANAGEMENT_USER_FILTER = (requiredLicense: string) => + i18n.translate('securitySolutionPackages.noteManagement.userFilter.upsell', { + defaultMessage: 'Upgrade to {requiredLicense} to make use of user filters', + values: { + requiredLicense, + }, + }); diff --git a/x-pack/packages/security-solution/upselling/service/types.ts b/x-pack/packages/security-solution/upselling/service/types.ts index 43019271a7e02..b053c9aedf857 100644 --- a/x-pack/packages/security-solution/upselling/service/types.ts +++ b/x-pack/packages/security-solution/upselling/service/types.ts @@ -27,4 +27,5 @@ export type UpsellingMessageId = | 'investigation_guide_interactions' | 'alert_assignments' | 'alert_suppression_rule_form' - | 'alert_suppression_rule_details'; + | 'alert_suppression_rule_details' + | 'note_management_user_filter'; diff --git a/x-pack/plugins/security_solution/public/common/components/user_profiles/use_suggest_users.tsx b/x-pack/plugins/security_solution/public/common/components/user_profiles/use_suggest_users.tsx index a8a2338e51e9d..626d621f61a30 100644 --- a/x-pack/plugins/security_solution/public/common/components/user_profiles/use_suggest_users.tsx +++ b/x-pack/plugins/security_solution/public/common/components/user_profiles/use_suggest_users.tsx @@ -13,10 +13,6 @@ import { suggestUsers } from './api'; import { USER_PROFILES_FAILURE } from './translations'; import { useAppToasts } from '../../hooks/use_app_toasts'; -export interface SuggestUserProfilesArgs { - searchTerm: string; -} - export const bulkGetUserProfiles = async ({ searchTerm, }: { @@ -25,7 +21,21 @@ export const bulkGetUserProfiles = async ({ return suggestUsers({ searchTerm }); }; -export const useSuggestUsers = ({ searchTerm }: { searchTerm: string }) => { +export interface UseSuggestUsersParams { + /** + * Search term to filter user profiles + */ + searchTerm: string; + /** + * Whether the query should be enabled + */ + enabled?: boolean; +} + +/** + * Fetches user profiles based on a search term + */ +export const useSuggestUsers = ({ enabled = true, searchTerm }: UseSuggestUsersParams) => { const { addError } = useAppToasts(); return useQuery( @@ -36,6 +46,7 @@ export const useSuggestUsers = ({ searchTerm }: { searchTerm: string }) => { { retry: false, staleTime: Infinity, + enabled, onError: (e) => { addError(e, { title: USER_PROFILES_FAILURE }); }, diff --git a/x-pack/plugins/security_solution/public/notes/components/search_row.test.tsx b/x-pack/plugins/security_solution/public/notes/components/search_row.test.tsx index be9546c77525b..447ade158306b 100644 --- a/x-pack/plugins/security_solution/public/notes/components/search_row.test.tsx +++ b/x-pack/plugins/security_solution/public/notes/components/search_row.test.tsx @@ -5,13 +5,14 @@ * 2.0. */ -import { fireEvent, render, screen } from '@testing-library/react'; +import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import { SearchRow } from './search_row'; import { ASSOCIATED_NOT_SELECT_TEST_ID, SEARCH_BAR_TEST_ID, USER_SELECT_TEST_ID } from './test_ids'; import { AssociatedFilter } from '../../../common/notes/constants'; import { useSuggestUsers } from '../../common/components/user_profiles/use_suggest_users'; +import { TestProviders } from '../../common/mock'; jest.mock('../../common/components/user_profiles/use_suggest_users'); @@ -35,7 +36,11 @@ describe('SearchRow', () => { }); it('should render the component', () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + + + ); expect(getByTestId(SEARCH_BAR_TEST_ID)).toBeInTheDocument(); expect(getByTestId(USER_SELECT_TEST_ID)).toBeInTheDocument(); @@ -43,7 +48,11 @@ describe('SearchRow', () => { }); it('should call the correct action when entering a value in the search bar', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + + + ); const searchBox = getByTestId(SEARCH_BAR_TEST_ID); @@ -53,20 +62,12 @@ describe('SearchRow', () => { expect(mockDispatch).toHaveBeenCalled(); }); - it('should call the correct action when select a user', async () => { - const { getByTestId } = render(); - - const userSelect = getByTestId('comboBoxSearchInput'); - userSelect.focus(); - - const option = await screen.findByText('test'); - fireEvent.click(option); - - expect(mockDispatch).toHaveBeenCalled(); - }); - it('should call the correct action when select a value in the associated note dropdown', async () => { - const { getByTestId } = render(); + const { getByTestId } = render( + + + + ); const associatedNoteSelect = getByTestId(ASSOCIATED_NOT_SELECT_TEST_ID); await userEvent.selectOptions(associatedNoteSelect, [AssociatedFilter.documentOnly]); diff --git a/x-pack/plugins/security_solution/public/notes/components/search_row.tsx b/x-pack/plugins/security_solution/public/notes/components/search_row.tsx index d540a586814d8..f2f90b3ba7e0d 100644 --- a/x-pack/plugins/security_solution/public/notes/components/search_row.tsx +++ b/x-pack/plugins/security_solution/public/notes/components/search_row.tsx @@ -5,10 +5,9 @@ * 2.0. */ -import React, { useMemo, useCallback, useState } from 'react'; +import React, { useCallback } from 'react'; import type { EuiSelectOption } from '@elastic/eui'; import { - EuiComboBox, EuiFlexGroup, EuiFlexItem, EuiSearchBar, @@ -16,17 +15,12 @@ import { useGeneratedHtmlId, } from '@elastic/eui'; import { useDispatch } from 'react-redux'; -import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; import { i18n } from '@kbn/i18n'; -import type { EuiComboBoxOptionOption } from '@elastic/eui/src/components/combo_box/types'; -import { ASSOCIATED_NOT_SELECT_TEST_ID, SEARCH_BAR_TEST_ID, USER_SELECT_TEST_ID } from './test_ids'; -import { useSuggestUsers } from '../../common/components/user_profiles/use_suggest_users'; -import { userFilterAssociatedNotes, userFilterUsers, userSearchedNotes } from '..'; +import { UserFilterDropdown } from './user_filter_dropdown'; +import { ASSOCIATED_NOT_SELECT_TEST_ID, SEARCH_BAR_TEST_ID } from './test_ids'; +import { userFilterAssociatedNotes, userSearchedNotes } from '..'; import { AssociatedFilter } from '../../../common/notes/constants'; -export const USERS_DROPDOWN = i18n.translate('xpack.securitySolution.notes.usersDropdownLabel', { - defaultMessage: 'Users', -}); const FILTER_SELECT = i18n.translate('xpack.securitySolution.notes.management.filterSelect', { defaultMessage: 'Select filter', }); @@ -55,26 +49,6 @@ export const SearchRow = React.memo(() => { [dispatch] ); - const { isLoading: isLoadingSuggestedUsers, data: userProfiles } = useSuggestUsers({ - searchTerm: '', - }); - const users = useMemo( - () => - (userProfiles || []).map((userProfile: UserProfileWithAvatar) => ({ - label: userProfile.user.full_name || userProfile.user.username, - })), - [userProfiles] - ); - - const [selectedUser, setSelectedUser] = useState>>(); - const onChange = useCallback( - (user: Array>) => { - setSelectedUser(user); - dispatch(userFilterUsers(user.length > 0 ? user[0].label : '')); - }, - [dispatch] - ); - const onAssociatedNoteSelectChange = useCallback( (e: React.ChangeEvent) => { dispatch(userFilterAssociatedNotes(e.target.value as AssociatedFilter)); @@ -88,15 +62,7 @@ export const SearchRow = React.memo(() => { - + { + const original = jest.requireActual('react-redux'); + + return { + ...original, + useDispatch: () => mockDispatch, + }; +}); + +describe('UserFilterDropdown', () => { + beforeEach(() => { + jest.clearAllMocks(); + (useSuggestUsers as jest.Mock).mockReturnValue({ + isLoading: false, + data: [{ user: { username: 'test' } }, { user: { username: 'elastic' } }], + }); + (useLicense as jest.Mock).mockReturnValue({ isPlatinumPlus: () => true }); + (useUpsellingMessage as jest.Mock).mockReturnValue('upsellingMessage'); + }); + + it('should render the component enabled', () => { + const { getByTestId } = render(); + + const dropdown = getByTestId(USER_SELECT_TEST_ID); + + expect(dropdown).toBeInTheDocument(); + expect(dropdown).not.toHaveClass('euiComboBox-isDisabled'); + }); + + it('should render the dropdown disabled', async () => { + (useLicense as jest.Mock).mockReturnValue({ isPlatinumPlus: () => false }); + + const { getByTestId } = render(); + + expect(getByTestId(USER_SELECT_TEST_ID)).toHaveClass('euiComboBox-isDisabled'); + }); + + it('should call the correct action when select a user', async () => { + const { getByTestId } = render(); + + const userSelect = getByTestId('comboBoxSearchInput'); + userSelect.focus(); + + const option = await screen.findByText('test'); + fireEvent.click(option); + + expect(mockDispatch).toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/security_solution/public/notes/components/user_filter_dropdown.tsx b/x-pack/plugins/security_solution/public/notes/components/user_filter_dropdown.tsx new file mode 100644 index 0000000000000..78f4ef6dd2ac8 --- /dev/null +++ b/x-pack/plugins/security_solution/public/notes/components/user_filter_dropdown.tsx @@ -0,0 +1,79 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useMemo, useCallback, useState } from 'react'; +import { EuiComboBox, EuiToolTip } from '@elastic/eui'; +import { useDispatch } from 'react-redux'; +import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; +import { i18n } from '@kbn/i18n'; +import type { EuiComboBoxOptionOption } from '@elastic/eui/src/components/combo_box/types'; +import { useLicense } from '../../common/hooks/use_license'; +import { useUpsellingMessage } from '../../common/hooks/use_upselling'; +import { USER_SELECT_TEST_ID } from './test_ids'; +import { useSuggestUsers } from '../../common/components/user_profiles/use_suggest_users'; +import { userFilterUsers } from '..'; + +export const USERS_DROPDOWN = i18n.translate('xpack.securitySolution.notes.usersDropdownLabel', { + defaultMessage: 'Users', +}); + +export const UserFilterDropdown = React.memo(() => { + const dispatch = useDispatch(); + const isPlatinumPlus = useLicense().isPlatinumPlus(); + const upsellingMessage = useUpsellingMessage('note_management_user_filter'); + + const { isLoading, data } = useSuggestUsers({ + searchTerm: '', + enabled: isPlatinumPlus, + }); + const users = useMemo( + () => + (data || []).map((userProfile: UserProfileWithAvatar) => ({ + label: userProfile.user.full_name || userProfile.user.username, + })), + [data] + ); + + const [selectedUser, setSelectedUser] = useState>>(); + const onChange = useCallback( + (user: Array>) => { + setSelectedUser(user); + dispatch(userFilterUsers(user.length > 0 ? user[0].label : '')); + }, + [dispatch] + ); + + const dropdown = useMemo( + () => ( + + ), + [isLoading, isPlatinumPlus, onChange, selectedUser, users] + ); + + return ( + <> + {isPlatinumPlus ? ( + <>{dropdown} + ) : ( + + {dropdown} + + )} + + ); +}); + +UserFilterDropdown.displayName = 'UserFilterDropdown'; diff --git a/x-pack/plugins/security_solution_ess/public/upselling/register_upsellings.tsx b/x-pack/plugins/security_solution_ess/public/upselling/register_upsellings.tsx index b7fbdab3b5982..69f3c5dd4cc28 100644 --- a/x-pack/plugins/security_solution_ess/public/upselling/register_upsellings.tsx +++ b/x-pack/plugins/security_solution_ess/public/upselling/register_upsellings.tsx @@ -12,6 +12,7 @@ import { ALERT_SUPPRESSION_RULE_FORM, UPGRADE_ALERT_ASSIGNMENTS, UPGRADE_INVESTIGATION_GUIDE, + UPGRADE_NOTES_MANAGEMENT_USER_FILTER, } from '@kbn/security-solution-upselling/messages'; import type { MessageUpsellings, @@ -132,4 +133,9 @@ export const upsellingMessages: UpsellingMessages = [ minimumLicenseRequired: 'platinum', message: ALERT_SUPPRESSION_RULE_DETAILS, }, + { + id: 'note_management_user_filter', + minimumLicenseRequired: 'platinum', + message: UPGRADE_NOTES_MANAGEMENT_USER_FILTER('Platinum'), + }, ]; From 236d80072b8cfe2bd931f3d5fad943d9d98e6b81 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 03:32:53 +1100 Subject: [PATCH 07/33] [8.x] [ML] Forecast api delete test: add retry to ensure forecast has time to complete before deletion (#197111) (#197257) # Backport This will backport the following commits from `main` to `8.x`: - [[ML] Forecast api delete test: add retry to ensure forecast has time to complete before deletion (#197111)](https://github.com/elastic/kibana/pull/197111) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Melissa Alvarez --- .../anomaly_detectors/forecast_with_spaces.ts | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/x-pack/test/api_integration/apis/ml/anomaly_detectors/forecast_with_spaces.ts b/x-pack/test/api_integration/apis/ml/anomaly_detectors/forecast_with_spaces.ts index 32e82c67e348d..a6bc0b0c99a86 100644 --- a/x-pack/test/api_integration/apis/ml/anomaly_detectors/forecast_with_spaces.ts +++ b/x-pack/test/api_integration/apis/ml/anomaly_detectors/forecast_with_spaces.ts @@ -15,6 +15,7 @@ export default ({ getService }: FtrProviderContext) => { const supertest = getService('supertestWithoutAuth'); const ml = getService('ml'); const spacesService = getService('spaces'); + const retry = getService('retry'); const forecastJobId = 'fq_single_forecast'; const forecastJobDatafeedId = `datafeed-${forecastJobId}`; @@ -45,21 +46,22 @@ export default ({ getService }: FtrProviderContext) => { user: USER, expectedStatusCode: number ) { - const { body, status } = await supertest - .delete( - `${ - space ? `/s/${space}` : '' - }/internal/ml/anomaly_detectors/${jobId}/_forecast/${forecastId}` - ) - .auth(user, ml.securityCommon.getPasswordForUser(user)) - .set(getCommonRequestHeader('1')); - ml.api.assertResponseStatusCode(expectedStatusCode, status, body); - - return body; + await retry.tryForTime(10000, async () => { + const { body, status } = await supertest + .delete( + `${ + space ? `/s/${space}` : '' + }/internal/ml/anomaly_detectors/${jobId}/_forecast/${forecastId}` + ) + .auth(user, ml.securityCommon.getPasswordForUser(user)) + .set(getCommonRequestHeader('1')); + ml.api.assertResponseStatusCode(expectedStatusCode, status, body); + + return body; + }); } - // Failing see: https://github.com/elastic/kibana/issues/195602 - describe.skip('POST anomaly_detectors _forecast with spaces', function () { + describe('POST anomaly_detectors _forecast with spaces', function () { let forecastId: string; before(async () => { await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); @@ -110,11 +112,11 @@ export default ({ getService }: FtrProviderContext) => { }); it('should not delete forecast for user without permissions', async () => { - await await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_VIEWER, 403); + await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_VIEWER, 403); }); it('should delete forecast for user with permissions', async () => { - await await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_POWERUSER, 200); + await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_POWERUSER, 200); }); it('should not run forecast for open job with invalid duration', async () => { From b639c47e1e0fde344c30df2d740addc42cc9d507 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 03:46:34 +1100 Subject: [PATCH 08/33] [8.x] [APM] Use subfeature permissions for Labs settings (#197092) (#197259) # Backport This will backport the following commits from `main` to `8.x`: - [[APM] Use subfeature permissions for Labs settings (#197092)](https://github.com/elastic/kibana/pull/197092) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Sergi Romeu --- .../labs/labs_flyout.tsx | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/apm_header_action_menu/labs/labs_flyout.tsx b/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/apm_header_action_menu/labs/labs_flyout.tsx index 7eea2faf9f62c..bda1c7e4ee022 100644 --- a/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/apm_header_action_menu/labs/labs_flyout.tsx +++ b/x-pack/plugins/observability_solution/apm/public/components/routing/app_root/apm_header_action_menu/labs/labs_flyout.tsx @@ -20,6 +20,7 @@ import { EuiSpacer, EuiText, EuiTitle, + EuiToolTip, } from '@elastic/eui'; import { withSuspense } from '@kbn/shared-ux-utility'; import { i18n } from '@kbn/i18n'; @@ -42,7 +43,11 @@ interface Props { export function LabsFlyout({ onClose }: Props) { const trackApmEvent = useUiTracker({ app: 'apm' }); - const { docLinks, notifications } = useApmPluginContext().core; + const { docLinks, notifications, application } = useApmPluginContext().core; + + const canSave = + application.capabilities.advancedSettings.save && + (application.capabilities.apm['settings:save'] as boolean); const { data, status } = useFetcher( (callApmApi) => callApmApi('GET /internal/apm/settings/labs'), @@ -152,7 +157,7 @@ export function LabsFlyout({ onClose }: Props) { > @@ -172,16 +177,27 @@ export function LabsFlyout({ onClose }: Props) { - - {i18n.translate('xpack.apm.labs.reload', { - defaultMessage: 'Reload to apply changes', - })} - + + {i18n.translate('xpack.apm.labs.reload', { + defaultMessage: 'Reload to apply changes', + })} + + From 867a0396a5d312d1f7468f6d3ab4340b7411fba0 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 04:01:21 +1100 Subject: [PATCH 09/33] [8.x] [Onboarding] Add tech preview badge to the OTel k8s flow (#197229) (#197268) # Backport This will backport the following commits from `main` to `8.x`: - [[Onboarding] Add tech preview badge to the OTel k8s flow (#197229)](https://github.com/elastic/kibana/pull/197229) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Giorgos Bamparopoulos --- .../onboarding_flow_form/use_custom_cards_for_category.tsx | 1 + .../public/application/pages/otel_kubernetes.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/x-pack/plugins/observability_solution/observability_onboarding/public/application/onboarding_flow_form/use_custom_cards_for_category.tsx b/x-pack/plugins/observability_solution/observability_onboarding/public/application/onboarding_flow_form/use_custom_cards_for_category.tsx index a31f835bae4d0..0ef775d4e3f6c 100644 --- a/x-pack/plugins/observability_solution/observability_onboarding/public/application/onboarding_flow_form/use_custom_cards_for_category.tsx +++ b/x-pack/plugins/observability_solution/observability_onboarding/public/application/onboarding_flow_form/use_custom_cards_for_category.tsx @@ -191,6 +191,7 @@ export function useCustomCardsForCategory( version: '', integration: '', isQuickstart: true, + release: 'preview', }, ]; diff --git a/x-pack/plugins/observability_solution/observability_onboarding/public/application/pages/otel_kubernetes.tsx b/x-pack/plugins/observability_solution/observability_onboarding/public/application/pages/otel_kubernetes.tsx index c4fba1fd8ff0e..8939a9fdf678e 100644 --- a/x-pack/plugins/observability_solution/observability_onboarding/public/application/pages/otel_kubernetes.tsx +++ b/x-pack/plugins/observability_solution/observability_onboarding/public/application/pages/otel_kubernetes.tsx @@ -28,6 +28,7 @@ export const OtelKubernetesPage = () => ( defaultMessage: 'Unified Kubernetes observability with the OpenTelemetry Operator', } )} + isTechnicalPreview={true} /> } > From e8b7c259257112faa9b2c88434c42b7a6b90d90e Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 04:16:46 +1100 Subject: [PATCH 10/33] [8.x] Add watsonx icon for inference endpoints management page (#197116) (#197276) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [Add watsonx icon for inference endpoints management page (#197116)](https://github.com/elastic/kibana/pull/197116) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Saikat Sarkar <132922331+saikatsarkar056@users.noreply.github.com> --- .../src/constants/trained_models.ts | 10 ++++++++++ .../public/assets/images/providers/watsonx_ai.svg | 3 +++ .../render_service_provider/service_provider.tsx | 5 +++++ .../public/components/all_inference_endpoints/types.ts | 1 + 4 files changed, 19 insertions(+) create mode 100644 x-pack/plugins/search_inference_endpoints/public/assets/images/providers/watsonx_ai.svg diff --git a/x-pack/packages/ml/trained_models_utils/src/constants/trained_models.ts b/x-pack/packages/ml/trained_models_utils/src/constants/trained_models.ts index 9fd3483771a9f..c2eb7d0ed8ef3 100644 --- a/x-pack/packages/ml/trained_models_utils/src/constants/trained_models.ts +++ b/x-pack/packages/ml/trained_models_utils/src/constants/trained_models.ts @@ -287,6 +287,16 @@ export type InferenceServiceSettings = }; }; } + | { + service: 'watsonxai'; + service_settings: { + api_key: string; + url: string; + model_id: string; + project_id: string; + api_version: string; + }; + } | { service: 'amazonbedrock'; service_settings: { diff --git a/x-pack/plugins/search_inference_endpoints/public/assets/images/providers/watsonx_ai.svg b/x-pack/plugins/search_inference_endpoints/public/assets/images/providers/watsonx_ai.svg new file mode 100644 index 0000000000000..29f7a735e6614 --- /dev/null +++ b/x-pack/plugins/search_inference_endpoints/public/assets/images/providers/watsonx_ai.svg @@ -0,0 +1,3 @@ + + + diff --git a/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_service_provider/service_provider.tsx b/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_service_provider/service_provider.tsx index 574b3881f121b..74f15f22762f1 100644 --- a/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_service_provider/service_provider.tsx +++ b/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/render_table_columns/render_service_provider/service_provider.tsx @@ -21,6 +21,7 @@ import googleAIStudioIcon from '../../../../assets/images/providers/google_ai_st import mistralIcon from '../../../../assets/images/providers/mistral.svg'; import amazonBedrockIcon from '../../../../assets/images/providers/amazon_bedrock.svg'; import alibabaCloudAISearchIcon from '../../../../assets/images/providers/alibaba_cloud_ai_search.svg'; +import watsonxAIIcon from '../../../../assets/images/providers/watsonx_ai.svg'; import { ServiceProviderKeys } from '../../types'; import * as i18n from './translations'; @@ -78,6 +79,10 @@ export const SERVICE_PROVIDERS: Record = ({ providerEndpoint }) => { diff --git a/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/types.ts b/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/types.ts index c1f23a3a4f2e3..b5c5fc49aa1fa 100644 --- a/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/types.ts +++ b/x-pack/plugins/search_inference_endpoints/public/components/all_inference_endpoints/types.ts @@ -21,6 +21,7 @@ export enum ServiceProviderKeys { hugging_face = 'hugging_face', mistral = 'mistral', openai = 'openai', + watsonxai = 'watsonxai', } export enum SortFieldInferenceEndpoint { From bb09eb393fca07ec6b810bc335e8bc61768e67e5 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 04:23:35 +1100 Subject: [PATCH 11/33] [8.x] [Index Management] Fix Flashing error banner in Index Template form (#196786) (#197279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[Index Management] Fix Flashing error banner in Index Template form (#196786)](https://github.com/elastic/kibana/pull/196786) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Jusheng Huang <117657272+viajes7@users.noreply.github.com> --- .../components/template_form/steps/step_logistics.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/public/application/components/template_form/steps/step_logistics.tsx b/x-pack/plugins/index_management/public/application/components/template_form/steps/step_logistics.tsx index 84cb0fa027ad1..d73d95600e5b1 100644 --- a/x-pack/plugins/index_management/public/application/components/template_form/steps/step_logistics.tsx +++ b/x-pack/plugins/index_management/public/application/components/template_form/steps/step_logistics.tsx @@ -194,6 +194,7 @@ export const StepLogistics: React.FunctionComponent = React.memo( const { submit, isSubmitted, + isSubmitting, isValid: isFormValid, getErrors: getFormErrors, getFormData, @@ -275,7 +276,7 @@ export const StepLogistics: React.FunctionComponent = React.memo(
From 259ab1182c1273554da76c97654255e6d9b5026f Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 04:25:29 +1100 Subject: [PATCH 12/33] [8.x] [TopNav] Ability for menu items to collapse into popover at custom breakpoints (#195820) (#197269) # Backport This will backport the following commits from `main` to `8.x`: - [[TopNav] Ability for menu items to collapse into popover at custom breakpoints (#195820)](https://github.com/elastic/kibana/pull/195820) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Tim Sullivan --- .../public/top_nav_menu/top_nav_menu.tsx | 26 ++++++++++++++----- .../top_nav_menu/top_nav_menu_items.tsx | 21 ++++++++++----- .../lens/public/app_plugin/lens_top_nav.tsx | 1 + 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx b/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx index 0d42b7c8f241a..6a3dabd9a0ceb 100644 --- a/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx +++ b/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx @@ -10,14 +10,15 @@ import React, { ReactElement } from 'react'; import classNames from 'classnames'; -import { MountPoint } from '@kbn/core/public'; +import type { MountPoint } from '@kbn/core/public'; import { MountPointPortal } from '@kbn/react-kibana-mount'; -import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; -import { StatefulSearchBarProps } from '@kbn/unified-search-plugin/public'; -import { AggregateQuery, Query } from '@kbn/es-query'; -import { TopNavMenuData } from './top_nav_menu_data'; +import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; +import type { StatefulSearchBarProps } from '@kbn/unified-search-plugin/public'; +import type { AggregateQuery, Query } from '@kbn/es-query'; +import type { EuiBreakpointSize } from '@elastic/eui'; +import type { TopNavMenuData } from './top_nav_menu_data'; import { TopNavMenuItems } from './top_nav_menu_items'; -import { TopNavMenuBadgeProps, TopNavMenuBadges } from './top_nav_menu_badges'; +import { type TopNavMenuBadgeProps, TopNavMenuBadges } from './top_nav_menu_badges'; export type TopNavMenuProps = Omit< StatefulSearchBarProps, @@ -51,6 +52,11 @@ export type TopNavMenuProps = Omit< * ``` */ setMenuMountPoint?: (menuMount: MountPoint | undefined) => void; + + /** + * A list of named breakpoints at which to show the popover version. If not provided, it will use the default set of ['xs', 's'] that is internally provided by EUI. + */ + popoverBreakpoints?: EuiBreakpointSize[]; }; /* @@ -76,7 +82,13 @@ export function TopNavMenu( } function renderMenu(className: string): ReactElement | null { - return ; + return ( + + ); } function renderSearchBar(): ReactElement | null { diff --git a/src/plugins/navigation/public/top_nav_menu/top_nav_menu_items.tsx b/src/plugins/navigation/public/top_nav_menu/top_nav_menu_items.tsx index 48179f30ec276..e8d118dadff7d 100644 --- a/src/plugins/navigation/public/top_nav_menu/top_nav_menu_items.tsx +++ b/src/plugins/navigation/public/top_nav_menu/top_nav_menu_items.tsx @@ -7,21 +7,30 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { EuiHeaderLinks } from '@elastic/eui'; +import { EuiBreakpointSize, EuiHeaderLinks } from '@elastic/eui'; import React from 'react'; import type { TopNavMenuData } from './top_nav_menu_data'; import { TopNavMenuItem } from './top_nav_menu_item'; +interface TopNavMenuItemsProps { + config: TopNavMenuData[] | undefined; + className?: string; + popoverBreakpoints?: EuiBreakpointSize[]; +} + export const TopNavMenuItems = ({ config, className, -}: { - config: TopNavMenuData[] | undefined; - className?: string; -}) => { + popoverBreakpoints, +}: TopNavMenuItemsProps) => { if (!config || config.length === 0) return null; return ( - + {config.map((menuItem: TopNavMenuData, i: number) => { return ; })} diff --git a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx index da99d693539b8..d26ce3f01cf34 100644 --- a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx +++ b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx @@ -1071,6 +1071,7 @@ export const LensTopNavMenu = ({ return ( Date: Wed, 23 Oct 2024 12:07:08 +1100 Subject: [PATCH 13/33] [8.x] [Security Solution][Notes] - copy changes for note and timeline + move the unassociated note advanced setting under the Security Solution section (#197312) (#197351) # Backport This will backport the following commits from `main` to `8.x`: - [[Security Solution][Notes] - copy changes for note and timeline + move the unassociated note advanced setting under the Security Solution section (#197312)](https://github.com/elastic/kibana/pull/197312) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Philippe Oberti --- .../sections/investigations_translations.ts | 3 +- .../add_note_icon_item.test.tsx | 14 ++++----- .../header_actions/add_note_icon_item.tsx | 30 +++++++++++++++---- .../components/header_actions/translations.ts | 24 --------------- .../attach_to_active_timeline.test.tsx | 14 ++++----- .../components/attach_to_active_timeline.tsx | 12 ++++---- .../left/components/notes_details.tsx | 2 +- .../public/management/links.ts | 2 +- .../notes/components/open_flyout_button.tsx | 2 +- .../public/notes/components/search_row.tsx | 21 +++++++------ .../components/notes/save_timeline.test.tsx | 6 ++-- .../components/notes/save_timeline.tsx | 8 ++--- .../components/timeline/tabs/notes/index.tsx | 2 +- .../query_tab_unified_components.test.tsx | 4 +-- .../security_solution/server/ui_settings.ts | 1 + 15 files changed, 72 insertions(+), 73 deletions(-) diff --git a/x-pack/plugins/security_solution/public/app/solution_navigation/links/sections/investigations_translations.ts b/x-pack/plugins/security_solution/public/app/solution_navigation/links/sections/investigations_translations.ts index d70717783870a..931c3c20d4002 100644 --- a/x-pack/plugins/security_solution/public/app/solution_navigation/links/sections/investigations_translations.ts +++ b/x-pack/plugins/security_solution/public/app/solution_navigation/links/sections/investigations_translations.ts @@ -24,7 +24,8 @@ export const TIMELINE_DESCRIPTION = i18n.translate( export const NOTE_DESCRIPTION = i18n.translate( 'xpack.securitySolution.navLinks.investigations.note.title', { - defaultMessage: 'Oversee, revise and revisit the annotations within each document and timeline', + defaultMessage: + 'Oversee, revise, and revisit the notes attached to alerts, events and Timelines.', } ); diff --git a/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.test.tsx b/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.test.tsx index 98dfc83e9d3e8..b07aa7aedfcad 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.test.tsx @@ -37,7 +37,7 @@ const renderTestComponent = (props: Partial = { timelineType: TimelineTypeEnum.default, eventId: 'event-1', - ariaLabel: 'Add Note', + ariaLabel: 'Add note', toggleShowNotes: toggleShowNotesMock, notesCount: 2, ...props, @@ -76,12 +76,12 @@ describe('AddEventNoteAction', () => { expect(NotesButtonMock).toHaveBeenCalledWith( expect.objectContaining({ - ariaLabel: 'Add Note', + ariaLabel: 'Add note', 'data-test-subj': 'add-note', isDisabled: false, timelineType: TimelineTypeEnum.default, toggleShowNotes: expect.any(Function), - toolTip: '2 Notes available. Click to view them & add more.', + toolTip: '2 notes available. Click to view them and add more.', eventId: 'event-1', notesCount: 2, }), @@ -98,12 +98,12 @@ describe('AddEventNoteAction', () => { expect(NotesButtonMock).toHaveBeenCalledWith( expect.objectContaining({ - ariaLabel: 'Add Note', + ariaLabel: 'Add note', 'data-test-subj': 'add-note', isDisabled: false, timelineType: TimelineTypeEnum.default, toggleShowNotes: expect.any(Function), - toolTip: '1 Note available. Click to view it & add more.', + toolTip: '1 note available. Click to view it and add more.', eventId: 'event-2', notesCount: 1, }), @@ -120,12 +120,12 @@ describe('AddEventNoteAction', () => { expect(NotesButtonMock).toHaveBeenCalledWith( expect.objectContaining({ - ariaLabel: 'Add Note', + ariaLabel: 'Add note', 'data-test-subj': 'add-note', isDisabled: false, timelineType: TimelineTypeEnum.default, toggleShowNotes: expect.any(Function), - toolTip: 'Add Note', + toolTip: 'Add note', eventId: 'event-3', notesCount: 0, }), diff --git a/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.tsx b/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.tsx index f9539b9062331..f931042863a62 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.tsx +++ b/x-pack/plugins/security_solution/public/common/components/header_actions/add_note_icon_item.tsx @@ -6,12 +6,34 @@ */ import React, { useMemo } from 'react'; +import { i18n } from '@kbn/i18n'; import { NotesButton } from '../../../timelines/components/timeline/properties/helpers'; import { type TimelineType, TimelineTypeEnum } from '../../../../common/api/timeline'; import { useUserPrivileges } from '../user_privileges'; -import * as i18n from './translations'; import { ActionIconItem } from './action_icon_item'; +const NOTES_DISABLE_TOOLTIP = i18n.translate( + 'xpack.securitySolution.timeline.body.notes.disableEventTooltip', + { + defaultMessage: 'Notes cannot be added here while editing a template Timeline.', + } +); +const NOTES_ADD_TOOLTIP = i18n.translate( + 'xpack.securitySolution.timeline.body.notes.addNoteTooltip', + { + defaultMessage: 'Add note', + } +); +const NOTES_COUNT_TOOLTIP = ({ notesCount }: { notesCount: number }) => + i18n.translate( + 'xpack.securitySolution.timeline.body.notes.addNote.multipleNotesAvailableTooltip', + { + values: { notesCount }, + defaultMessage: + '{notesCount} {notesCount, plural, one {note} other {notes} } available. Click to view {notesCount, plural, one {it} other {them}} and add more.', + } + ); + interface AddEventNoteActionProps { ariaLabel?: string; timelineType: TimelineType; @@ -33,7 +55,7 @@ const AddEventNoteActionComponent: React.FC = ({ const { kibanaSecuritySolutionsPrivileges } = useUserPrivileges(); const NOTES_TOOLTIP = useMemo( - () => (notesCount > 0 ? i18n.NOTES_COUNT_TOOLTIP({ notesCount }) : i18n.NOTES_ADD_TOOLTIP), + () => (notesCount > 0 ? NOTES_COUNT_TOOLTIP({ notesCount }) : NOTES_ADD_TOOLTIP), [notesCount] ); @@ -45,9 +67,7 @@ const AddEventNoteActionComponent: React.FC = ({ isDisabled={kibanaSecuritySolutionsPrivileges.crud === false} timelineType={timelineType} toggleShowNotes={toggleShowNotes} - toolTip={ - timelineType === TimelineTypeEnum.template ? i18n.NOTES_DISABLE_TOOLTIP : NOTES_TOOLTIP - } + toolTip={timelineType === TimelineTypeEnum.template ? NOTES_DISABLE_TOOLTIP : NOTES_TOOLTIP} eventId={eventId} notesCount={notesCount} /> diff --git a/x-pack/plugins/security_solution/public/common/components/header_actions/translations.ts b/x-pack/plugins/security_solution/public/common/components/header_actions/translations.ts index 10832ccfac1e5..03ff7503643c9 100644 --- a/x-pack/plugins/security_solution/public/common/components/header_actions/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/header_actions/translations.ts @@ -14,30 +14,6 @@ export const OPEN_SESSION_VIEW = i18n.translate( } ); -export const NOTES_DISABLE_TOOLTIP = i18n.translate( - 'xpack.securitySolution.timeline.body.notes.disableEventTooltip', - { - defaultMessage: 'Notes may not be added here while editing a template timeline', - } -); - -export const NOTES_ADD_TOOLTIP = i18n.translate( - 'xpack.securitySolution.timeline.body.notes.addNoteTooltip', - { - defaultMessage: 'Add Note', - } -); - -export const NOTES_COUNT_TOOLTIP = ({ notesCount }: { notesCount: number }) => - i18n.translate( - 'xpack.securitySolution.timeline.body.notes.addNote.multipleNotesAvailableTooltip', - { - values: { notesCount }, - defaultMessage: - '{notesCount} {notesCount, plural, one {Note} other {Notes} } available. Click to view {notesCount, plural, one {it} other {them}} & add more.', - } - ); - export const SORT_FIELDS = i18n.translate('xpack.securitySolution.timeline.sortFieldsButton', { defaultMessage: 'Sort fields', }); diff --git a/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.test.tsx b/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.test.tsx index 610354f8af822..51f5641af0f9c 100644 --- a/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.test.tsx +++ b/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.test.tsx @@ -50,13 +50,13 @@ describe('AttachToActiveTimeline', () => { expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toBeInTheDocument(); expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toHaveStyle('background-color: #FEC514'); - expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toHaveTextContent('Save timeline'); + expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toHaveTextContent('Save current Timeline'); expect(queryByTestId(ATTACH_TO_TIMELINE_CHECKBOX_TEST_ID)).not.toBeInTheDocument(); expect(getByTestId(ATTACH_TO_TIMELINE_CALLOUT_TEST_ID)).toBeInTheDocument(); expect(getByTestId(ATTACH_TO_TIMELINE_CALLOUT_TEST_ID)).toHaveClass('euiCallOut--warning'); - expect(getByText('Attach to timeline')).toBeInTheDocument(); + expect(getByText('Attach to current Timeline')).toBeInTheDocument(); expect( - getByText('Before attaching a note to the timeline, you need to save the timeline first.') + getByText('You must save the current Timeline before attaching notes to it.') ).toBeInTheDocument(); }); @@ -76,7 +76,7 @@ describe('AttachToActiveTimeline', () => { }, }); - const { getByTestId, getByText, queryByTestId } = render( + const { getByTestId, getByText, getAllByText, queryByTestId } = render( { expect(getByTestId(ATTACH_TO_TIMELINE_CHECKBOX_TEST_ID)).toBeInTheDocument(); expect(getByTestId(ATTACH_TO_TIMELINE_CALLOUT_TEST_ID)).toBeInTheDocument(); expect(getByTestId(ATTACH_TO_TIMELINE_CALLOUT_TEST_ID)).toHaveClass('euiCallOut--primary'); - expect(getByText('Attach to timeline')).toBeInTheDocument(); - expect( - getByText('You can associate the newly created note to the active timeline.') - ).toBeInTheDocument(); + expect(getAllByText('Attach to current Timeline')).toHaveLength(2); + expect(getByText('Also attach this note to the current Timeline.')).toBeInTheDocument(); }); it('should call the callback when user click on the checkbox', () => { diff --git a/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.tsx b/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.tsx index 77b3404561275..c8cd360947881 100644 --- a/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.tsx +++ b/x-pack/plugins/security_solution/public/flyout/document_details/left/components/attach_to_active_timeline.tsx @@ -26,31 +26,31 @@ const timelineCheckBoxId = 'xpack.securitySolution.flyout.notes.attachToTimeline export const ATTACH_TO_TIMELINE_CALLOUT_TITLE = i18n.translate( 'xpack.securitySolution.flyout.left.notes.attachToTimeline.calloutTitle', { - defaultMessage: 'Attach to timeline', + defaultMessage: 'Attach to current Timeline', } ); export const SAVED_TIMELINE_CALLOUT_CONTENT = i18n.translate( 'xpack.securitySolution.flyout.left.notes.attachToTimeline.calloutContent', { - defaultMessage: 'You can associate the newly created note to the active timeline.', + defaultMessage: 'Also attach this note to the current Timeline.', } ); export const UNSAVED_TIMELINE_CALLOUT_CONTENT = i18n.translate( 'xpack.securitySolution.flyout.left.notes.attachToTimeline.calloutContent', { - defaultMessage: 'Before attaching a note to the timeline, you need to save the timeline first.', + defaultMessage: 'You must save the current Timeline before attaching notes to it.', } ); export const ATTACH_TO_TIMELINE_CHECKBOX = i18n.translate( 'xpack.securitySolution.flyout.left.notes.attachToTimeline.checkboxLabel', { - defaultMessage: 'Attach to active timeline', + defaultMessage: 'Attach to current Timeline', } ); export const SAVE_TIMELINE_BUTTON = i18n.translate( - 'xpack.securitySolution.flyout.left.notes.savedTimelineButtonLabel', + 'xpack.securitySolution.flyout.left.notes.attachToTimeline.savedTimelineButtonLabel', { - defaultMessage: 'Save timeline', + defaultMessage: 'Save current Timeline', } ); diff --git a/x-pack/plugins/security_solution/public/flyout/document_details/left/components/notes_details.tsx b/x-pack/plugins/security_solution/public/flyout/document_details/left/components/notes_details.tsx index f97ca576d2385..e35c7a3af0d4e 100644 --- a/x-pack/plugins/security_solution/public/flyout/document_details/left/components/notes_details.tsx +++ b/x-pack/plugins/security_solution/public/flyout/document_details/left/components/notes_details.tsx @@ -42,7 +42,7 @@ export const FETCH_NOTES_ERROR = i18n.translate( ); export const NO_NOTES = (isAlert: boolean) => i18n.translate('xpack.securitySolution.flyout.left.notes.noNotesLabel', { - defaultMessage: 'No notes have been created for this {value}', + defaultMessage: 'No notes have been created for this {value}.', values: { value: isAlert ? 'alert' : 'event' }, }); diff --git a/x-pack/plugins/security_solution/public/management/links.ts b/x-pack/plugins/security_solution/public/management/links.ts index c83a7360910fa..27b5b62eac6f8 100644 --- a/x-pack/plugins/security_solution/public/management/links.ts +++ b/x-pack/plugins/security_solution/public/management/links.ts @@ -223,7 +223,7 @@ export const links: LinkItem = { title: NOTES, description: i18n.translate('xpack.securitySolution.appLinks.notesDescription', { defaultMessage: - 'Oversee, revise and revisit the annotations within each document and timeline.', + 'Oversee, revise, and revisit the notes attached to alerts, events and Timelines.', }), landingIcon: 'filebeatApp', path: NOTES_PATH, diff --git a/x-pack/plugins/security_solution/public/notes/components/open_flyout_button.tsx b/x-pack/plugins/security_solution/public/notes/components/open_flyout_button.tsx index 34ae9405fdf86..85e9e24c6f26e 100644 --- a/x-pack/plugins/security_solution/public/notes/components/open_flyout_button.tsx +++ b/x-pack/plugins/security_solution/public/notes/components/open_flyout_button.tsx @@ -20,7 +20,7 @@ import { DocumentDetailsRightPanelKey } from '../../flyout/document_details/shar export const OPEN_FLYOUT_BUTTON = i18n.translate( 'xpack.securitySolution.notes.openFlyoutButtonLabel', { - defaultMessage: 'Expand event details', + defaultMessage: 'Expand alert/event details', } ); diff --git a/x-pack/plugins/security_solution/public/notes/components/search_row.tsx b/x-pack/plugins/security_solution/public/notes/components/search_row.tsx index f2f90b3ba7e0d..3c4093f913acf 100644 --- a/x-pack/plugins/security_solution/public/notes/components/search_row.tsx +++ b/x-pack/plugins/security_solution/public/notes/components/search_row.tsx @@ -21,8 +21,8 @@ import { ASSOCIATED_NOT_SELECT_TEST_ID, SEARCH_BAR_TEST_ID } from './test_ids'; import { userFilterAssociatedNotes, userSearchedNotes } from '..'; import { AssociatedFilter } from '../../../common/notes/constants'; -const FILTER_SELECT = i18n.translate('xpack.securitySolution.notes.management.filterSelect', { - defaultMessage: 'Select filter', +const ATTACH_FILTER = i18n.translate('xpack.securitySolution.notes.management.attachFilter', { + defaultMessage: 'Attached to', }); const searchBox = { @@ -31,11 +31,14 @@ const searchBox = { 'data-test-subj': SEARCH_BAR_TEST_ID, }; const associatedNoteSelectOptions: EuiSelectOption[] = [ - { value: AssociatedFilter.all, text: 'All' }, - { value: AssociatedFilter.documentOnly, text: 'Attached to document only' }, - { value: AssociatedFilter.savedObjectOnly, text: 'Attached to timeline only' }, - { value: AssociatedFilter.documentAndSavedObject, text: 'Attached to document and timeline' }, - { value: AssociatedFilter.orphan, text: 'Orphan' }, + { value: AssociatedFilter.all, text: 'Anything or nothing' }, + { value: AssociatedFilter.documentOnly, text: 'Alerts or events only' }, + { value: AssociatedFilter.savedObjectOnly, text: 'Timelines only' }, + { + value: AssociatedFilter.documentAndSavedObject, + text: 'Alerts or events and Timelines only', + }, + { value: AssociatedFilter.orphan, text: 'Nothing' }, ]; export const SearchRow = React.memo(() => { @@ -69,8 +72,8 @@ export const SearchRow = React.memo(() => { id={associatedSelectId} options={associatedNoteSelectOptions} onChange={onAssociatedNoteSelectChange} - prepend={FILTER_SELECT} - aria-label={FILTER_SELECT} + prepend={ATTACH_FILTER} + aria-label={ATTACH_FILTER} data-test-subj={ASSOCIATED_NOT_SELECT_TEST_ID} /> diff --git a/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.test.tsx index 36a45e993674f..8a024aec79840 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.test.tsx @@ -42,11 +42,11 @@ describe('SaveTimelineCallout', () => { expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toBeInTheDocument(); expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toHaveStyle('background-color: #BD271E'); - expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toHaveTextContent('Save timeline'); + expect(getByTestId(SAVE_TIMELINE_BUTTON_TEST_ID)).toHaveTextContent('Save Timeline'); expect(getByTestId(SAVE_TIMELINE_CALLOUT_TEST_ID)).toBeInTheDocument(); - expect(getAllByText('Save timeline')).toHaveLength(2); + expect(getAllByText('Save Timeline')).toHaveLength(2); expect( - getByText('You need to save your timeline before creating notes for it.') + getByText('You must save this Timeline before attaching notes to it.') ).toBeInTheDocument(); }); }); diff --git a/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.tsx b/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.tsx index 0c0a56f2699d3..12efd2db689b7 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/notes/save_timeline.tsx @@ -16,19 +16,19 @@ import { SaveTimelineButton } from '../modal/actions/save_timeline_button'; export const SAVE_TIMELINE_CALLOUT_TITLE = i18n.translate( 'xpack.securitySolution.timeline.notes.saveTimeline.calloutTitle', { - defaultMessage: 'Save timeline', + defaultMessage: 'Save Timeline', } ); export const SAVE_TIMELINE_CALLOUT_CONTENT = i18n.translate( 'xpack.securitySolution.timeline.notes.saveTimeline.calloutContent', { - defaultMessage: 'You need to save your timeline before creating notes for it.', + defaultMessage: 'You must save this Timeline before attaching notes to it.', } ); export const SAVE_TIMELINE_BUTTON = i18n.translate( - 'xpack.securitySolution.flyout.left.notes.savedTimelineButtonLabel', + 'xpack.securitySolution.flyout.left.notes.saveTimeline.buttonLabel', { - defaultMessage: 'Save timeline', + defaultMessage: 'Save Timeline', } ); diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/notes/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/notes/index.tsx index 737001125c990..aad74f15d4f62 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/notes/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/notes/index.tsx @@ -59,7 +59,7 @@ export const FETCH_NOTES_ERROR = i18n.translate( } ); export const NO_NOTES = i18n.translate('xpack.securitySolution.notes.noNotesLabel', { - defaultMessage: 'No notes have yet been created for this timeline', + defaultMessage: 'No notes have been created for this Timeline.', }); interface NotesTabContentProps { diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/query_tab_unified_components.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/query_tab_unified_components.test.tsx index 9d450f46f4b01..107c166183647 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/query_tab_unified_components.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/tabs/query/query_tab_unified_components.test.tsx @@ -918,7 +918,7 @@ describe('query tab with unified timeline', () => { await waitFor(() => { expect(screen.getByTestId('timeline-notes-tool-tip')).toBeInTheDocument(); expect(screen.getByTestId('timeline-notes-tool-tip')).toHaveTextContent( - '1 Note available. Click to view it & add more.' + '1 note available. Click to view it and add more.' ); }); }, @@ -975,7 +975,7 @@ describe('query tab with unified timeline', () => { await waitFor(() => { expect(screen.getByTestId('timeline-notes-tool-tip')).toBeVisible(); expect(screen.getByTestId('timeline-notes-tool-tip')).toHaveTextContent( - '1 Note available. Click to view it & add more.' + '1 note available. Click to view it and add more.' ); }); }, diff --git a/x-pack/plugins/security_solution/server/ui_settings.ts b/x-pack/plugins/security_solution/server/ui_settings.ts index 842b8bbeceff8..6aeb86750be7a 100644 --- a/x-pack/plugins/security_solution/server/ui_settings.ts +++ b/x-pack/plugins/security_solution/server/ui_settings.ts @@ -343,6 +343,7 @@ export const initUiSettings = ( max: 1000, defaultValue: DEFAULT_MAX_UNASSOCIATED_NOTES, }), + category: [APP_ID], requiresPageReload: false, }, [EXCLUDED_DATA_TIERS_FOR_RULE_EXECUTION]: { From 4a69bcdb592a0a8555d28d2d64a9c5e24e274ebb Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:15:32 +1100 Subject: [PATCH 14/33] [8.x] [ResponseOps][Rules] Remove unintended internal Find routes API with public access (#193757) (#197359) # Backport This will backport the following commits from `main` to `8.x`: - [[ResponseOps][Rules] Remove unintended internal Find routes API with public access (#193757)](https://github.com/elastic/kibana/pull/193757) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Zacqary Adam Xeper --- .../plugins/alerting/server/routes/index.ts | 3 +- .../find/find_internal_rules_route.test.ts | 36 + .../apis/find/find_internal_rules_route.ts | 87 ++ .../rule/apis/find/find_rules_route.test.ts | 12 + .../routes/rule/apis/find/find_rules_route.ts | 116 +-- .../rule_management/api/api.test.ts | 17 +- .../rule_management/api/api.ts | 6 +- .../use_fetch_rules_snooze_settings_query.ts | 2 +- .../group1/tests/alerting/find.ts | 230 ++---- .../group1/tests/alerting/find_internal.ts | 762 ++++++++++++++++++ .../group1/tests/alerting/find_with_post.ts | 14 +- .../group1/tests/alerting/index.ts | 1 + .../tests/alerting/group1/create.ts | 13 +- .../spaces_only/tests/alerting/group1/find.ts | 160 ++-- .../tests/alerting/group1/find_internal.ts | 355 ++++++++ .../tests/alerting/group2/update.ts | 9 +- .../pages/alerts/custom_threshold.ts | 5 +- .../apps/observability/pages/rules_page.ts | 7 +- .../rule_actions/snoozing/rule_snoozing.cy.ts | 2 +- 19 files changed, 1450 insertions(+), 387 deletions(-) create mode 100644 x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.test.ts create mode 100644 x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.ts create mode 100644 x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_internal.ts create mode 100644 x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find_internal.ts diff --git a/x-pack/plugins/alerting/server/routes/index.ts b/x-pack/plugins/alerting/server/routes/index.ts index 97fdf8c90f8d6..1a274692cefe4 100644 --- a/x-pack/plugins/alerting/server/routes/index.ts +++ b/x-pack/plugins/alerting/server/routes/index.ts @@ -20,7 +20,8 @@ import { deleteRuleRoute } from './rule/apis/delete/delete_rule_route'; import { aggregateRulesRoute } from './rule/apis/aggregate/aggregate_rules_route'; import { disableRuleRoute } from './rule/apis/disable/disable_rule_route'; import { enableRuleRoute } from './rule/apis/enable/enable_rule_route'; -import { findRulesRoute, findInternalRulesRoute } from './rule/apis/find/find_rules_route'; +import { findRulesRoute } from './rule/apis/find/find_rules_route'; +import { findInternalRulesRoute } from './rule/apis/find/find_internal_rules_route'; import { getRuleAlertSummaryRoute } from './get_rule_alert_summary'; import { getRuleExecutionLogRoute } from './get_rule_execution_log'; import { getGlobalExecutionLogRoute } from './get_global_execution_logs'; diff --git a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.test.ts b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.test.ts new file mode 100644 index 0000000000000..46ff2e8e96e12 --- /dev/null +++ b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.test.ts @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { httpServiceMock } from '@kbn/core/server/mocks'; +import { licenseStateMock } from '../../../../lib/license_state.mock'; +import { findInternalRulesRoute } from './find_internal_rules_route'; + +jest.mock('../../../../lib/license_api_access', () => ({ + verifyApiAccess: jest.fn(), +})); + +jest.mock('../../../lib/track_legacy_terminology', () => ({ + trackLegacyTerminology: jest.fn(), +})); + +beforeEach(() => { + jest.resetAllMocks(); +}); + +describe('findInternalRulesRoute', () => { + it('registers the route without public access', async () => { + const licenseState = licenseStateMock.create(); + const router = httpServiceMock.createRouter(); + + findInternalRulesRoute(router, licenseState); + expect(router.post).toHaveBeenCalledWith( + expect.not.objectContaining({ + options: expect.objectContaining({ access: 'public' }), + }), + expect.any(Function) + ); + }); +}); diff --git a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.ts b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.ts new file mode 100644 index 0000000000000..8ff8ce59192cf --- /dev/null +++ b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_internal_rules_route.ts @@ -0,0 +1,87 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { IRouter } from '@kbn/core/server'; +import { UsageCounter } from '@kbn/usage-collection-plugin/server'; +import type { + FindRulesRequestQueryV1, + FindRulesResponseV1, +} from '../../../../../common/routes/rule/apis/find'; +import { findRulesRequestQuerySchemaV1 } from '../../../../../common/routes/rule/apis/find'; +import { RuleParamsV1 } from '../../../../../common/routes/rule/response'; +import { ILicenseState } from '../../../../lib'; +import { + AlertingRequestHandlerContext, + INTERNAL_ALERTING_API_FIND_RULES_PATH, +} from '../../../../types'; +import { verifyAccessAndContext } from '../../../lib'; +import { trackLegacyTerminology } from '../../../lib/track_legacy_terminology'; +import { transformFindRulesBodyV1, transformFindRulesResponseV1 } from './transforms'; + +export const findInternalRulesRoute = ( + router: IRouter, + licenseState: ILicenseState, + usageCounter?: UsageCounter +) => { + router.post( + { + path: INTERNAL_ALERTING_API_FIND_RULES_PATH, + options: { access: 'internal' }, + validate: { + body: findRulesRequestQuerySchemaV1, + }, + }, + router.handleLegacyErrors( + verifyAccessAndContext(licenseState, async function (context, req, res) { + const rulesClient = (await context.alerting).getRulesClient(); + + const body: FindRulesRequestQueryV1 = req.body; + + trackLegacyTerminology( + [req.body.search, req.body.search_fields, req.body.sort_field].filter( + Boolean + ) as string[], + usageCounter + ); + + const options = transformFindRulesBodyV1({ + ...body, + has_reference: body.has_reference || undefined, + search_fields: searchFieldsAsArray(body.search_fields), + }); + + if (req.body.fields) { + usageCounter?.incrementCounter({ + counterName: `alertingFieldsUsage`, + counterType: 'alertingFieldsUsage', + incrementBy: 1, + }); + } + + const findResult = await rulesClient.find({ + options, + excludeFromPublicApi: false, + includeSnoozeData: true, + }); + + const responseBody: FindRulesResponseV1['body'] = + transformFindRulesResponseV1(findResult, options.fields); + + return res.ok({ + body: responseBody, + }); + }) + ) + ); +}; + +function searchFieldsAsArray(searchFields: string | string[] | undefined): string[] | undefined { + if (!searchFields) { + return; + } + return Array.isArray(searchFields) ? searchFields : [searchFields]; +} diff --git a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.test.ts b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.test.ts index 4e3c9b635ec3a..0e1f07a5ce543 100644 --- a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.test.ts +++ b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.test.ts @@ -30,6 +30,18 @@ beforeEach(() => { }); describe('findRulesRoute', () => { + it('registers the route with public access', async () => { + const licenseState = licenseStateMock.create(); + const router = httpServiceMock.createRouter(); + + findRulesRoute(router, licenseState); + expect(router.get).toHaveBeenCalledWith( + expect.objectContaining({ + options: expect.objectContaining({ access: 'public' }), + }), + expect.any(Function) + ); + }); it('finds rules with proper parameters', async () => { const licenseState = licenseStateMock.create(); const router = httpServiceMock.createRouter(); diff --git a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts index b4384e9d8f4ef..90afde8f20813 100644 --- a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts +++ b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts @@ -7,40 +7,26 @@ import { IRouter } from '@kbn/core/server'; import { UsageCounter } from '@kbn/usage-collection-plugin/server'; -import { ILicenseState } from '../../../../lib'; -import { verifyAccessAndContext } from '../../../lib'; -import { findRulesRequestQuerySchemaV1 } from '../../../../../common/routes/rule/apis/find'; import type { FindRulesRequestQueryV1, FindRulesResponseV1, } from '../../../../../common/routes/rule/apis/find'; +import { findRulesRequestQuerySchemaV1 } from '../../../../../common/routes/rule/apis/find'; import { RuleParamsV1, ruleResponseSchemaV1 } from '../../../../../common/routes/rule/response'; -import { - AlertingRequestHandlerContext, - BASE_ALERTING_API_PATH, - INTERNAL_ALERTING_API_FIND_RULES_PATH, -} from '../../../../types'; +import { ILicenseState } from '../../../../lib'; +import { AlertingRequestHandlerContext, BASE_ALERTING_API_PATH } from '../../../../types'; +import { verifyAccessAndContext } from '../../../lib'; import { trackLegacyTerminology } from '../../../lib/track_legacy_terminology'; import { transformFindRulesBodyV1, transformFindRulesResponseV1 } from './transforms'; -interface BuildFindRulesRouteParams { - licenseState: ILicenseState; - path: string; - router: IRouter; - excludeFromPublicApi?: boolean; - usageCounter?: UsageCounter; -} - -const buildFindRulesRoute = ({ - licenseState, - path, - router, - excludeFromPublicApi = false, - usageCounter, -}: BuildFindRulesRouteParams) => { +export const findRulesRoute = ( + router: IRouter, + licenseState: ILicenseState, + usageCounter?: UsageCounter +) => { router.get( { - path, + path: `${BASE_ALERTING_API_PATH}/rules/_find`, options: { access: 'public', summary: 'Get information about rules', @@ -91,7 +77,7 @@ const buildFindRulesRoute = ({ const findResult = await rulesClient.find({ options, - excludeFromPublicApi, + excludeFromPublicApi: true, includeSnoozeData: true, }); @@ -104,86 +90,6 @@ const buildFindRulesRoute = ({ }) ) ); - if (path === INTERNAL_ALERTING_API_FIND_RULES_PATH) { - router.post( - { - path, - options: { access: 'internal' }, - validate: { - body: findRulesRequestQuerySchemaV1, - }, - }, - router.handleLegacyErrors( - verifyAccessAndContext(licenseState, async function (context, req, res) { - const rulesClient = (await context.alerting).getRulesClient(); - - const body: FindRulesRequestQueryV1 = req.body; - - trackLegacyTerminology( - [req.body.search, req.body.search_fields, req.body.sort_field].filter( - Boolean - ) as string[], - usageCounter - ); - - const options = transformFindRulesBodyV1({ - ...body, - has_reference: body.has_reference || undefined, - search_fields: searchFieldsAsArray(body.search_fields), - }); - - if (req.body.fields) { - usageCounter?.incrementCounter({ - counterName: `alertingFieldsUsage`, - counterType: 'alertingFieldsUsage', - incrementBy: 1, - }); - } - - const findResult = await rulesClient.find({ - options, - excludeFromPublicApi, - includeSnoozeData: true, - }); - - const responseBody: FindRulesResponseV1['body'] = - transformFindRulesResponseV1(findResult, options.fields); - - return res.ok({ - body: responseBody, - }); - }) - ) - ); - } -}; - -export const findRulesRoute = ( - router: IRouter, - licenseState: ILicenseState, - usageCounter?: UsageCounter -) => { - buildFindRulesRoute({ - excludeFromPublicApi: true, - licenseState, - path: `${BASE_ALERTING_API_PATH}/rules/_find`, - router, - usageCounter, - }); -}; - -export const findInternalRulesRoute = ( - router: IRouter, - licenseState: ILicenseState, - usageCounter?: UsageCounter -) => { - buildFindRulesRoute({ - excludeFromPublicApi: false, - licenseState, - path: INTERNAL_ALERTING_API_FIND_RULES_PATH, - router, - usageCounter, - }); }; function searchFieldsAsArray(searchFields: string | string[] | undefined): string[] | undefined { diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts index d10bb4bb03e08..bc7c288906e8e 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.test.ts @@ -854,9 +854,7 @@ describe('Detections Rules API', () => { expect(fetchMock).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ - query: expect.objectContaining({ - filter: 'alert.id:"alert:id1" or alert.id:"alert:id2"', - }), + body: '{"filter":"alert.id:\\"alert:id1\\" or alert.id:\\"alert:id2\\"","fields":"[\\"muteAll\\",\\"activeSnoozes\\",\\"isSnoozedUntil\\",\\"snoozeSchedule\\"]","per_page":2}', }) ); }); @@ -867,9 +865,7 @@ describe('Detections Rules API', () => { expect(fetchMock).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ - query: expect.objectContaining({ - per_page: 2, - }), + body: '{"filter":"alert.id:\\"alert:id1\\" or alert.id:\\"alert:id2\\"","fields":"[\\"muteAll\\",\\"activeSnoozes\\",\\"isSnoozedUntil\\",\\"snoozeSchedule\\"]","per_page":2}', }) ); }); @@ -880,14 +876,7 @@ describe('Detections Rules API', () => { expect(fetchMock).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ - query: expect.objectContaining({ - fields: JSON.stringify([ - 'muteAll', - 'activeSnoozes', - 'isSnoozedUntil', - 'snoozeSchedule', - ]), - }), + body: '{"filter":"alert.id:\\"alert:id1\\" or alert.id:\\"alert:id2\\"","fields":"[\\"muteAll\\",\\"activeSnoozes\\",\\"isSnoozedUntil\\",\\"snoozeSchedule\\"]","per_page":2}', }) ); }); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts index c86606d0d8137..1e2ee1be7a47a 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/api.ts @@ -241,12 +241,12 @@ export const fetchRulesSnoozeSettings = async ({ const response = await KibanaServices.get().http.fetch( INTERNAL_ALERTING_API_FIND_RULES_PATH, { - method: 'GET', - query: { + method: 'POST', + body: JSON.stringify({ filter: ids.map((x) => `alert.id:"alert:${x}"`).join(' or '), fields: JSON.stringify(['muteAll', 'activeSnoozes', 'isSnoozedUntil', 'snoozeSchedule']), per_page: ids.length, - }, + }), signal, } ); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings_query.ts b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings_query.ts index 8d2ca14d79f9b..a0eedb35d4fa1 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings_query.ts +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/api/hooks/use_fetch_rules_snooze_settings_query.ts @@ -13,7 +13,7 @@ import type { RulesSnoozeSettingsMap } from '../../logic'; import { fetchRulesSnoozeSettings } from '../api'; import { DEFAULT_QUERY_OPTIONS } from './constants'; -const FETCH_RULE_SNOOZE_SETTINGS_QUERY_KEY = ['GET', INTERNAL_ALERTING_API_FIND_RULES_PATH]; +const FETCH_RULE_SNOOZE_SETTINGS_QUERY_KEY = ['POST', INTERNAL_ALERTING_API_FIND_RULES_PATH]; /** * A wrapper around useQuery provides default values to the underlying query, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts index 37d42ceeccb3a..bf5595e5756c1 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts @@ -6,10 +6,8 @@ */ import expect from '@kbn/expect'; -import { Agent as SuperTestAgent } from 'supertest'; import { chunk, omit } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; -import { SupertestWithoutAuthProviderType } from '@kbn/ftr-common-functional-services'; import { ES_QUERY_ID, ML_ANOMALY_DETECTION_RULE_TYPE_ID, @@ -19,13 +17,14 @@ import { SuperuserAtSpace1, UserAtSpaceScenarios, StackAlertsOnly } from '../../ import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; -const findTestUtils = ( - describeType: 'internal' | 'public', - objectRemover: ObjectRemover, - supertest: SuperTestAgent, - supertestWithoutAuth: SupertestWithoutAuthProviderType -) => { - describe(describeType, () => { +// eslint-disable-next-line import/no-default-export +export default function createFindTests({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const supertestWithoutAuth = getService('supertestWithoutAuth'); + + describe('find public API', () => { + const objectRemover = new ObjectRemover(supertest); + afterEach(async () => { await objectRemover.removeAll(); }); @@ -71,9 +70,9 @@ const findTestUtils = ( const response = await supertestWithoutAuth .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` + `${getUrlPrefix( + space.id + )}/api/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` ) .auth(user.username, user.password); @@ -97,8 +96,6 @@ const findTestUtils = ( expect(response.body.per_page).to.be.greaterThan(0); expect(response.body.total).to.be.greaterThan(0); const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); - const activeSnoozes = match.active_snoozes; - const hasActiveSnoozes = !!(activeSnoozes || []).filter((obj: any) => obj).length; expect(match).to.eql({ id: createdAlert.id, name: 'abc', @@ -138,14 +135,6 @@ const findTestUtils = ( execution_status: match.execution_status, ...(match.next_run ? { next_run: match.next_run } : {}), ...(match.last_run ? { last_run: match.last_run } : {}), - ...(describeType === 'internal' - ? { - monitoring: match.monitoring, - snooze_schedule: match.snooze_schedule, - ...(hasActiveSnoozes && { active_snoozes: activeSnoozes }), - is_snoozed_until: null, - } - : {}), }); expect(Date.parse(match.created_at)).to.be.greaterThan(0); expect(Date.parse(match.updated_at)).to.be.greaterThan(0); @@ -195,9 +184,9 @@ const findTestUtils = ( const response = await supertestWithoutAuth .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?per_page=${perPage}&sort_field=createdAt` + `${getUrlPrefix( + space.id + )}/api/alerting/rules/_find?per_page=${perPage}&sort_field=createdAt` ) .auth(user.username, user.password); @@ -244,9 +233,9 @@ const findTestUtils = ( const secondResponse = await supertestWithoutAuth .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?per_page=${perPage}&sort_field=createdAt&page=2` + `${getUrlPrefix( + space.id + )}/api/alerting/rules/_find?per_page=${perPage}&sort_field=createdAt&page=2` ) .auth(user.username, user.password); @@ -291,9 +280,9 @@ const findTestUtils = ( const response = await supertestWithoutAuth .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.actions:{ actionTypeId: test.noop }` + `${getUrlPrefix( + space.id + )}/api/alerting/rules/_find?filter=alert.attributes.actions:{ actionTypeId: test.noop }` ) .auth(user.username, user.password); @@ -317,8 +306,6 @@ const findTestUtils = ( expect(response.body.per_page).to.be.greaterThan(0); expect(response.body.total).to.be.greaterThan(0); const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); - const activeSnoozes = match.active_snoozes; - const hasActiveSnoozes = !!(activeSnoozes || []).filter((obj: any) => obj).length; expect(match).to.eql({ id: createdAlert.id, name: 'abc', @@ -352,14 +339,6 @@ const findTestUtils = ( revision: 0, ...(match.next_run ? { next_run: match.next_run } : {}), ...(match.last_run ? { last_run: match.last_run } : {}), - ...(describeType === 'internal' - ? { - monitoring: match.monitoring, - snooze_schedule: match.snooze_schedule, - ...(hasActiveSnoozes && { active_snoozes: activeSnoozes }), - is_snoozed_until: null, - } - : {}), }); expect(Date.parse(match.created_at)).to.be.greaterThan(0); expect(Date.parse(match.updated_at)).to.be.greaterThan(0); @@ -401,9 +380,9 @@ const findTestUtils = ( const response = await supertestWithoutAuth .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.alertTypeId:test.restricted-noop&fields=["tags"]&sort_field=createdAt` + `${getUrlPrefix( + space.id + )}/api/alerting/rules/_find?filter=alert.attributes.alertTypeId:test.restricted-noop&fields=["tags"]&sort_field=createdAt` ) .auth(user.username, user.password); @@ -434,19 +413,11 @@ const findTestUtils = ( id: createdAlert.id, actions: [], tags: [myTag], - ...(describeType === 'internal' && { - snooze_schedule: [], - is_snoozed_until: null, - }), }); expect(omit(matchSecond, 'updatedAt')).to.eql({ id: createdSecondAlert.id, actions: [], tags: [myTag], - ...(describeType === 'internal' && { - snooze_schedule: [], - is_snoozed_until: null, - }), }); break; default: @@ -486,9 +457,9 @@ const findTestUtils = ( const response = await supertestWithoutAuth .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.alertTypeId:test.restricted-noop&fields=["tags","executionStatus"]&sort_field=createdAt` + `${getUrlPrefix( + space.id + )}/api/alerting/rules/_find?filter=alert.attributes.alertTypeId:test.restricted-noop&fields=["tags","executionStatus"]&sort_field=createdAt` ) .auth(user.username, user.password); @@ -520,20 +491,12 @@ const findTestUtils = ( actions: [], tags: [myTag], execution_status: matchFirst.execution_status, - ...(describeType === 'internal' && { - snooze_schedule: [], - is_snoozed_until: null, - }), }); expect(omit(matchSecond, 'updatedAt')).to.eql({ id: createdSecondAlert.id, actions: [], tags: [myTag], execution_status: matchSecond.execution_status, - ...(describeType === 'internal' && { - snooze_schedule: [], - is_snoozed_until: null, - }), }); break; default: @@ -551,9 +514,9 @@ const findTestUtils = ( const response = await supertestWithoutAuth .get( - `${getUrlPrefix('other')}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` + `${getUrlPrefix( + 'other' + )}/api/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` ) .auth(user.username, user.password); @@ -586,88 +549,71 @@ const findTestUtils = ( }); }); } - }); - describe('Actions', () => { - const { user, space } = SuperuserAtSpace1; - - it('should return the actions correctly', async () => { - const { body: createdAction } = await supertest - .post(`${getUrlPrefix(space.id)}/api/actions/connector`) - .set('kbn-xsrf', 'foo') - .send({ - name: 'MY action', - connector_type_id: 'test.noop', - config: {}, - secrets: {}, - }) - .expect(200); - - const { body: createdRule1 } = await supertest - .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) - .set('kbn-xsrf', 'foo') - .send( - getTestRuleData({ - enabled: true, - actions: [ - { - id: createdAction.id, - group: 'default', - params: {}, - }, - { - id: 'system-connector-test.system-action', - params: {}, - }, - ], + describe('Actions', () => { + const { user, space } = SuperuserAtSpace1; + + it('should return the actions correctly', async () => { + const { body: createdAction } = await supertest + .post(`${getUrlPrefix(space.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .send({ + name: 'MY action', + connector_type_id: 'test.noop', + config: {}, + secrets: {}, }) - ) - .expect(200); - - objectRemover.add(space.id, createdRule1.id, 'rule', 'alerting'); - - const response = await supertestWithoutAuth - .get(`${getUrlPrefix(space.id)}/api/alerting/rules/_find`) - .set('kbn-xsrf', 'foo') - .auth(user.username, user.password); - - const action = response.body.data[0].actions[0]; - const systemAction = response.body.data[0].actions[1]; - const { uuid, ...restAction } = action; - const { uuid: systemActionUuid, ...restSystemAction } = systemAction; - - expect([restAction, restSystemAction]).to.eql([ - { - id: createdAction.id, - connector_type_id: 'test.noop', - group: 'default', - params: {}, - }, - { - id: 'system-connector-test.system-action', - connector_type_id: 'test.system-action', - params: {}, - }, - , - ]); - }); - }); -}; + .expect(200); -// eslint-disable-next-line import/no-default-export -export default function createFindTests({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); + const { body: createdRule1 } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + enabled: true, + actions: [ + { + id: createdAction.id, + group: 'default', + params: {}, + }, + { + id: 'system-connector-test.system-action', + params: {}, + }, + ], + }) + ) + .expect(200); - describe('find', () => { - const objectRemover = new ObjectRemover(supertest); + objectRemover.add(space.id, createdRule1.id, 'rule', 'alerting'); - afterEach(async () => { - await objectRemover.removeAll(); - }); + const response = await supertestWithoutAuth + .get(`${getUrlPrefix(space.id)}/api/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password); + + const action = response.body.data[0].actions[0]; + const systemAction = response.body.data[0].actions[1]; + const { uuid, ...restAction } = action; + const { uuid: systemActionUuid, ...restSystemAction } = systemAction; - findTestUtils('public', objectRemover, supertest, supertestWithoutAuth); - findTestUtils('internal', objectRemover, supertest, supertestWithoutAuth); + expect([restAction, restSystemAction]).to.eql([ + { + id: createdAction.id, + connector_type_id: 'test.noop', + group: 'default', + params: {}, + }, + { + id: 'system-connector-test.system-action', + connector_type_id: 'test.system-action', + params: {}, + }, + , + ]); + }); + }); describe('stack alerts', () => { const ruleTypes = [ diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_internal.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_internal.ts new file mode 100644 index 0000000000000..ee8d49c662ada --- /dev/null +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_internal.ts @@ -0,0 +1,762 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import { chunk, omit } from 'lodash'; +import { v4 as uuidv4 } from 'uuid'; +import { + ES_QUERY_ID, + ML_ANOMALY_DETECTION_RULE_TYPE_ID, + OBSERVABILITY_THRESHOLD_RULE_TYPE_ID, +} from '@kbn/rule-data-utils'; +import { SuperuserAtSpace1, UserAtSpaceScenarios, StackAlertsOnly } from '../../../scenarios'; +import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib'; +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default function createFindTests({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const supertestWithoutAuth = getService('supertestWithoutAuth'); + + describe('find internal API', () => { + const objectRemover = new ObjectRemover(supertest); + + afterEach(async () => { + await objectRemover.removeAll(); + }); + + for (const scenario of UserAtSpaceScenarios) { + const { user, space } = scenario; + describe(scenario.id, () => { + it('should handle find alert request appropriately', async () => { + const { body: createdAction } = await supertest + .post(`${getUrlPrefix(space.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .send({ + name: 'MY action', + connector_type_id: 'test.noop', + config: {}, + secrets: {}, + }) + .expect(200); + + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + actions: [ + { + group: 'default', + id: createdAction.id, + params: {}, + frequency: { + summary: false, + notify_when: 'onThrottleInterval', + throttle: '1m', + }, + }, + ], + notify_when: undefined, + throttle: undefined, + }) + ) + .expect(200); + objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + search: 'test.noop', + search_fields: 'alertTypeId', + }); + + switch (scenario.id) { + case 'no_kibana_privileges at space1': + case 'space_1_all at space2': + expect(response.statusCode).to.eql(403); + expect(response.body).to.eql({ + error: 'Forbidden', + message: `Unauthorized to find rules for any rule types`, + statusCode: 403, + }); + break; + case 'global_read at space1': + case 'superuser at space1': + case 'space_1_all at space1': + case 'space_1_all_alerts_none_actions at space1': + case 'space_1_all_with_restricted_fixture at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.greaterThan(0); + expect(response.body.total).to.be.greaterThan(0); + const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); + const activeSnoozes = match.active_snoozes; + const hasActiveSnoozes = !!(activeSnoozes || []).filter((obj: any) => obj).length; + expect(match).to.eql({ + id: createdAlert.id, + name: 'abc', + tags: ['foo'], + rule_type_id: 'test.noop', + running: match.running ?? false, + consumer: 'alertsFixture', + schedule: { interval: '1m' }, + enabled: true, + actions: [ + { + group: 'default', + id: createdAction.id, + connector_type_id: 'test.noop', + params: {}, + uuid: match.actions[0].uuid, + frequency: { + summary: false, + notify_when: 'onThrottleInterval', + throttle: '1m', + }, + }, + ], + params: {}, + created_by: 'elastic', + scheduled_task_id: match.scheduled_task_id, + created_at: match.created_at, + updated_at: match.updated_at, + throttle: null, + notify_when: null, + updated_by: 'elastic', + api_key_owner: 'elastic', + api_key_created_by_user: false, + mute_all: false, + muted_alert_ids: [], + revision: 0, + execution_status: match.execution_status, + ...(match.next_run ? { next_run: match.next_run } : {}), + ...(match.last_run ? { last_run: match.last_run } : {}), + + monitoring: match.monitoring, + snooze_schedule: match.snooze_schedule, + ...(hasActiveSnoozes && { active_snoozes: activeSnoozes }), + is_snoozed_until: null, + }); + expect(Date.parse(match.created_at)).to.be.greaterThan(0); + expect(Date.parse(match.updated_at)).to.be.greaterThan(0); + break; + default: + throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); + } + }); + + it('should filter out types that the user is not authorized to `get` retaining pagination', async () => { + async function createNoOpAlert(overrides = {}) { + const alert = getTestRuleData(overrides); + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send(alert) + .expect(200); + objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting'); + return { + id: createdAlert.id, + rule_type_id: alert.rule_type_id, + }; + } + function createRestrictedNoOpAlert() { + return createNoOpAlert({ + rule_type_id: 'test.restricted-noop', + consumer: 'alertsRestrictedFixture', + }); + } + function createUnrestrictedNoOpAlert() { + return createNoOpAlert({ + rule_type_id: 'test.unrestricted-noop', + consumer: 'alertsFixture', + }); + } + const allAlerts = []; + allAlerts.push(await createNoOpAlert()); + allAlerts.push(await createNoOpAlert()); + allAlerts.push(await createRestrictedNoOpAlert()); + allAlerts.push(await createUnrestrictedNoOpAlert()); + allAlerts.push(await createUnrestrictedNoOpAlert()); + allAlerts.push(await createRestrictedNoOpAlert()); + allAlerts.push(await createNoOpAlert()); + allAlerts.push(await createNoOpAlert()); + + const perPage = 4; + + const response = await supertestWithoutAuth + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + per_page: perPage, + sort_field: 'createdAt', + }); + + switch (scenario.id) { + case 'no_kibana_privileges at space1': + case 'space_1_all at space2': + expect(response.statusCode).to.eql(403); + expect(response.body).to.eql({ + error: 'Forbidden', + message: `Unauthorized to find rules for any rule types`, + statusCode: 403, + }); + break; + case 'space_1_all at space1': + case 'space_1_all_alerts_none_actions at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.equal(perPage); + expect(response.body.total).to.be.equal(6); + { + const [firstPage] = chunk( + allAlerts + .filter((alert) => alert.rule_type_id !== 'test.restricted-noop') + .map((alert) => alert.id), + perPage + ); + expect(response.body.data.map((alert: any) => alert.id)).to.eql(firstPage); + } + break; + case 'global_read at space1': + case 'superuser at space1': + case 'space_1_all_with_restricted_fixture at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.equal(perPage); + expect(response.body.total).to.be.equal(8); + + { + const [firstPage, secondPage] = chunk( + allAlerts.map((alert) => alert.id), + perPage + ); + expect(response.body.data.map((alert: any) => alert.id)).to.eql(firstPage); + + const secondResponse = await supertestWithoutAuth + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + per_page: perPage, + sort_field: 'createdAt', + page: 2, + }); + + expect(secondResponse.body.data.map((alert: any) => alert.id)).to.eql(secondPage); + } + + break; + default: + throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); + } + }); + + it('should handle find alert request with filter appropriately', async () => { + const { body: createdAction } = await supertest + .post(`${getUrlPrefix(space.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .send({ + name: 'My action', + connector_type_id: 'test.noop', + config: {}, + secrets: {}, + }) + .expect(200); + + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + enabled: false, + actions: [ + { + id: createdAction.id, + group: 'default', + params: {}, + }, + ], + }) + ) + .expect(200); + objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + filter: 'alert.attributes.actions:{ actionTypeId: test.noop }', + }); + + switch (scenario.id) { + case 'no_kibana_privileges at space1': + case 'space_1_all at space2': + expect(response.statusCode).to.eql(403); + expect(response.body).to.eql({ + error: 'Forbidden', + message: `Unauthorized to find rules for any rule types`, + statusCode: 403, + }); + break; + case 'global_read at space1': + case 'superuser at space1': + case 'space_1_all at space1': + case 'space_1_all_alerts_none_actions at space1': + case 'space_1_all_with_restricted_fixture at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.greaterThan(0); + expect(response.body.total).to.be.greaterThan(0); + const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); + const activeSnoozes = match.active_snoozes; + const hasActiveSnoozes = !!(activeSnoozes || []).filter((obj: any) => obj).length; + expect(match).to.eql({ + id: createdAlert.id, + name: 'abc', + tags: ['foo'], + rule_type_id: 'test.noop', + running: match.running ?? false, + consumer: 'alertsFixture', + schedule: { interval: '1m' }, + enabled: false, + actions: [ + { + id: createdAction.id, + group: 'default', + connector_type_id: 'test.noop', + params: {}, + uuid: createdAlert.actions[0].uuid, + }, + ], + params: {}, + created_by: 'elastic', + throttle: '1m', + api_key_created_by_user: null, + updated_by: 'elastic', + api_key_owner: null, + mute_all: false, + muted_alert_ids: [], + notify_when: 'onThrottleInterval', + created_at: match.created_at, + updated_at: match.updated_at, + execution_status: match.execution_status, + revision: 0, + ...(match.next_run ? { next_run: match.next_run } : {}), + ...(match.last_run ? { last_run: match.last_run } : {}), + monitoring: match.monitoring, + snooze_schedule: match.snooze_schedule, + ...(hasActiveSnoozes && { active_snoozes: activeSnoozes }), + is_snoozed_until: null, + }); + expect(Date.parse(match.created_at)).to.be.greaterThan(0); + expect(Date.parse(match.updated_at)).to.be.greaterThan(0); + break; + default: + throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); + } + }); + + it('should handle find alert request with fields appropriately', async () => { + const myTag = uuidv4(); + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + enabled: false, + tags: [myTag], + rule_type_id: 'test.restricted-noop', + consumer: 'alertsRestrictedFixture', + }) + ) + .expect(200); + objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting'); + + // create another type with same tag + const { body: createdSecondAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + tags: [myTag], + rule_type_id: 'test.restricted-noop', + consumer: 'alertsRestrictedFixture', + }) + ) + .expect(200); + objectRemover.add(space.id, createdSecondAlert.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + filter: 'alert.attributes.alertTypeId:test.restricted-noop', + fields: ['tags'], + sort_field: 'createdAt', + }); + + switch (scenario.id) { + case 'no_kibana_privileges at space1': + case 'space_1_all at space2': + expect(response.statusCode).to.eql(403); + expect(response.body).to.eql({ + error: 'Forbidden', + message: `Unauthorized to find rules for any rule types`, + statusCode: 403, + }); + break; + case 'space_1_all at space1': + case 'space_1_all_alerts_none_actions at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.data).to.eql([]); + break; + case 'global_read at space1': + case 'superuser at space1': + case 'space_1_all_with_restricted_fixture at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.greaterThan(0); + expect(response.body.total).to.be.greaterThan(0); + const [matchFirst, matchSecond] = response.body.data; + expect(omit(matchFirst, 'updatedAt')).to.eql({ + id: createdAlert.id, + actions: [], + tags: [myTag], + snooze_schedule: [], + is_snoozed_until: null, + }); + expect(omit(matchSecond, 'updatedAt')).to.eql({ + id: createdSecondAlert.id, + actions: [], + tags: [myTag], + snooze_schedule: [], + is_snoozed_until: null, + }); + break; + default: + throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); + } + }); + + it('should handle find alert request with executionStatus field appropriately', async () => { + const myTag = uuidv4(); + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + enabled: false, + tags: [myTag], + rule_type_id: 'test.restricted-noop', + consumer: 'alertsRestrictedFixture', + }) + ) + .expect(200); + objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting'); + + // create another type with same tag + const { body: createdSecondAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + tags: [myTag], + rule_type_id: 'test.restricted-noop', + consumer: 'alertsRestrictedFixture', + }) + ) + .expect(200); + objectRemover.add(space.id, createdSecondAlert.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + filter: 'alert.attributes.alertTypeId:test.restricted-noop', + fields: ['tags', 'executionStatus'], + sort_field: 'createdAt', + }); + + switch (scenario.id) { + case 'no_kibana_privileges at space1': + case 'space_1_all at space2': + expect(response.statusCode).to.eql(403); + expect(response.body).to.eql({ + error: 'Forbidden', + message: `Unauthorized to find rules for any rule types`, + statusCode: 403, + }); + break; + case 'space_1_all at space1': + case 'space_1_all_alerts_none_actions at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.data).to.eql([]); + break; + case 'global_read at space1': + case 'superuser at space1': + case 'space_1_all_with_restricted_fixture at space1': + expect(response.statusCode).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.greaterThan(0); + expect(response.body.total).to.be.greaterThan(0); + const [matchFirst, matchSecond] = response.body.data; + expect(omit(matchFirst, 'updatedAt')).to.eql({ + id: createdAlert.id, + actions: [], + tags: [myTag], + execution_status: matchFirst.execution_status, + snooze_schedule: [], + is_snoozed_until: null, + }); + expect(omit(matchSecond, 'updatedAt')).to.eql({ + id: createdSecondAlert.id, + actions: [], + tags: [myTag], + execution_status: matchSecond.execution_status, + snooze_schedule: [], + is_snoozed_until: null, + }); + break; + default: + throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); + } + }); + + it(`shouldn't find alert from another space`, async () => { + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send(getTestRuleData()) + .expect(200); + objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .post(`${getUrlPrefix('other')}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + search: 'test.noop', + search_fields: 'alertTypeId', + }); + + switch (scenario.id) { + case 'no_kibana_privileges at space1': + case 'space_1_all at space2': + case 'space_1_all at space1': + case 'space_1_all_alerts_none_actions at space1': + case 'space_1_all_with_restricted_fixture at space1': + expect(response.statusCode).to.eql(403); + expect(response.body).to.eql({ + error: 'Forbidden', + message: `Unauthorized to find rules for any rule types`, + statusCode: 403, + }); + break; + case 'global_read at space1': + case 'superuser at space1': + expect(response.statusCode).to.eql(200); + expect(response.body).to.eql({ + page: 1, + per_page: 10, + total: 0, + data: [], + }); + break; + default: + throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); + } + }); + }); + } + + describe('Actions', () => { + const { user, space } = SuperuserAtSpace1; + + it('should return the actions correctly', async () => { + const { body: createdAction } = await supertest + .post(`${getUrlPrefix(space.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .send({ + name: 'MY action', + connector_type_id: 'test.noop', + config: {}, + secrets: {}, + }) + .expect(200); + + const { body: createdRule1 } = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + enabled: true, + actions: [ + { + id: createdAction.id, + group: 'default', + params: {}, + }, + { + id: 'system-connector-test.system-action', + params: {}, + }, + ], + }) + ) + .expect(200); + + objectRemover.add(space.id, createdRule1.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .get(`${getUrlPrefix(space.id)}/api/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password); + + const action = response.body.data[0].actions[0]; + const systemAction = response.body.data[0].actions[1]; + const { uuid, ...restAction } = action; + const { uuid: systemActionUuid, ...restSystemAction } = systemAction; + + expect([restAction, restSystemAction]).to.eql([ + { + id: createdAction.id, + connector_type_id: 'test.noop', + group: 'default', + params: {}, + }, + { + id: 'system-connector-test.system-action', + connector_type_id: 'test.system-action', + params: {}, + }, + , + ]); + }); + }); + describe('stack alerts', () => { + const ruleTypes = [ + [ + ES_QUERY_ID, + { + searchType: 'esQuery', + timeWindowSize: 5, + timeWindowUnit: 'm', + threshold: [1000], + thresholdComparator: '>', + size: 100, + esQuery: '{\n "query":{\n "match_all" : {}\n }\n }', + aggType: 'count', + groupBy: 'all', + termSize: 5, + excludeHitsFromPreviousRun: false, + sourceFields: [], + index: ['.kibana'], + timeField: 'created_at', + }, + ], + [ + OBSERVABILITY_THRESHOLD_RULE_TYPE_ID, + { + criteria: [ + { + comparator: '>', + metrics: [ + { + name: 'A', + aggType: 'count', + }, + ], + threshold: [100], + timeSize: 1, + timeUnit: 'm', + }, + ], + alertOnNoData: false, + alertOnGroupDisappear: false, + searchConfiguration: { + query: { + query: '', + language: 'kuery', + }, + index: 'kibana-event-log-data-view', + }, + }, + ], + [ + ML_ANOMALY_DETECTION_RULE_TYPE_ID, + { + severity: 75, + resultType: 'bucket', + includeInterim: false, + jobSelection: { + jobIds: ['low_request_rate'], + }, + }, + ], + ]; + + const createRule = async (rule = {}) => { + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix('space1')}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send(getTestRuleData({ ...rule })) + .expect(200); + + objectRemover.add('space1', createdAlert.id, 'rule', 'alerting'); + }; + + for (const [ruleTypeId, params] of ruleTypes) { + it(`should get rules of ${ruleTypeId} rule type ID and stackAlerts consumer`, async () => { + /** + * We create two rules. The first one is a test.noop + * rule with stackAlerts as consumer. The second rule + * is has different rule type ID but with the same consumer as the first rule (stackAlerts). + * This way we can verify that the find API call returns only the rules the user is authorized to. + * Specifically only the second rule because the StackAlertsOnly user does not have + * access to the test.noop rule type. + */ + await createRule({ consumer: 'stackAlerts' }); + await createRule({ rule_type_id: ruleTypeId, params, consumer: 'stackAlerts' }); + + const response = await supertestWithoutAuth + .get(`${getUrlPrefix('space1')}/api/alerting/rules/_find`) + .auth(StackAlertsOnly.username, StackAlertsOnly.password); + + expect(response.statusCode).to.eql(200); + expect(response.body.total).to.equal(1); + expect(response.body.data[0].rule_type_id).to.equal(ruleTypeId); + expect(response.body.data[0].consumer).to.equal('stackAlerts'); + }); + } + + for (const [ruleTypeId, params] of ruleTypes) { + it(`should NOT get rules of ${ruleTypeId} rule type ID and NOT stackAlerts consumer`, async () => { + /** + * We create two rules with logs as consumer. The user is authorized to + * access rules only with the stackAlerts consumers. + */ + await createRule({ consumer: 'logs' }); + await createRule({ rule_type_id: ruleTypeId, params, consumer: 'logs' }); + + const response = await supertestWithoutAuth + .get(`${getUrlPrefix('space1')}/api/alerting/rules/_find`) + .auth(StackAlertsOnly.username, StackAlertsOnly.password); + + expect(response.statusCode).to.eql(200); + expect(response.body.total).to.equal(0); + }); + } + }); + }); +} diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_with_post.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_with_post.ts index f221b5869dd6b..c8afff8fcc476 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_with_post.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find_with_post.ts @@ -207,12 +207,14 @@ const findTestUtils = ( expect(response.body.data.map((alert: any) => alert.id)).to.eql(firstPage); const secondResponse = await supertestWithoutAuth - .get( - `${getUrlPrefix(space.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?per_page=${perPage}&sort_field=createdAt&page=2` - ) - .auth(user.username, user.password); + .post(`${getUrlPrefix(space.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'kibana') + .auth(user.username, user.password) + .send({ + per_page: perPage, + sort_field: 'createdAt', + page: 2, + }); expect(secondResponse.body.data.map((alert: any) => alert.id)).to.eql(secondPage); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/index.ts index ec938e8dc4abb..262fe8af301c8 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/index.ts @@ -22,6 +22,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC loadTestFile(require.resolve('./backfill')); loadTestFile(require.resolve('./find')); + loadTestFile(require.resolve('./find_internal')); loadTestFile(require.resolve('./find_with_post')); loadTestFile(require.resolve('./create')); loadTestFile(require.resolve('./delete')); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts index 9932ee2c11a36..57d41424186b3 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts @@ -341,13 +341,14 @@ export default function createAlertTests({ getService }: FtrProviderContext) { ) .expect(200); - const response = await supertest.get( - `${getUrlPrefix( - Spaces.space1.id - )}/internal/alerting/rules/_find?filter=alert.attributes.params.risk_score:40` - ); + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'kibana') + .send({ + filter: `alert.attributes.params.risk_score:40`, + }) + .expect(200); - expect(response.status).to.eql(200); objectRemover.add(Spaces.space1.id, createResponse.body.id, 'rule', 'alerting'); expect(response.body.total).to.equal(1); expect(response.body.data[0].mapped_params).to.eql({ diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find.ts index c8aeba2b7e210..e730dd657d2f1 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find.ts @@ -26,13 +26,15 @@ async function createAlert( return createdAlert; } -const findTestUtils = ( - describeType: 'internal' | 'public', - supertest: SuperTestAgent, - objectRemover: ObjectRemover -) => { - describe(describeType, () => { +// eslint-disable-next-line import/no-default-export +export default function createFindTests({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('find public API', () => { + const objectRemover = new ObjectRemover(supertest); + afterEach(() => objectRemover.removeAll()); + describe('handle find alert request', function () { this.tags('skipFIPS'); it('should handle find alert request appropriately', async () => { @@ -72,9 +74,9 @@ const findTestUtils = ( objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting'); const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` ); expect(response.status).to.eql(200); @@ -82,8 +84,6 @@ const findTestUtils = ( expect(response.body.per_page).to.be.greaterThan(0); expect(response.body.total).to.be.greaterThan(0); const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); - const activeSnoozes = match.active_snoozes; - const hasActiveSnoozes = !!(activeSnoozes || []).filter((obj: any) => obj).length; expect(match).to.eql({ id: createdAlert.id, name: 'abc', @@ -123,14 +123,6 @@ const findTestUtils = ( execution_status: match.execution_status, ...(match.next_run ? { next_run: match.next_run } : {}), ...(match.last_run ? { last_run: match.last_run } : {}), - ...(describeType === 'internal' - ? { - monitoring: match.monitoring, - snooze_schedule: match.snooze_schedule, - ...(hasActiveSnoozes && { active_snoozes: activeSnoozes }), - is_snoozed_until: null, - } - : {}), }); expect(Date.parse(match.created_at)).to.be.greaterThan(0); expect(Date.parse(match.updated_at)).to.be.greaterThan(0); @@ -147,9 +139,9 @@ const findTestUtils = ( await supertest .get( - `${getUrlPrefix(Spaces.other.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` + `${getUrlPrefix( + Spaces.other.id + )}/api/alerting/rules/_find?search=test.noop&search_fields=alertTypeId` ) .expect(200, { page: 1, @@ -186,62 +178,50 @@ const findTestUtils = ( ]); }); - it(`it should${ - describeType === 'public' ? ' NOT' : '' - } allow filter on monitoring attributes`, async () => { + it(`it should NOT allow filter on monitoring attributes`, async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.monitoring.run.calculated_metrics.success_ratio>50` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?filter=alert.attributes.monitoring.run.calculated_metrics.success_ratio>50` ); - expect(response.status).to.eql(describeType === 'internal' ? 200 : 400); - if (describeType === 'public') { - expect(response.body.message).to.eql( - 'Error find rules: Filter is not supported on this field alert.attributes.monitoring.run.calculated_metrics.success_ratio' - ); - } + expect(response.status).to.eql(400); + expect(response.body.message).to.eql( + 'Error find rules: Filter is not supported on this field alert.attributes.monitoring.run.calculated_metrics.success_ratio' + ); }); - it(`it should${ - describeType === 'public' ? ' NOT' : '' - } allow ordering on monitoring attributes`, async () => { + it(`it should NOT allow ordering on monitoring attributes`, async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?sort_field=monitoring.run.calculated_metrics.success_ratio` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?sort_field=monitoring.run.calculated_metrics.success_ratio` ); - expect(response.status).to.eql(describeType === 'internal' ? 200 : 400); - if (describeType === 'public') { - expect(response.body.message).to.eql( - 'Error find rules: Sort is not supported on this field monitoring.run.calculated_metrics.success_ratio' - ); - } + expect(response.status).to.eql(400); + expect(response.body.message).to.eql( + 'Error find rules: Sort is not supported on this field monitoring.run.calculated_metrics.success_ratio' + ); }); - it(`it should${ - describeType === 'public' ? ' NOT' : '' - } allow search_fields on monitoring attributes`, async () => { + it(`it should NOT allow search_fields on monitoring attributes`, async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?search_fields=monitoring.run.calculated_metrics.success_ratio&search=50` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?search_fields=monitoring.run.calculated_metrics.success_ratio&search=50` ); - expect(response.status).to.eql(describeType === 'internal' ? 200 : 400); - if (describeType === 'public') { - expect(response.body.message).to.eql( - 'Error find rules: Search field monitoring.run.calculated_metrics.success_ratio not supported' - ); - } + expect(response.status).to.eql(400); + expect(response.body.message).to.eql( + 'Error find rules: Search field monitoring.run.calculated_metrics.success_ratio not supported' + ); }); it('should filter on string parameters', async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.params.strValue:"my b"` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?filter=alert.attributes.params.strValue:"my b"` ); expect(response.status).to.eql(200); @@ -251,9 +231,7 @@ const findTestUtils = ( it('should filter on kueryNode parameters', async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=${JSON.stringify( + `${getUrlPrefix(Spaces.space1.id)}/api/alerting/rules/_find?filter=${JSON.stringify( fromKueryExpression('alert.attributes.params.strValue:"my b"') )}` ); @@ -265,9 +243,9 @@ const findTestUtils = ( it('should sort by parameters', async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?sort_field=params.severity&sort_order=asc` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?sort_field=params.severity&sort_order=asc` ); expect(response.body.data[0].params.severity).to.equal('low'); expect(response.body.data[1].params.severity).to.equal('medium'); @@ -276,9 +254,9 @@ const findTestUtils = ( it('should search by parameters', async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?search_fields=params.severity&search=medium` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?search_fields=params.severity&search=medium` ); expect(response.status).to.eql(200); @@ -288,51 +266,31 @@ const findTestUtils = ( it('should filter on parameters', async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.params.risk_score:40` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?filter=alert.attributes.params.risk_score:40` ); expect(response.status).to.eql(200); expect(response.body.total).to.equal(1); expect(response.body.data[0].params.risk_score).to.eql(40); - if (describeType === 'public') { - expect(response.body.data[0].mapped_params).to.eql(undefined); - } + expect(response.body.data[0].mapped_params).to.eql(undefined); }); it('should error if filtering on mapped parameters directly using the public API', async () => { const response = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/${ - describeType === 'public' ? 'api' : 'internal' - }/alerting/rules/_find?filter=alert.attributes.mapped_params.risk_score:40` + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerting/rules/_find?filter=alert.attributes.mapped_params.risk_score:40` ); - if (describeType === 'public') { - expect(response.status).to.eql(400); - expect(response.body.message).to.eql( - 'Error find rules: Filter is not supported on this field alert.attributes.mapped_params.risk_score' - ); - } else { - expect(response.status).to.eql(200); - } + expect(response.status).to.eql(400); + expect(response.body.message).to.eql( + 'Error find rules: Filter is not supported on this field alert.attributes.mapped_params.risk_score' + ); }); }); - }); -}; - -// eslint-disable-next-line import/no-default-export -export default function createFindTests({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - - describe('find', () => { - const objectRemover = new ObjectRemover(supertest); - - afterEach(() => objectRemover.removeAll()); - - findTestUtils('public', supertest, objectRemover); - findTestUtils('internal', supertest, objectRemover); describe('legacy', function () { this.tags('skipFIPS'); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find_internal.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find_internal.ts new file mode 100644 index 0000000000000..25fc54a5229d3 --- /dev/null +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/find_internal.ts @@ -0,0 +1,355 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import { Agent as SuperTestAgent } from 'supertest'; +import { fromKueryExpression } from '@kbn/es-query'; +import { Spaces } from '../../../scenarios'; +import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib'; +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; + +async function createAlert( + objectRemover: ObjectRemover, + supertest: SuperTestAgent, + overwrites = {} +) { + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send(getTestRuleData(overwrites)) + .expect(200); + objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting'); + return createdAlert; +} + +// eslint-disable-next-line import/no-default-export +export default function createFindTests({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('find internal API', () => { + const objectRemover = new ObjectRemover(supertest); + + afterEach(() => objectRemover.removeAll()); + + describe('handle find alert request', function () { + this.tags('skipFIPS'); + it('should handle find alert request appropriately', async () => { + const { body: createdAction } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .send({ + name: 'MY action', + connector_type_id: 'test.noop', + config: {}, + secrets: {}, + }) + .expect(200); + + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + actions: [ + { + group: 'default', + id: createdAction.id, + params: {}, + frequency: { + summary: false, + notify_when: 'onThrottleInterval', + throttle: '1m', + }, + }, + ], + notify_when: undefined, + throttle: undefined, + }) + ) + .expect(200); + objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting'); + + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + search: 'test.noop', + search_fields: 'alertTypeId', + }); + + expect(response.status).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.per_page).to.be.greaterThan(0); + expect(response.body.total).to.be.greaterThan(0); + const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); + const activeSnoozes = match.active_snoozes; + const hasActiveSnoozes = !!(activeSnoozes || []).filter((obj: any) => obj).length; + expect(match).to.eql({ + id: createdAlert.id, + name: 'abc', + tags: ['foo'], + rule_type_id: 'test.noop', + revision: 0, + running: false, + consumer: 'alertsFixture', + schedule: { interval: '1m' }, + enabled: true, + actions: [ + { + group: 'default', + id: createdAction.id, + connector_type_id: 'test.noop', + params: {}, + frequency: { + summary: false, + notify_when: 'onThrottleInterval', + throttle: '1m', + }, + uuid: match.actions[0].uuid, + }, + ], + params: {}, + created_by: null, + api_key_owner: null, + api_key_created_by_user: null, + scheduled_task_id: match.scheduled_task_id, + updated_by: null, + throttle: null, + notify_when: null, + mute_all: false, + muted_alert_ids: [], + created_at: match.created_at, + updated_at: match.updated_at, + execution_status: match.execution_status, + ...(match.next_run ? { next_run: match.next_run } : {}), + ...(match.last_run ? { last_run: match.last_run } : {}), + monitoring: match.monitoring, + snooze_schedule: match.snooze_schedule, + ...(hasActiveSnoozes && { active_snoozes: activeSnoozes }), + is_snoozed_until: null, + }); + expect(Date.parse(match.created_at)).to.be.greaterThan(0); + expect(Date.parse(match.updated_at)).to.be.greaterThan(0); + }); + }); + + it(`shouldn't find alert from another space`, async () => { + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send(getTestRuleData()) + .expect(200); + objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting'); + + await supertest + .post(`${getUrlPrefix(Spaces.other.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + search: 'test.noop', + search_fields: 'alertTypeId', + }) + .expect(200, { + page: 1, + per_page: 10, + total: 0, + data: [], + }); + }); + + describe('basic functionality', () => { + beforeEach(async () => { + await Promise.all([ + createAlert(objectRemover, supertest, { params: { strValue: 'my a' } }), + createAlert(objectRemover, supertest, { params: { strValue: 'my b' } }), + createAlert(objectRemover, supertest, { params: { strValue: 'my c' } }), + createAlert(objectRemover, supertest, { + params: { + risk_score: 60, + severity: 'high', + }, + }), + createAlert(objectRemover, supertest, { + params: { + risk_score: 40, + severity: 'medium', + }, + }), + createAlert(objectRemover, supertest, { + params: { + risk_score: 20, + severity: 'low', + }, + }), + ]); + }); + + it(`it should allow filter on monitoring attributes`, async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + filter: 'alert.attributes.monitoring.run.calculated_metrics.success_ratio>50', + }); + + expect(response.status).to.eql(200); + }); + + it(`it should allow ordering on monitoring attributes`, async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + sort_field: 'monitoring.run.calculated_metrics.success_ratio', + }); + + expect(response.status).to.eql(200); + }); + + it(`it should allow search_fields on monitoring attributes`, async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + search_fields: 'monitoring.run.calculated_metrics.success_ratio', + search: '50', + }); + + expect(response.status).to.eql(200); + }); + + it('should filter on string parameters', async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + filter: 'alert.attributes.params.strValue:"my b"', + }); + + expect(response.status).to.eql(200); + expect(response.body.total).to.equal(1); + expect(response.body.data[0].params.strValue).to.eql('my b'); + }); + + it('should filter on kueryNode parameters', async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + filter: JSON.stringify(fromKueryExpression('alert.attributes.params.strValue:"my b"')), + }); + + expect(response.status).to.eql(200); + expect(response.body.total).to.equal(1); + expect(response.body.data[0].params.strValue).to.eql('my b'); + }); + + it('should sort by parameters', async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + sort_field: 'params.severity', + sort_order: 'asc', + }); + expect(response.body.data[0].params.severity).to.equal('low'); + expect(response.body.data[1].params.severity).to.equal('medium'); + expect(response.body.data[2].params.severity).to.equal('high'); + }); + + it('should search by parameters', async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + search_fields: 'params.severity', + search: 'medium', + }); + + expect(response.status).to.eql(200); + expect(response.body.total).to.equal(1); + expect(response.body.data[0].params.severity).to.eql('medium'); + }); + + it('should filter on parameters', async () => { + const response = await supertest + .get(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + filter: 'alert.attributes.params.risk_score:40', + }); + + expect(response.status).to.eql(200); + expect(response.body.total).to.equal(1); + expect(response.body.data[0].params.risk_score).to.eql(40); + }); + + it('should error if filtering on mapped parameters directly using the public API', async () => { + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'foo') + .send({ + filter: 'alert.attributes.mapped_params.risk_score:40', + }); + + expect(response.status).to.eql(200); + }); + }); + + describe('legacy', function () { + this.tags('skipFIPS'); + it('should handle find alert request appropriately', async () => { + const { body: createdAlert } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send(getTestRuleData()) + .expect(200); + objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting'); + + const response = await supertest.get( + `${getUrlPrefix( + Spaces.space1.id + )}/api/alerts/_find?search=test.noop&search_fields=alertTypeId` + ); + + expect(response.status).to.eql(200); + expect(response.body.page).to.equal(1); + expect(response.body.perPage).to.be.greaterThan(0); + expect(response.body.total).to.be.greaterThan(0); + const match = response.body.data.find((obj: any) => obj.id === createdAlert.id); + expect(match).to.eql({ + id: createdAlert.id, + name: 'abc', + tags: ['foo'], + alertTypeId: 'test.noop', + consumer: 'alertsFixture', + schedule: { interval: '1m' }, + enabled: true, + actions: [], + params: {}, + createdBy: null, + apiKeyOwner: null, + apiKeyCreatedByUser: null, + scheduledTaskId: match.scheduledTaskId, + updatedBy: null, + throttle: '1m', + notifyWhen: 'onThrottleInterval', + muteAll: false, + mutedInstanceIds: [], + createdAt: match.createdAt, + updatedAt: match.updatedAt, + executionStatus: match.executionStatus, + revision: 0, + running: false, + ...(match.nextRun ? { nextRun: match.nextRun } : {}), + ...(match.lastRun ? { lastRun: match.lastRun } : {}), + }); + expect(Date.parse(match.createdAt)).to.be.greaterThan(0); + expect(Date.parse(match.updatedAt)).to.be.greaterThan(0); + }); + }); + }); +} diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/update.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/update.ts index 029775fbba383..025fa3b693dce 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/update.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/update.ts @@ -91,11 +91,10 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { expect(Date.parse(response.body.next_run)).to.be.greaterThan(0); } - response = await supertest.get( - `${getUrlPrefix( - Spaces.space1.id - )}/internal/alerting/rules/_find?filter=alert.attributes.params.risk_score:40` - ); + response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) + .set('kbn-xsrf', 'kibana') + .send({ filter: `alert.attributes.params.risk_score:40` }); expect(response.body.data[0].mapped_params).to.eql({ risk_score: 40, diff --git a/x-pack/test/observability_functional/apps/observability/pages/alerts/custom_threshold.ts b/x-pack/test/observability_functional/apps/observability/pages/alerts/custom_threshold.ts index 38d308a17e7b0..91cb7eec19ef6 100644 --- a/x-pack/test/observability_functional/apps/observability/pages/alerts/custom_threshold.ts +++ b/x-pack/test/observability_functional/apps/observability/pages/alerts/custom_threshold.ts @@ -209,7 +209,10 @@ export default ({ getService }: FtrProviderContext) => { }); it('saved the rule correctly', async () => { - const { body: rules } = await supertest.get('/internal/alerting/rules/_find'); + const { body: rules } = await supertest + .post('/internal/alerting/rules/_find') + .set('kbn-xsrf', 'kibana') + .send({}); expect(rules.data.length).toEqual(1); expect(rules.data[0]).toEqual( diff --git a/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts b/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts index abc2534efaf8a..4ec0f412e1f03 100644 --- a/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts +++ b/x-pack/test/observability_functional/apps/observability/pages/rules_page.ts @@ -29,7 +29,12 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => { const { body: { data: rules }, } = await supertest - .get(`${INTERNAL_RULE_ENDPOINT}/_find?search=${name}&search_fields=name`) + .post(`${INTERNAL_RULE_ENDPOINT}/_find`) + .set('kbn-xsrf', 'kibana') + .send({ + search: name, + search_fields: ['name'], + }) .expect(200); return rules.find((rule: any) => rule.name === name); } diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/rule_actions/snoozing/rule_snoozing.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/rule_actions/snoozing/rule_snoozing.cy.ts index 270a9146f65a9..9622cb94bdd4f 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/rule_actions/snoozing/rule_snoozing.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/rule_actions/snoozing/rule_snoozing.cy.ts @@ -217,7 +217,7 @@ describe('rule snoozing', { tags: ['@ess', '@serverless', '@skipInServerlessMKI' describe('Handling errors', () => { it('shows an error if unable to load snooze settings', () => { createRule(getNewRule({ name: 'Test rule', enabled: false })).then(({ body: rule }) => { - cy.intercept('GET', `${INTERNAL_ALERTING_API_FIND_RULES_PATH}*`, { + cy.intercept('POST', `${INTERNAL_ALERTING_API_FIND_RULES_PATH}*`, { statusCode: 500, }); From 72774b12d22385dd0da71abeae8fd3243409660e Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:32:33 +1100 Subject: [PATCH 15/33] [8.x] [ES|QL] Supports _index_mode in the metadata options (#197167) (#197322) # Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Supports _index_mode in the metadata options (#197167)](https://github.com/elastic/kibana/pull/197167) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Stratoula Kalafateli --- .../src/autocomplete/autocomplete.test.ts | 2 +- .../kbn-esql-validation-autocomplete/src/shared/constants.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts index e463902554074..deb4592428089 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts @@ -1123,7 +1123,7 @@ describe('autocomplete', () => { { filterText: '_source', text: '_source, ', command: TRIGGER_SUGGESTION_COMMAND }, ]); // no comma if there are no more fields - testSuggestions('FROM a METADATA _id, _ignored, _index, _source, _version/', [ + testSuggestions('FROM a METADATA _id, _ignored, _index, _source, _index_mode, _version/', [ { filterText: '_version', text: '_version | ', command: TRIGGER_SUGGESTION_COMMAND }, ]); }); diff --git a/packages/kbn-esql-validation-autocomplete/src/shared/constants.ts b/packages/kbn-esql-validation-autocomplete/src/shared/constants.ts index c1942118a41e2..1a9f382d32a6d 100644 --- a/packages/kbn-esql-validation-autocomplete/src/shared/constants.ts +++ b/packages/kbn-esql-validation-autocomplete/src/shared/constants.ts @@ -15,4 +15,4 @@ export const SINGLE_TICK_REGEX = /`/g; export const DOUBLE_BACKTICK = '``'; export const SINGLE_BACKTICK = '`'; -export const METADATA_FIELDS = ['_version', '_id', '_index', '_source', '_ignored']; +export const METADATA_FIELDS = ['_version', '_id', '_index', '_source', '_ignored', '_index_mode']; From b3fef2a4ca384ac9197a17537a71a8e9e62c44a2 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:34:07 +1100 Subject: [PATCH 16/33] [8.x] [ES|QL] Normalize multiplication by one when pretty-printing (#197182) (#197318) # Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Normalize multiplication by one when pretty-printing (#197182)](https://github.com/elastic/kibana/pull/197182) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Vadim Kibana <82822460+vadimkibana@users.noreply.github.com> --- packages/kbn-esql-ast/src/ast/helpers.ts | 27 ++++++- .../__tests__/basic_pretty_printer.test.ts | 62 ++++++++++++++- .../src/pretty_print/basic_pretty_printer.ts | 79 ++++++++++++++++++- .../kbn-esql-ast/src/pretty_print/helpers.ts | 2 +- packages/kbn-esql-ast/src/visitor/utils.ts | 4 + 5 files changed, 169 insertions(+), 5 deletions(-) diff --git a/packages/kbn-esql-ast/src/ast/helpers.ts b/packages/kbn-esql-ast/src/ast/helpers.ts index 9ca49dcb38822..74a7b5c0991e8 100644 --- a/packages/kbn-esql-ast/src/ast/helpers.ts +++ b/packages/kbn-esql-ast/src/ast/helpers.ts @@ -7,11 +7,22 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { ESQLAstNode, ESQLBinaryExpression, ESQLFunction } from '../types'; +import type { + ESQLAstNode, + ESQLBinaryExpression, + ESQLColumn, + ESQLFunction, + ESQLIntegerLiteral, + ESQLLiteral, + ESQLProperNode, +} from '../types'; import { BinaryExpressionGroup } from './constants'; +export const isProperNode = (node: unknown): node is ESQLProperNode => + !!node && typeof node === 'object' && !Array.isArray(node); + export const isFunctionExpression = (node: unknown): node is ESQLFunction => - !!node && typeof node === 'object' && !Array.isArray(node) && (node as any).type === 'function'; + isProperNode(node) && node.type === 'function'; /** * Returns true if the given node is a binary expression, i.e. an operator @@ -28,6 +39,18 @@ export const isFunctionExpression = (node: unknown): node is ESQLFunction => export const isBinaryExpression = (node: unknown): node is ESQLBinaryExpression => isFunctionExpression(node) && node.subtype === 'binary-expression'; +export const isLiteral = (node: unknown): node is ESQLLiteral => + isProperNode(node) && node.type === 'literal'; + +export const isIntegerLiteral = (node: unknown): node is ESQLIntegerLiteral => + isLiteral(node) && node.literalType === 'integer'; + +export const isDoubleLiteral = (node: unknown): node is ESQLIntegerLiteral => + isLiteral(node) && node.literalType === 'double'; + +export const isColumn = (node: unknown): node is ESQLColumn => + isProperNode(node) && node.type === 'column'; + /** * Returns the group of a binary expression: * diff --git a/packages/kbn-esql-ast/src/pretty_print/__tests__/basic_pretty_printer.test.ts b/packages/kbn-esql-ast/src/pretty_print/__tests__/basic_pretty_printer.test.ts index 20db9e729f094..9e21c45f75b4b 100644 --- a/packages/kbn-esql-ast/src/pretty_print/__tests__/basic_pretty_printer.test.ts +++ b/packages/kbn-esql-ast/src/pretty_print/__tests__/basic_pretty_printer.test.ts @@ -16,7 +16,7 @@ const reprint = (src: string) => { const { root } = parse(src); const text = BasicPrettyPrinter.print(root); - // console.log(JSON.stringify(ast, null, 2)); + // console.log(JSON.stringify(root, null, 2)); return { text }; }; @@ -194,6 +194,66 @@ describe('single line query', () => { expect(text).toBe('ROW NOT a'); }); + + test('negative numbers', () => { + const { text } = reprint('ROW -1'); + + expect(text).toBe('ROW -1'); + }); + + test('negative numbers in brackets', () => { + const { text } = reprint('ROW -(1)'); + + expect(text).toBe('ROW -1'); + }); + + test('negative column names', () => { + const { text } = reprint('ROW -col'); + + expect(text).toBe('ROW -col'); + }); + + test('plus unary expression', () => { + const { text } = reprint('ROW +(23)'); + + expect(text).toBe('ROW 23'); + }); + + test('chained multiple unary expressions', () => { + const { text } = reprint('ROW ----+-+(23)'); + + expect(text).toBe('ROW -23'); + }); + + test('before another expression', () => { + const { text } = reprint('ROW ----+-+(1 + 1)'); + + expect(text).toBe('ROW -(1 + 1)'); + }); + + test('negative one from the right side', () => { + const { text } = reprint('ROW 2 * -1'); + + expect(text).toBe('ROW -2'); + }); + + test('two minuses is plus', () => { + const { text } = reprint('ROW --123'); + + expect(text).toBe('ROW 123'); + }); + + test('two minuses is plus (float)', () => { + const { text } = reprint('ROW --1.23'); + + expect(text).toBe('ROW 1.23'); + }); + + test('two minuses is plus (with brackets)', () => { + const { text } = reprint('ROW --(123)'); + + expect(text).toBe('ROW 123'); + }); }); describe('postfix unary expression', () => { diff --git a/packages/kbn-esql-ast/src/pretty_print/basic_pretty_printer.ts b/packages/kbn-esql-ast/src/pretty_print/basic_pretty_printer.ts index ec744c65f636e..2f1e3439cd3a3 100644 --- a/packages/kbn-esql-ast/src/pretty_print/basic_pretty_printer.ts +++ b/packages/kbn-esql-ast/src/pretty_print/basic_pretty_printer.ts @@ -7,9 +7,18 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { binaryExpressionGroup } from '../ast/helpers'; +import { + binaryExpressionGroup, + isBinaryExpression, + isColumn, + isDoubleLiteral, + isIntegerLiteral, + isLiteral, + isProperNode, +} from '../ast/helpers'; import { ESQLAstBaseItem, ESQLAstCommand, ESQLAstQueryExpression } from '../types'; import { ESQLAstExpressionNode, Visitor } from '../visitor'; +import { resolveItem } from '../visitor/utils'; import { LeafPrinter } from './leaf_printer'; export interface BasicPrettyPrinterOptions { @@ -152,6 +161,62 @@ export class BasicPrettyPrinter { return formatted; } + protected simplifyMultiplicationByOne( + node: ESQLAstExpressionNode, + minusCount: number = 0 + ): string | undefined { + if (isBinaryExpression(node) && node.name === '*') { + let [left, right] = node.args; + left = resolveItem(left); + right = resolveItem(right); + + if (isProperNode(left) && isProperNode(right)) { + if (!!left.formatting || !!right.formatting) { + return undefined; + } + if (isIntegerLiteral(left)) { + if (left.value === 1) { + return this.simplifyMultiplicationByOne(right, minusCount); + } else if (left.value === -1) { + return this.simplifyMultiplicationByOne(right, minusCount + 1); + } + } + if (isIntegerLiteral(right)) { + if (right.value === 1) { + return this.simplifyMultiplicationByOne(left, minusCount); + } else if (right.value === -1) { + return this.simplifyMultiplicationByOne(left, minusCount + 1); + } + } + return undefined; + } else { + return undefined; + } + } + + const isNegative = minusCount % 2 === 1; + + if (isNegative && (isIntegerLiteral(node) || isDoubleLiteral(node)) && node.value < 0) { + return BasicPrettyPrinter.expression( + { + ...node, + value: Math.abs(node.value), + }, + this.opts + ); + } + + let expression = BasicPrettyPrinter.expression(node, this.opts); + const sign = isNegative ? '-' : ''; + const needsBrackets = !!sign && !isColumn(node) && !isLiteral(node); + + if (needsBrackets) { + expression = `(${expression})`; + } + + return sign ? `${sign}${expression}` : expression; + } + protected readonly visitor: Visitor = new Visitor() .on('visitExpression', (ctx) => { return ''; @@ -237,6 +302,18 @@ export class BasicPrettyPrinter { const groupLeft = binaryExpressionGroup(left); const groupRight = binaryExpressionGroup(right); + if ( + node.name === '*' && + ((isIntegerLiteral(left) && Math.abs(left.value) === 1) || + (isIntegerLiteral(right) && Math.abs(right.value) === 1)) + ) { + const formatted = this.simplifyMultiplicationByOne(node); + + if (formatted) { + return formatted; + } + } + let leftFormatted = ctx.visitArgument(0); let rightFormatted = ctx.visitArgument(1); diff --git a/packages/kbn-esql-ast/src/pretty_print/helpers.ts b/packages/kbn-esql-ast/src/pretty_print/helpers.ts index f9d9daac84e7a..1b4a75a119cb2 100644 --- a/packages/kbn-esql-ast/src/pretty_print/helpers.ts +++ b/packages/kbn-esql-ast/src/pretty_print/helpers.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { ESQLAstBaseItem, ESQLProperNode } from '../types'; +import type { ESQLAstBaseItem, ESQLProperNode } from '../types'; import { Walker } from '../walker'; export interface QueryPrettyPrintStats { diff --git a/packages/kbn-esql-ast/src/visitor/utils.ts b/packages/kbn-esql-ast/src/visitor/utils.ts index 0dc95b73cf9d7..da8544ef46c90 100644 --- a/packages/kbn-esql-ast/src/visitor/utils.ts +++ b/packages/kbn-esql-ast/src/visitor/utils.ts @@ -36,6 +36,10 @@ export const firstItem = (items: ESQLAstItem[]): ESQLSingleAstItem | undefined = } }; +export const resolveItem = (items: ESQLAstItem | ESQLAstItem[]): ESQLAstItem => { + return Array.isArray(items) ? resolveItem(items[0]) : items; +}; + /** * Returns the last normalized "single item" from the "item" list. * From 87612c3a59c038a955e9944edb8e7873b7fd2955 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:26:27 +1100 Subject: [PATCH 17/33] [8.x] [Dashboard][ES|QL] Allow creating a dashboard with ES|QL chart even when there are no dataviews (#196658) (#197366) # Backport This will backport the following commits from `main` to `8.x`: - [[Dashboard][ES|QL] Allow creating a dashboard with ES|QL chart even when there are no dataviews (#196658)](https://github.com/elastic/kibana/pull/196658) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Stratoula Kalafateli --- src/plugins/dashboard/kibana.jsonc | 5 +- .../no_data/dashboard_app_no_data.tsx | 100 +++++++++++++++++- src/plugins/dashboard/public/plugin.tsx | 3 + .../public/services/kibana_services.ts | 3 + src/plugins/dashboard/tsconfig.json | 1 + .../group6/dashboard_esql_no_data.ts | 14 ++- 6 files changed, 116 insertions(+), 10 deletions(-) diff --git a/src/plugins/dashboard/kibana.jsonc b/src/plugins/dashboard/kibana.jsonc index 2bf60cde55ef0..d7b0f2c16e04b 100644 --- a/src/plugins/dashboard/kibana.jsonc +++ b/src/plugins/dashboard/kibana.jsonc @@ -24,7 +24,7 @@ "urlForwarding", "presentationUtil", "visualizations", - "unifiedSearch" + "unifiedSearch", ], "optionalPlugins": [ "home", @@ -35,7 +35,8 @@ "taskManager", "serverless", "noDataPage", - "observabilityAIAssistant" + "observabilityAIAssistant", + "lens" ], "requiredBundles": [ "kibanaReact", diff --git a/src/plugins/dashboard/public/dashboard_app/no_data/dashboard_app_no_data.tsx b/src/plugins/dashboard/public/dashboard_app/no_data/dashboard_app_no_data.tsx index 15b3d00d07ec7..366726267c311 100644 --- a/src/plugins/dashboard/public/dashboard_app/no_data/dashboard_app_no_data.tsx +++ b/src/plugins/dashboard/public/dashboard_app/no_data/dashboard_app_no_data.tsx @@ -7,9 +7,19 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import React from 'react'; - +import React, { useCallback, useEffect, useState } from 'react'; +import { i18n } from '@kbn/i18n'; +import useAsync from 'react-use/lib/useAsync'; +import { v4 as uuidv4 } from 'uuid'; +import { + getESQLAdHocDataview, + getESQLQueryColumns, + getIndexForESQLQuery, + getInitialESQLQuery, +} from '@kbn/esql-utils'; import { withSuspense } from '@kbn/shared-ux-utility'; +import type { TypedLensByValueInput } from '@kbn/lens-plugin/public'; +import { getLensAttributesFromSuggestion } from '@kbn/visualization-utils'; import { DASHBOARD_APP_ID } from '../../dashboard_constants'; import { @@ -19,10 +29,15 @@ import { embeddableService, noDataPageService, shareService, + lensService, } from '../../services/kibana_services'; import { getDashboardBackupService } from '../../services/dashboard_backup_service'; import { getDashboardContentManagementService } from '../../services/dashboard_content_management_service'; +function generateId() { + return uuidv4(); +} + export const DashboardAppNoDataPage = ({ onDataViewCreated, }: { @@ -35,7 +50,7 @@ export const DashboardAppNoDataPage = ({ noDataPage: noDataPageService, share: shareService, }; - + const [abortController, setAbortController] = useState(new AbortController()); const importPromise = import('@kbn/shared-ux-page-analytics-no-data'); const AnalyticsNoDataPageKibanaProvider = withSuspense( React.lazy(() => @@ -44,6 +59,83 @@ export const DashboardAppNoDataPage = ({ }) ) ); + + const lensHelpersAsync = useAsync(() => { + return lensService?.stateHelperApi() ?? Promise.resolve(null); + }, [lensService]); + + useEffect(() => { + return () => { + abortController?.abort(); + }; + }, [abortController]); + + const onTryESQL = useCallback(async () => { + abortController?.abort(); + if (lensHelpersAsync.value) { + const abc = new AbortController(); + const { dataViews } = dataService; + const indexName = (await getIndexForESQLQuery({ dataViews })) ?? '*'; + const dataView = await getESQLAdHocDataview(`from ${indexName}`, dataViews); + const esqlQuery = getInitialESQLQuery(dataView); + + try { + const columns = await getESQLQueryColumns({ + esqlQuery, + search: dataService.search.search, + signal: abc.signal, + timeRange: dataService.query.timefilter.timefilter.getAbsoluteTime(), + }); + + // lens suggestions api context + const context = { + dataViewSpec: dataView?.toSpec(false), + fieldName: '', + textBasedColumns: columns, + query: { esql: esqlQuery }, + }; + + setAbortController(abc); + + const chartSuggestions = lensHelpersAsync.value.suggestions(context, dataView); + if (chartSuggestions?.length) { + const [suggestion] = chartSuggestions; + + const attrs = getLensAttributesFromSuggestion({ + filters: [], + query: { + esql: esqlQuery, + }, + suggestion, + dataView, + }) as TypedLensByValueInput['attributes']; + + const lensEmbeddableInput = { + attributes: attrs, + id: generateId(), + }; + + await embeddableService.getStateTransfer().navigateToWithEmbeddablePackage('dashboards', { + state: { + type: 'lens', + input: lensEmbeddableInput, + }, + path: '#/create', + }); + } + } catch (error) { + if (error.name !== 'AbortError') { + coreServices.notifications.toasts.addWarning( + i18n.translate('dashboard.noDataviews.esqlRequestWarningMessage', { + defaultMessage: 'Unable to load columns. {errorMessage}', + values: { errorMessage: error.message }, + }) + ); + } + } + } + }, [abortController, lensHelpersAsync.value]); + const AnalyticsNoDataPage = withSuspense( React.lazy(() => importPromise.then(({ AnalyticsNoDataPage: NoDataPage }) => { @@ -54,7 +146,7 @@ export const DashboardAppNoDataPage = ({ return ( - + ); }; diff --git a/src/plugins/dashboard/public/plugin.tsx b/src/plugins/dashboard/public/plugin.tsx index b7a920eb08ce3..a8e7cd96f38db 100644 --- a/src/plugins/dashboard/public/plugin.tsx +++ b/src/plugins/dashboard/public/plugin.tsx @@ -27,6 +27,7 @@ import { type CoreStart, } from '@kbn/core/public'; import type { DataPublicPluginSetup, DataPublicPluginStart } from '@kbn/data-plugin/public'; +import type { LensPublicSetup, LensPublicStart } from '@kbn/lens-plugin/public'; import type { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public'; import type { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public'; import { FieldFormatsStart } from '@kbn/field-formats-plugin/public/plugin'; @@ -96,6 +97,7 @@ export interface DashboardSetupDependencies { urlForwarding: UrlForwardingSetup; unifiedSearch: UnifiedSearchPublicPluginStart; observabilityAIAssistant?: ObservabilityAIAssistantPublicSetup; + lens?: LensPublicSetup; } export interface DashboardStartDependencies { @@ -120,6 +122,7 @@ export interface DashboardStartDependencies { customBranding: CustomBrandingStart; serverless?: ServerlessPluginStart; noDataPage?: NoDataPagePluginStart; + lens?: LensPublicStart; observabilityAIAssistant?: ObservabilityAIAssistantPublicStart; } diff --git a/src/plugins/dashboard/public/services/kibana_services.ts b/src/plugins/dashboard/public/services/kibana_services.ts index e8b164d47b413..e3fde8c37c2a9 100644 --- a/src/plugins/dashboard/public/services/kibana_services.ts +++ b/src/plugins/dashboard/public/services/kibana_services.ts @@ -18,6 +18,7 @@ import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public/plugin' import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public'; import type { NoDataPagePluginStart } from '@kbn/no-data-page-plugin/public'; import type { ObservabilityAIAssistantPublicStart } from '@kbn/observability-ai-assistant-plugin/public'; +import type { LensPublicStart } from '@kbn/lens-plugin/public'; import type { PresentationUtilPluginStart } from '@kbn/presentation-util-plugin/public'; import type { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public'; import type { ScreenshotModePluginStart } from '@kbn/screenshot-mode-plugin/public'; @@ -40,6 +41,7 @@ export let fieldFormatService: FieldFormatsStart; export let navigationService: NavigationPublicPluginStart; export let noDataPageService: NoDataPagePluginStart | undefined; export let observabilityAssistantService: ObservabilityAIAssistantPublicStart | undefined; +export let lensService: LensPublicStart | undefined; export let presentationUtilService: PresentationUtilPluginStart; export let savedObjectsTaggingService: SavedObjectTaggingOssPluginStart | undefined; export let screenshotModeService: ScreenshotModePluginStart; @@ -63,6 +65,7 @@ export const setKibanaServices = (kibanaCore: CoreStart, deps: DashboardStartDep navigationService = deps.navigation; noDataPageService = deps.noDataPage; observabilityAssistantService = deps.observabilityAIAssistant; + lensService = deps.lens; presentationUtilService = deps.presentationUtil; savedObjectsTaggingService = deps.savedObjectsTaggingOss; serverlessService = deps.serverless; diff --git a/src/plugins/dashboard/tsconfig.json b/src/plugins/dashboard/tsconfig.json index 57125918ef3fc..3e95675ea64c3 100644 --- a/src/plugins/dashboard/tsconfig.json +++ b/src/plugins/dashboard/tsconfig.json @@ -80,6 +80,7 @@ "@kbn/content-management-favorites-public", "@kbn/core-custom-branding-browser-mocks", "@kbn/core-mount-utils-browser", + "@kbn/visualization-utils", ], "exclude": ["target/**/*"] } diff --git a/test/functional/apps/dashboard/group6/dashboard_esql_no_data.ts b/test/functional/apps/dashboard/group6/dashboard_esql_no_data.ts index 148cb95a82b11..333ac7f015397 100644 --- a/test/functional/apps/dashboard/group6/dashboard_esql_no_data.ts +++ b/test/functional/apps/dashboard/group6/dashboard_esql_no_data.ts @@ -6,14 +6,16 @@ * your election, the "Elastic License 2.0", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ +import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ getService, getPageObjects }: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const testSubjects = getService('testSubjects'); - const esql = getService('esql'); - const PageObjects = getPageObjects(['discover', 'dashboard']); + const panelActions = getService('dashboardPanelActions'); + const monacoEditor = getService('monacoEditor'); + const PageObjects = getPageObjects(['dashboard']); describe('No Data Views: Try ES|QL', () => { before(async () => { @@ -26,8 +28,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await testSubjects.existOrFail('noDataViewsPrompt'); await testSubjects.click('tryESQLLink'); - await PageObjects.discover.expectOnDiscover(); - await esql.expectEsqlStatement('FROM logs* | LIMIT 10'); + await PageObjects.dashboard.expectOnDashboard('New Dashboard'); + expect(await testSubjects.exists('lnsVisualizationContainer')).to.be(true); + + await panelActions.clickInlineEdit(); + const editorValue = await monacoEditor.getCodeEditorValue(); + expect(editorValue).to.eql(`FROM logs* | LIMIT 10`); }); }); } From 7e238131e6a411ced6abeba1805e6b10a91a953a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:28:43 +1100 Subject: [PATCH 18/33] [8.x] [ResponseOps][Rules] Create the rule params package (#196971) (#197367) # Backport This will backport the following commits from `main` to `8.x`: - [[ResponseOps][Rules] Create the rule params package (#196971)](https://github.com/elastic/kibana/pull/196971) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Christos Nasikas --- .github/CODEOWNERS | 1 + package.json | 1 + packages/response-ops/rule_params/README.md | 3 +++ packages/response-ops/rule_params/index.ts | 23 ++++++++++++++++ .../response-ops/rule_params/jest.config.js | 14 ++++++++++ .../response-ops/rule_params/kibana.jsonc | 5 ++++ packages/response-ops/rule_params/latest.ts | 10 +++++++ .../response-ops/rule_params/package.json | 6 +++++ .../response-ops/rule_params/tsconfig.json | 19 ++++++++++++++ packages/response-ops/rule_params/v1.ts | 26 +++++++++++++++++++ tsconfig.base.json | 2 ++ .../routes/backfill/response/schemas/v1.ts | 3 ++- .../routes/rule/apis/create/schemas/v1.ts | 6 ++--- .../routes/rule/apis/update/schemas/v1.ts | 6 ++--- .../common/routes/rule/response/index.ts | 17 +++++------- .../common/routes/rule/response/schemas/v1.ts | 6 ++--- .../common/routes/rule/response/types/v1.ts | 5 ++-- .../backfill/result/schemas/index.ts | 3 ++- .../create/schemas/create_rule_data_schema.ts | 3 ++- .../update/schemas/update_rule_data_schema.ts | 3 ++- .../application/rule/schemas/rule_schemas.ts | 2 +- .../server/application/rule/types/rule.ts | 2 +- x-pack/plugins/alerting/tsconfig.json | 3 ++- yarn.lock | 4 +++ 24 files changed, 141 insertions(+), 32 deletions(-) create mode 100644 packages/response-ops/rule_params/README.md create mode 100644 packages/response-ops/rule_params/index.ts create mode 100644 packages/response-ops/rule_params/jest.config.js create mode 100644 packages/response-ops/rule_params/kibana.jsonc create mode 100644 packages/response-ops/rule_params/latest.ts create mode 100644 packages/response-ops/rule_params/package.json create mode 100644 packages/response-ops/rule_params/tsconfig.json create mode 100644 packages/response-ops/rule_params/v1.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2e71f23309f81..2371e7d9f7a51 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -727,6 +727,7 @@ packages/kbn-resizable-layout @elastic/kibana-data-discovery examples/resizable_layout_examples @elastic/kibana-data-discovery x-pack/test/plugin_functional/plugins/resolver_test @elastic/security-solution packages/response-ops/feature_flag_service @elastic/response-ops +packages/response-ops/rule_params @elastic/response-ops examples/response_stream @elastic/ml-ui packages/kbn-rison @elastic/kibana-operations x-pack/packages/rollup @elastic/kibana-management diff --git a/package.json b/package.json index d0778dba1fb2c..643a3ffe1a4c8 100644 --- a/package.json +++ b/package.json @@ -746,6 +746,7 @@ "@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples", "@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test", "@kbn/response-ops-feature-flag-service": "link:packages/response-ops/feature_flag_service", + "@kbn/response-ops-rule-params": "link:packages/response-ops/rule_params", "@kbn/response-stream-plugin": "link:examples/response_stream", "@kbn/rison": "link:packages/kbn-rison", "@kbn/rollup": "link:x-pack/packages/rollup", diff --git a/packages/response-ops/rule_params/README.md b/packages/response-ops/rule_params/README.md new file mode 100644 index 0000000000000..8cc747bf38864 --- /dev/null +++ b/packages/response-ops/rule_params/README.md @@ -0,0 +1,3 @@ +# @kbn/response-ops-rule-params + +The package is responsible for the parameters' schema of all rule types. The alerting plugin uses this package to generate OAS documentation for the `params` property in the rule in requests and responses. diff --git a/packages/response-ops/rule_params/index.ts b/packages/response-ops/rule_params/index.ts new file mode 100644 index 0000000000000..a5ce640a4c5d4 --- /dev/null +++ b/packages/response-ops/rule_params/index.ts @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export { ruleParamsSchema, ruleParamsSchemaWithDefaultValue } from './latest'; + +export { + ruleParamsSchema as ruleParamsSchemaV1, + ruleParamsSchemaWithDefaultValue as ruleParamsSchemaWithDefaultValueV1, +} from './v1'; + +export type { RuleParams } from './latest'; +export type { RuleParamsWithDefaultValue } from './latest'; + +export type { + RuleParams as RuleParamsV1, + RuleParamsWithDefaultValue as RuleParamsWithDefaultValueV1, +} from './v1'; diff --git a/packages/response-ops/rule_params/jest.config.js b/packages/response-ops/rule_params/jest.config.js new file mode 100644 index 0000000000000..ee60f7ea42272 --- /dev/null +++ b/packages/response-ops/rule_params/jest.config.js @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../..', + roots: ['/packages/response-ops/rule_params'], +}; diff --git a/packages/response-ops/rule_params/kibana.jsonc b/packages/response-ops/rule_params/kibana.jsonc new file mode 100644 index 0000000000000..6a6744a58c4a1 --- /dev/null +++ b/packages/response-ops/rule_params/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/response-ops-rule-params", + "owner": "@elastic/response-ops" +} diff --git a/packages/response-ops/rule_params/latest.ts b/packages/response-ops/rule_params/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/packages/response-ops/rule_params/latest.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export * from './v1'; diff --git a/packages/response-ops/rule_params/package.json b/packages/response-ops/rule_params/package.json new file mode 100644 index 0000000000000..43145b8d5da4c --- /dev/null +++ b/packages/response-ops/rule_params/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/response-ops-rule-params", + "private": true, + "version": "1.0.0", + "license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0" +} \ No newline at end of file diff --git a/packages/response-ops/rule_params/tsconfig.json b/packages/response-ops/rule_params/tsconfig.json new file mode 100644 index 0000000000000..3df73f778fdc1 --- /dev/null +++ b/packages/response-ops/rule_params/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/config-schema", + ] +} diff --git a/packages/response-ops/rule_params/v1.ts b/packages/response-ops/rule_params/v1.ts new file mode 100644 index 0000000000000..a083f67f10c8c --- /dev/null +++ b/packages/response-ops/rule_params/v1.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { TypeOf, schema } from '@kbn/config-schema'; + +export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), { + meta: { description: 'The parameters for the rule.' }, +}); + +export const ruleParamsSchemaWithDefaultValue = schema.recordOf( + schema.string(), + schema.maybe(schema.any()), + { + defaultValue: {}, + meta: { description: 'The parameters for the rule.' }, + } +); + +export type RuleParams = TypeOf; +export type RuleParamsWithDefaultValue = TypeOf; diff --git a/tsconfig.base.json b/tsconfig.base.json index 43b35e31ea905..b68b2e8703138 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1448,6 +1448,8 @@ "@kbn/resolver-test-plugin/*": ["x-pack/test/plugin_functional/plugins/resolver_test/*"], "@kbn/response-ops-feature-flag-service": ["packages/response-ops/feature_flag_service"], "@kbn/response-ops-feature-flag-service/*": ["packages/response-ops/feature_flag_service/*"], + "@kbn/response-ops-rule-params": ["packages/response-ops/rule_params"], + "@kbn/response-ops-rule-params/*": ["packages/response-ops/rule_params/*"], "@kbn/response-stream-plugin": ["examples/response_stream"], "@kbn/response-stream-plugin/*": ["examples/response_stream/*"], "@kbn/rison": ["packages/kbn-rison"], diff --git a/x-pack/plugins/alerting/common/routes/backfill/response/schemas/v1.ts b/x-pack/plugins/alerting/common/routes/backfill/response/schemas/v1.ts index 268ef7f5e90d1..5da51d53dddbb 100644 --- a/x-pack/plugins/alerting/common/routes/backfill/response/schemas/v1.ts +++ b/x-pack/plugins/alerting/common/routes/backfill/response/schemas/v1.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params'; import { adHocRunStatus } from '../../../../constants'; export const statusSchema = schema.oneOf([ @@ -26,7 +27,7 @@ export const backfillResponseSchema = schema.object({ name: schema.string(), tags: schema.arrayOf(schema.string()), rule_type_id: schema.string(), - params: schema.recordOf(schema.string(), schema.maybe(schema.any())), + params: ruleParamsSchemaV1, api_key_owner: schema.nullable(schema.string()), api_key_created_by_user: schema.maybe(schema.nullable(schema.boolean())), consumer: schema.string(), diff --git a/x-pack/plugins/alerting/common/routes/rule/apis/create/schemas/v1.ts b/x-pack/plugins/alerting/common/routes/rule/apis/create/schemas/v1.ts index d9157850bfd8d..e70df7f9dc73f 100644 --- a/x-pack/plugins/alerting/common/routes/rule/apis/create/schemas/v1.ts +++ b/x-pack/plugins/alerting/common/routes/rule/apis/create/schemas/v1.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchemaWithDefaultValueV1 } from '@kbn/response-ops-rule-params'; import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation'; import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response'; import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query'; @@ -166,10 +167,7 @@ export const createBodySchema = schema.object({ }) ) ), - params: schema.recordOf(schema.string(), schema.maybe(schema.any()), { - defaultValue: {}, - meta: { description: 'The parameters for the rule.' }, - }), + params: ruleParamsSchemaWithDefaultValueV1, schedule: schema.object( { interval: schema.string({ diff --git a/x-pack/plugins/alerting/common/routes/rule/apis/update/schemas/v1.ts b/x-pack/plugins/alerting/common/routes/rule/apis/update/schemas/v1.ts index e83e26f119595..b838d21e5cc03 100644 --- a/x-pack/plugins/alerting/common/routes/rule/apis/update/schemas/v1.ts +++ b/x-pack/plugins/alerting/common/routes/rule/apis/update/schemas/v1.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchemaWithDefaultValueV1 } from '@kbn/response-ops-rule-params'; import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation'; import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response'; import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query'; @@ -152,10 +153,7 @@ export const updateBodySchema = schema.object({ }) ) ), - params: schema.recordOf(schema.string(), schema.any(), { - defaultValue: {}, - meta: { description: 'The parameters for the rule.' }, - }), + params: ruleParamsSchemaWithDefaultValueV1, actions: schema.arrayOf(actionSchema, { defaultValue: [] }), notify_when: schema.maybe(schema.nullable(notifyWhenSchemaV1)), alert_delay: schema.maybe(alertDelaySchemaV1), diff --git a/x-pack/plugins/alerting/common/routes/rule/response/index.ts b/x-pack/plugins/alerting/common/routes/rule/response/index.ts index 8c784e744d473..1c7632ad28988 100644 --- a/x-pack/plugins/alerting/common/routes/rule/response/index.ts +++ b/x-pack/plugins/alerting/common/routes/rule/response/index.ts @@ -6,7 +6,6 @@ */ export { - ruleParamsSchema, actionParamsSchema, mappedParamsSchema, ruleExecutionStatusSchema, @@ -18,16 +17,9 @@ export { scheduleIdsSchema, } from './schemas/latest'; -export type { - RuleParams, - RuleResponse, - RuleSnoozeSchedule, - RuleLastRun, - Monitoring, -} from './types/latest'; +export type { RuleResponse, RuleSnoozeSchedule, RuleLastRun, Monitoring } from './types/latest'; export { - ruleParamsSchema as ruleParamsSchemaV1, actionParamsSchema as actionParamsSchemaV1, mappedParamsSchema as mappedParamsSchemaV1, ruleExecutionStatusSchema as ruleExecutionStatusSchemaV1, @@ -41,9 +33,14 @@ export { } from './schemas/v1'; export type { - RuleParams as RuleParamsV1, RuleResponse as RuleResponseV1, RuleSnoozeSchedule as RuleSnoozeScheduleV1, RuleLastRun as RuleLastRunV1, Monitoring as MonitoringV1, } from './types/v1'; + +export { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params'; +export { ruleParamsSchema } from '@kbn/response-ops-rule-params'; + +export type { RuleParamsV1 } from '@kbn/response-ops-rule-params'; +export type { RuleParams } from '@kbn/response-ops-rule-params'; diff --git a/x-pack/plugins/alerting/common/routes/rule/response/schemas/v1.ts b/x-pack/plugins/alerting/common/routes/rule/response/schemas/v1.ts index 29488b98d6ca8..069aca001d14f 100644 --- a/x-pack/plugins/alerting/common/routes/rule/response/schemas/v1.ts +++ b/x-pack/plugins/alerting/common/routes/rule/response/schemas/v1.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params'; import { rRuleResponseSchemaV1 } from '../../../r_rule'; import { alertsFilterQuerySchemaV1 } from '../../../alerts_filter_query'; import { @@ -18,9 +19,6 @@ import { import { validateNotifyWhenV1 } from '../../validation'; import { flappingSchemaV1 } from '../../common'; -export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), { - meta: { description: 'The parameters for the rule.' }, -}); export const actionParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), { meta: { description: @@ -497,7 +495,7 @@ export const ruleResponseSchema = schema.object({ }), schedule: intervalScheduleSchema, actions: schema.arrayOf(actionSchema), - params: ruleParamsSchema, + params: ruleParamsSchemaV1, mapped_params: schema.maybe(mappedParamsSchema), scheduled_task_id: schema.maybe( schema.string({ diff --git a/x-pack/plugins/alerting/common/routes/rule/response/types/v1.ts b/x-pack/plugins/alerting/common/routes/rule/response/types/v1.ts index e9a37eea1fe72..e32a56a302e63 100644 --- a/x-pack/plugins/alerting/common/routes/rule/response/types/v1.ts +++ b/x-pack/plugins/alerting/common/routes/rule/response/types/v1.ts @@ -6,22 +6,21 @@ */ import type { TypeOf } from '@kbn/config-schema'; +import { RuleParamsV1 } from '@kbn/response-ops-rule-params'; import { - ruleParamsSchemaV1, ruleResponseSchemaV1, ruleSnoozeScheduleSchemaV1, ruleLastRunSchemaV1, monitoringSchemaV1, } from '..'; -export type RuleParams = TypeOf; export type RuleSnoozeSchedule = TypeOf; export type RuleLastRun = TypeOf; export type Monitoring = TypeOf; type RuleResponseSchemaType = TypeOf; -export interface RuleResponse { +export interface RuleResponse { id: RuleResponseSchemaType['id']; enabled: RuleResponseSchemaType['enabled']; name: RuleResponseSchemaType['name']; diff --git a/x-pack/plugins/alerting/server/application/backfill/result/schemas/index.ts b/x-pack/plugins/alerting/server/application/backfill/result/schemas/index.ts index de3cc5926a4ae..b454d41dd40ca 100644 --- a/x-pack/plugins/alerting/server/application/backfill/result/schemas/index.ts +++ b/x-pack/plugins/alerting/server/application/backfill/result/schemas/index.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchema } from '@kbn/response-ops-rule-params'; import { adHocRunStatus } from '../../../../../common/constants'; export const statusSchema = schema.oneOf([ @@ -32,7 +33,7 @@ export const backfillSchema = schema.object({ name: schema.string(), tags: schema.arrayOf(schema.string()), alertTypeId: schema.string(), - params: schema.recordOf(schema.string(), schema.maybe(schema.any())), + params: ruleParamsSchema, apiKeyOwner: schema.nullable(schema.string()), apiKeyCreatedByUser: schema.maybe(schema.nullable(schema.boolean())), consumer: schema.string(), diff --git a/x-pack/plugins/alerting/server/application/rule/methods/create/schemas/create_rule_data_schema.ts b/x-pack/plugins/alerting/server/application/rule/methods/create/schemas/create_rule_data_schema.ts index 0672d7929fdb2..e2cf0da359b0a 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/create/schemas/create_rule_data_schema.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/create/schemas/create_rule_data_schema.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchemaWithDefaultValue } from '@kbn/response-ops-rule-params'; import { validateDuration } from '../../../validation'; import { notifyWhenSchema, @@ -23,7 +24,7 @@ export const createRuleDataSchema = schema.object( consumer: schema.string(), tags: schema.arrayOf(schema.string(), { defaultValue: [] }), throttle: schema.maybe(schema.nullable(schema.string({ validate: validateDuration }))), - params: schema.recordOf(schema.string(), schema.maybe(schema.any()), { defaultValue: {} }), + params: ruleParamsSchemaWithDefaultValue, schedule: schema.object({ interval: schema.string({ validate: validateDuration }), }), diff --git a/x-pack/plugins/alerting/server/application/rule/methods/update/schemas/update_rule_data_schema.ts b/x-pack/plugins/alerting/server/application/rule/methods/update/schemas/update_rule_data_schema.ts index 0c4a1df45d44e..9c0bf1666f846 100644 --- a/x-pack/plugins/alerting/server/application/rule/methods/update/schemas/update_rule_data_schema.ts +++ b/x-pack/plugins/alerting/server/application/rule/methods/update/schemas/update_rule_data_schema.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchemaWithDefaultValue } from '@kbn/response-ops-rule-params'; import { validateDuration } from '../../../validation'; import { notifyWhenSchema, @@ -23,7 +24,7 @@ export const updateRuleDataSchema = schema.object( interval: schema.string({ validate: validateDuration }), }), throttle: schema.maybe(schema.nullable(schema.string({ validate: validateDuration }))), - params: schema.recordOf(schema.string(), schema.maybe(schema.any()), { defaultValue: {} }), + params: ruleParamsSchemaWithDefaultValue, actions: schema.arrayOf(actionRequestSchema, { defaultValue: [] }), systemActions: schema.maybe(schema.arrayOf(systemActionRequestSchema, { defaultValue: [] })), notifyWhen: schema.maybe(schema.nullable(notifyWhenSchema)), diff --git a/x-pack/plugins/alerting/server/application/rule/schemas/rule_schemas.ts b/x-pack/plugins/alerting/server/application/rule/schemas/rule_schemas.ts index 7f9fcb1bd5377..da91ceb727d2c 100644 --- a/x-pack/plugins/alerting/server/application/rule/schemas/rule_schemas.ts +++ b/x-pack/plugins/alerting/server/application/rule/schemas/rule_schemas.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ruleParamsSchema } from '@kbn/response-ops-rule-params'; import { ruleLastRunOutcomeValues, ruleExecutionStatusValues, @@ -18,7 +19,6 @@ import { notifyWhenSchema } from './notify_when_schema'; import { actionSchema, systemActionSchema } from './action_schemas'; import { flappingSchema } from './flapping_schema'; -export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any())); export const mappedParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any())); export const intervalScheduleSchema = schema.object({ diff --git a/x-pack/plugins/alerting/server/application/rule/types/rule.ts b/x-pack/plugins/alerting/server/application/rule/types/rule.ts index 0b1177d31e1f7..2e5cad45cf92f 100644 --- a/x-pack/plugins/alerting/server/application/rule/types/rule.ts +++ b/x-pack/plugins/alerting/server/application/rule/types/rule.ts @@ -6,6 +6,7 @@ */ import { TypeOf } from '@kbn/config-schema'; +import { ruleParamsSchema } from '@kbn/response-ops-rule-params'; import { ruleNotifyWhen, ruleLastRunOutcomeValues, @@ -14,7 +15,6 @@ import { ruleExecutionStatusWarningReason, } from '../constants'; import { - ruleParamsSchema, snoozeScheduleSchema, ruleExecutionStatusSchema, ruleLastRunSchema, diff --git a/x-pack/plugins/alerting/tsconfig.json b/x-pack/plugins/alerting/tsconfig.json index c0951663a8489..eefc1999b26d5 100644 --- a/x-pack/plugins/alerting/tsconfig.json +++ b/x-pack/plugins/alerting/tsconfig.json @@ -73,7 +73,8 @@ "@kbn/core-security-server", "@kbn/core-http-server", "@kbn/zod", - "@kbn/core-saved-objects-base-server-internal" + "@kbn/core-saved-objects-base-server-internal", + "@kbn/response-ops-rule-params" ], "exclude": [ "target/**/*" diff --git a/yarn.lock b/yarn.lock index 6139daa0f206c..54e60a9b8543d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6191,6 +6191,10 @@ version "0.0.0" uid "" +"@kbn/response-ops-rule-params@link:packages/response-ops/rule_params": + version "0.0.0" + uid "" + "@kbn/response-stream-plugin@link:examples/response_stream": version "0.0.0" uid "" From e291c9c704910baeff58db07e70c682b65b62587 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:25:31 +1100 Subject: [PATCH 19/33] [8.x] [Authz] Superuser privileges (#196586) (#197369) # Backport This will backport the following commits from `main` to `8.x`: - [[Authz] Superuser privileges (#196586)](https://github.com/elastic/kibana/pull/196586) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Elena Shostak <165678770+elena-shostak@users.noreply.github.com> --- .../security_route_config_validator.test.ts | 28 ++++ .../src/security_route_config_validator.ts | 10 ++ packages/core/http/core-http-server/index.ts | 1 + .../http/core-http-server/src/router/index.ts | 2 +- .../http/core-http-server/src/router/route.ts | 8 + src/core/server/index.ts | 6 +- .../server/routes/key_rotation.test.ts | 11 +- .../server/routes/key_rotation.ts | 8 +- x-pack/plugins/security/common/constants.ts | 11 ++ .../authorization/api_authorization.test.ts | 156 +++++++++++++----- .../server/authorization/api_authorization.ts | 66 ++++++-- 11 files changed, 244 insertions(+), 63 deletions(-) diff --git a/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.test.ts b/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.test.ts index d130bfdce9fb5..f10d2cb3b3ac4 100644 --- a/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.test.ts +++ b/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.test.ts @@ -8,6 +8,7 @@ */ import { validRouteSecurity } from './security_route_config_validator'; +import { ReservedPrivilegesSet } from '@kbn/core-http-server'; describe('RouteSecurity validation', () => { it('should pass validation for valid route security with authz enabled and valid required privileges', () => { @@ -276,4 +277,31 @@ describe('RouteSecurity validation', () => { `"[authz.requiredPrivileges]: anyRequired privileges must contain unique values"` ); }); + + it('should fail validation when anyRequired has superuser privileges set', () => { + const invalidRouteSecurity = { + authz: { + requiredPrivileges: [ + { anyRequired: ['privilege1', 'privilege1'], allRequired: ['privilege4'] }, + { anyRequired: ['privilege5', ReservedPrivilegesSet.superuser] }, + ], + }, + }; + + expect(() => validRouteSecurity(invalidRouteSecurity)).toThrowErrorMatchingInlineSnapshot( + `"[authz.requiredPrivileges]: Combining superuser with other privileges is redundant, superuser privileges set can be only used as a standalone privilege."` + ); + }); + + it('should fail validation when allRequired combines superuser privileges set with other privileges', () => { + const invalidRouteSecurity = { + authz: { + requiredPrivileges: [ReservedPrivilegesSet.superuser, 'privilege1'], + }, + }; + + expect(() => validRouteSecurity(invalidRouteSecurity)).toThrowErrorMatchingInlineSnapshot( + `"[authz.requiredPrivileges]: Combining superuser with other privileges is redundant, superuser privileges set can be only used as a standalone privilege."` + ); + }); }); diff --git a/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.ts b/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.ts index d74f41d3157b4..65073f9a66ec6 100644 --- a/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.ts +++ b/packages/core/http/core-http-router-server-internal/src/security_route_config_validator.ts @@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema'; import type { RouteSecurity, RouteConfigOptions } from '@kbn/core-http-server'; +import { ReservedPrivilegesSet } from '@kbn/core-http-server'; import type { DeepPartial } from '@kbn/utility-types'; const privilegeSetSchema = schema.object( @@ -49,6 +50,15 @@ const requiredPrivilegesSchema = schema.arrayOf( } }); + // Combining superuser with other privileges is redundant. + // If user is a superuser, they inherently have access to all the privileges that may come with other roles. + if ( + anyRequired.includes(ReservedPrivilegesSet.superuser) || + (allRequired.includes(ReservedPrivilegesSet.superuser) && allRequired.length > 1) + ) { + return 'Combining superuser with other privileges is redundant, superuser privileges set can be only used as a standalone privilege.'; + } + if (anyRequired.length && allRequired.length) { for (const privilege of anyRequired) { if (allRequired.includes(privilege)) { diff --git a/packages/core/http/core-http-server/index.ts b/packages/core/http/core-http-server/index.ts index 4ba653fbd534c..f7cae6e02165e 100644 --- a/packages/core/http/core-http-server/index.ts +++ b/packages/core/http/core-http-server/index.ts @@ -127,6 +127,7 @@ export { getResponseValidation, isFullValidatorContainer, isKibanaResponse, + ReservedPrivilegesSet, } from './src/router'; export type { ICspConfig } from './src/csp'; diff --git a/packages/core/http/core-http-server/src/router/index.ts b/packages/core/http/core-http-server/src/router/index.ts index c26212fa0de81..7e4be0507ae1a 100644 --- a/packages/core/http/core-http-server/src/router/index.ts +++ b/packages/core/http/core-http-server/src/router/index.ts @@ -66,7 +66,7 @@ export type { PrivilegeSet, } from './route'; -export { validBodyOutput } from './route'; +export { validBodyOutput, ReservedPrivilegesSet } from './route'; export type { RouteValidationFunction, RouteValidationResultFactory, diff --git a/packages/core/http/core-http-server/src/router/route.ts b/packages/core/http/core-http-server/src/router/route.ts index a97ff9dd4040b..f7bde57ff6c51 100644 --- a/packages/core/http/core-http-server/src/router/route.ts +++ b/packages/core/http/core-http-server/src/router/route.ts @@ -187,6 +187,14 @@ export interface RouteSecurity { authc?: RouteAuthc; } +/** + * A set of reserved privileges that can be used to check access to the route. + */ +export enum ReservedPrivilegesSet { + operator = 'operator', + superuser = 'superuser', +} + /** * Additional route options. * @public diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 1ac38b1d44157..52149cd611be3 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -242,7 +242,11 @@ export type { } from '@kbn/core-http-server'; export type { IExternalUrlPolicy } from '@kbn/core-http-common'; -export { validBodyOutput, OnPostAuthResultType } from '@kbn/core-http-server'; +export { + validBodyOutput, + OnPostAuthResultType, + ReservedPrivilegesSet, +} from '@kbn/core-http-server'; export type { HttpResourcesRenderOptions, diff --git a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts index f387e94e80990..b0bdc9b98a86d 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.test.ts @@ -7,7 +7,7 @@ import { Type } from '@kbn/config-schema'; import type { IRouter, RequestHandler, RequestHandlerContext, RouteConfig } from '@kbn/core/server'; -import { kibanaResponseFactory } from '@kbn/core/server'; +import { kibanaResponseFactory, ReservedPrivilegesSet } from '@kbn/core/server'; import { httpServerMock } from '@kbn/core/server/mocks'; import { routeDefinitionParamsMock } from './index.mock'; @@ -43,9 +43,14 @@ describe('Key rotation routes', () => { }); it('correctly defines route.', () => { + expect(routeConfig.security).toEqual({ + authz: { + requiredPrivileges: [ReservedPrivilegesSet.superuser], + }, + }); expect(routeConfig.options).toEqual({ access: 'public', - tags: ['access:rotateEncryptionKey', 'oas-tag:saved objects'], + tags: ['oas-tag:saved objects'], summary: `Rotate a key for encrypted saved objects`, description: `If a saved object cannot be decrypted using the primary encryption key, Kibana attempts to decrypt it using the specified decryption-only keys. In most of the cases this overhead is negligible, but if you're dealing with a large number of saved objects and experiencing performance issues, you may want to rotate the encryption key. NOTE: Bulk key rotation can consume a considerable amount of resources and hence only user with a superuser role can trigger it.`, @@ -96,7 +101,7 @@ describe('Key rotation routes', () => { expect(config.options).toEqual({ access: 'internal', - tags: ['access:rotateEncryptionKey', 'oas-tag:saved objects'], + tags: ['oas-tag:saved objects'], summary: `Rotate a key for encrypted saved objects`, description: `If a saved object cannot be decrypted using the primary encryption key, Kibana attempts to decrypt it using the specified decryption-only keys. In most of the cases this overhead is negligible, but if you're dealing with a large number of saved objects and experiencing performance issues, you may want to rotate the encryption key. NOTE: Bulk key rotation can consume a considerable amount of resources and hence only user with a superuser role can trigger it.`, diff --git a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts index 272e74c3a69cb..46df83a187c3b 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/routes/key_rotation.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { ReservedPrivilegesSet } from '@kbn/core/server'; import type { RouteDefinitionParams } from '.'; @@ -39,9 +40,14 @@ export function defineKeyRotationRoutes({ type: schema.maybe(schema.string()), }), }, + security: { + authz: { + requiredPrivileges: [ReservedPrivilegesSet.superuser], + }, + }, options: { - tags: ['access:rotateEncryptionKey', 'oas-tag:saved objects'], access: buildFlavor === 'serverless' ? 'internal' : 'public', + tags: ['oas-tag:saved objects'], summary: `Rotate a key for encrypted saved objects`, description: `If a saved object cannot be decrypted using the primary encryption key, Kibana attempts to decrypt it using the specified decryption-only keys. In most of the cases this overhead is negligible, but if you're dealing with a large number of saved objects and experiencing performance issues, you may want to rotate the encryption key. NOTE: Bulk key rotation can consume a considerable amount of resources and hence only user with a superuser role can trigger it.`, diff --git a/x-pack/plugins/security/common/constants.ts b/x-pack/plugins/security/common/constants.ts index 3a9b20bbb0bd7..c75ab77a7de98 100644 --- a/x-pack/plugins/security/common/constants.ts +++ b/x-pack/plugins/security/common/constants.ts @@ -127,3 +127,14 @@ export const API_VERSIONS = { }, }, }; + +/** + * Privileges that define the superuser role or the role equivalent to the superuser role. + */ +export const SUPERUSER_PRIVILEGES = { + kibana: ['*'], + elasticsearch: { + cluster: ['all'], + index: { '*': ['all'] }, + }, +}; diff --git a/x-pack/plugins/security/server/authorization/api_authorization.test.ts b/x-pack/plugins/security/server/authorization/api_authorization.test.ts index e928d73220274..0181c98d6f1b1 100644 --- a/x-pack/plugins/security/server/authorization/api_authorization.test.ts +++ b/x-pack/plugins/security/server/authorization/api_authorization.test.ts @@ -6,6 +6,7 @@ */ import type { RouteSecurity } from '@kbn/core/server'; +import { ReservedPrivilegesSet } from '@kbn/core/server'; import { coreMock, httpServerMock, @@ -149,7 +150,10 @@ describe('initAPIAuthorization', () => { asserts, }: { security?: RouteSecurity; - kibanaPrivilegesResponse?: Array<{ privilege: string; authorized: boolean }>; + kibanaPrivilegesResponse?: { + privileges: { kibana: Array<{ privilege: string; authorized: boolean }> }; + hasAllRequested?: boolean; + }; kibanaPrivilegesRequestActions?: string[]; asserts: { forbidden?: boolean; @@ -180,11 +184,7 @@ describe('initAPIAuthorization', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockPostAuthToolkit = httpServiceMock.createOnPostAuthToolkit(); - const mockCheckPrivileges = jest.fn().mockReturnValue({ - privileges: { - kibana: kibanaPrivilegesResponse, - }, - }); + const mockCheckPrivileges = jest.fn().mockReturnValue(kibanaPrivilegesResponse); mockAuthz.mode.useRbacForRequest.mockReturnValue(true); mockAuthz.checkPrivilegesDynamicallyWithRequest.mockImplementation((request) => { // hapi conceals the actual "request" from us, so we make sure that the headers are passed to @@ -194,6 +194,12 @@ describe('initAPIAuthorization', () => { return mockCheckPrivileges; }); + mockAuthz.checkPrivilegesWithRequest.mockImplementation((request) => { + expect(request.headers).toMatchObject(headers); + + return { globally: () => kibanaPrivilegesResponse }; + }); + await postAuthHandler(mockRequest, mockResponse, mockPostAuthToolkit); expect(mockAuthz.mode.useRbacForRequest).toHaveBeenCalledWith(mockRequest); @@ -207,11 +213,13 @@ describe('initAPIAuthorization', () => { return; } - expect(mockCheckPrivileges).toHaveBeenCalledWith({ - kibana: kibanaPrivilegesRequestActions!.map((action: string) => - mockAuthz.actions.api.get(action) - ), - }); + if (kibanaPrivilegesRequestActions) { + expect(mockCheckPrivileges).toHaveBeenCalledWith({ + kibana: kibanaPrivilegesRequestActions!.map((action: string) => + mockAuthz.actions.api.get(action) + ), + }); + } if (asserts.forbidden) { expect(mockResponse.forbidden).toHaveBeenCalled(); @@ -239,11 +247,15 @@ describe('initAPIAuthorization', () => { ], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: true }, - { privilege: 'api:privilege2', authorized: true }, - { privilege: 'api:privilege3', authorized: false }, - ], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: true }, + { privilege: 'api:privilege2', authorized: true }, + { privilege: 'api:privilege3', authorized: false }, + ], + }, + }, kibanaPrivilegesRequestActions: ['privilege1', 'privilege2', 'privilege3'], asserts: { authzResult: { @@ -267,10 +279,14 @@ describe('initAPIAuthorization', () => { ], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: true }, - { privilege: 'api:privilege2', authorized: true }, - ], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: true }, + { privilege: 'api:privilege2', authorized: true }, + ], + }, + }, kibanaPrivilegesRequestActions: ['privilege1', 'privilege2'], asserts: { authzResult: { @@ -293,11 +309,15 @@ describe('initAPIAuthorization', () => { ], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: false }, - { privilege: 'api:privilege2', authorized: true }, - { privilege: 'api:privilege3', authorized: false }, - ], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: false }, + { privilege: 'api:privilege2', authorized: true }, + { privilege: 'api:privilege3', authorized: false }, + ], + }, + }, kibanaPrivilegesRequestActions: ['privilege1', 'privilege2', 'privilege3'], asserts: { authzResult: { @@ -317,10 +337,14 @@ describe('initAPIAuthorization', () => { requiredPrivileges: ['privilege1', 'privilege2'], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: true }, - { privilege: 'api:privilege2', authorized: true }, - ], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: true }, + { privilege: 'api:privilege2', authorized: true }, + ], + }, + }, kibanaPrivilegesRequestActions: ['privilege1', 'privilege2'], asserts: { authzResult: { @@ -344,18 +368,54 @@ describe('initAPIAuthorization', () => { ], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: true }, - { privilege: 'api:privilege2', authorized: false }, - { privilege: 'api:privilege3', authorized: false }, - ], kibanaPrivilegesRequestActions: ['privilege1', 'privilege2', 'privilege3'], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: true }, + { privilege: 'api:privilege2', authorized: false }, + { privilege: 'api:privilege3', authorized: false }, + ], + }, + }, asserts: { forbidden: true, }, } ); + testSecurityConfig( + `protected route restricted to only superusers returns forbidden if user not a superuser`, + { + security: { + authz: { + requiredPrivileges: [ReservedPrivilegesSet.superuser], + }, + }, + kibanaPrivilegesResponse: { privileges: { kibana: [] }, hasAllRequested: false }, + asserts: { + forbidden: true, + }, + } + ); + + testSecurityConfig( + `protected route allowed only for superuser access returns "authzResult" if user is superuser`, + { + security: { + authz: { + requiredPrivileges: [ReservedPrivilegesSet.superuser], + }, + }, + kibanaPrivilegesResponse: { privileges: { kibana: [] }, hasAllRequested: true }, + asserts: { + authzResult: { + [ReservedPrivilegesSet.superuser]: true, + }, + }, + } + ); + testSecurityConfig( `protected route returns forbidden if user doesn't have at least one from allRequired privileges requested`, { @@ -369,12 +429,16 @@ describe('initAPIAuthorization', () => { ], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: true }, - { privilege: 'api:privilege2', authorized: false }, - { privilege: 'api:privilege3', authorized: false }, - { privilege: 'api:privilege4', authorized: true }, - ], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: true }, + { privilege: 'api:privilege2', authorized: false }, + { privilege: 'api:privilege3', authorized: false }, + { privilege: 'api:privilege4', authorized: true }, + ], + }, + }, kibanaPrivilegesRequestActions: ['privilege1', 'privilege2', 'privilege3', 'privilege4'], asserts: { forbidden: true, @@ -390,10 +454,14 @@ describe('initAPIAuthorization', () => { requiredPrivileges: ['privilege1', 'privilege2'], }, }, - kibanaPrivilegesResponse: [ - { privilege: 'api:privilege1', authorized: true }, - { privilege: 'api:privilege2', authorized: false }, - ], + kibanaPrivilegesResponse: { + privileges: { + kibana: [ + { privilege: 'api:privilege1', authorized: true }, + { privilege: 'api:privilege2', authorized: false }, + ], + }, + }, kibanaPrivilegesRequestActions: ['privilege1', 'privilege2'], asserts: { forbidden: true, diff --git a/x-pack/plugins/security/server/authorization/api_authorization.ts b/x-pack/plugins/security/server/authorization/api_authorization.ts index 9c67ff8bdff8b..2b99c2a176ac1 100644 --- a/x-pack/plugins/security/server/authorization/api_authorization.ts +++ b/x-pack/plugins/security/server/authorization/api_authorization.ts @@ -14,18 +14,28 @@ import type { PrivilegeSet, RouteAuthz, } from '@kbn/core/server'; +import { ReservedPrivilegesSet } from '@kbn/core/server'; import type { AuthorizationServiceSetup } from '@kbn/security-plugin-types-server'; import type { RecursiveReadonly } from '@kbn/utility-types'; -import { API_OPERATION_PREFIX } from '../../common/constants'; +import { API_OPERATION_PREFIX, SUPERUSER_PRIVILEGES } from '../../common/constants'; const isAuthzDisabled = (authz?: RecursiveReadonly): authz is AuthzDisabled => { return (authz as AuthzDisabled)?.enabled === false; }; +const isReservedPrivilegeSet = (privilege: string): privilege is ReservedPrivilegesSet => { + return Object.hasOwn(ReservedPrivilegesSet, privilege); +}; + export function initAPIAuthorization( http: HttpServiceSetup, - { actions, checkPrivilegesDynamicallyWithRequest, mode }: AuthorizationServiceSetup, + { + actions, + checkPrivilegesDynamicallyWithRequest, + checkPrivilegesWithRequest, + mode, + }: AuthorizationServiceSetup, logger: Logger ) { http.registerOnPostAuth(async (request, response, toolkit) => { @@ -47,24 +57,54 @@ export function initAPIAuthorization( const authz = security.authz as AuthzEnabled; - const requestedPrivileges = authz.requiredPrivileges.flatMap((privilegeEntry) => { - if (typeof privilegeEntry === 'object') { - return [...(privilegeEntry.allRequired ?? []), ...(privilegeEntry.anyRequired ?? [])]; + const { requestedPrivileges, requestedReservedPrivileges } = authz.requiredPrivileges.reduce( + (acc, privilegeEntry) => { + const privileges = + typeof privilegeEntry === 'object' + ? [...(privilegeEntry.allRequired ?? []), ...(privilegeEntry.anyRequired ?? [])] + : [privilegeEntry]; + + for (const privilege of privileges) { + if (isReservedPrivilegeSet(privilege)) { + acc.requestedReservedPrivileges.push(privilege); + } else { + acc.requestedPrivileges.push(privilege); + } + } + + return acc; + }, + { + requestedPrivileges: [] as string[], + requestedReservedPrivileges: [] as string[], } + ); - return privilegeEntry; - }); - - const apiActions = requestedPrivileges.map((permission) => actions.api.get(permission)); const checkPrivileges = checkPrivilegesDynamicallyWithRequest(request); - const checkPrivilegesResponse = await checkPrivileges({ kibana: apiActions }); - const privilegeToApiOperation = (privilege: string) => privilege.replace(API_OPERATION_PREFIX, ''); + const kibanaPrivileges: Record = {}; - for (const kbPrivilege of checkPrivilegesResponse.privileges.kibana) { - kibanaPrivileges[privilegeToApiOperation(kbPrivilege.privilege)] = kbPrivilege.authorized; + if (requestedPrivileges.length > 0) { + const checkPrivilegesResponse = await checkPrivileges({ + kibana: requestedPrivileges.map((permission) => actions.api.get(permission)), + }); + + for (const kbPrivilege of checkPrivilegesResponse.privileges.kibana) { + kibanaPrivileges[privilegeToApiOperation(kbPrivilege.privilege)] = kbPrivilege.authorized; + } + } + + for (const reservedPrivilege of requestedReservedPrivileges) { + if (reservedPrivilege === ReservedPrivilegesSet.superuser) { + const checkSuperuserPrivilegesResponse = await checkPrivilegesWithRequest( + request + ).globally(SUPERUSER_PRIVILEGES); + + kibanaPrivileges[ReservedPrivilegesSet.superuser] = + checkSuperuserPrivilegesResponse.hasAllRequested; + } } const hasRequestedPrivilege = (kbPrivilege: Privilege | PrivilegeSet) => { From b663248f8a2138e1c2d0a96c03f134f8433bf06a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:31:37 +1100 Subject: [PATCH 20/33] [8.x] [ML] API tests for ML's _has_privileges (#197274) (#197372) # Backport This will backport the following commits from `main` to `8.x`: - [[ML] API tests for ML's _has_privileges (#197274)](https://github.com/elastic/kibana/pull/197274) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: James Gowdy --- .../apis/ml/system/has_privileges.ts | 143 ++++++++++++++++++ .../api_integration/apis/ml/system/index.ts | 1 + x-pack/test/functional/services/ml/api.ts | 28 ++++ 3 files changed, 172 insertions(+) create mode 100644 x-pack/test/api_integration/apis/ml/system/has_privileges.ts diff --git a/x-pack/test/api_integration/apis/ml/system/has_privileges.ts b/x-pack/test/api_integration/apis/ml/system/has_privileges.ts new file mode 100644 index 0000000000000..2e705240b403e --- /dev/null +++ b/x-pack/test/api_integration/apis/ml/system/has_privileges.ts @@ -0,0 +1,143 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; + +import { MlHasPrivilegesResponse } from '@kbn/ml-plugin/public/application/services/ml_api_service'; +import { FtrProviderContext } from '../../../ftr_provider_context'; +import { getCommonRequestHeader } from '../../../../functional/services/ml/common_api'; +import { USER } from '../../../../functional/services/ml/security_common'; + +export default ({ getService }: FtrProviderContext) => { + const esArchiver = getService('esArchiver'); + const supertest = getService('supertestWithoutAuth'); + const ml = getService('ml'); + + async function runRequest( + user: USER, + index: any, + expectedStatusCode = 200 + ): Promise { + const { body, status } = await supertest + .post(`/internal/ml/_has_privileges`) + .auth(user, ml.securityCommon.getPasswordForUser(user)) + .set(getCommonRequestHeader('1')) + .send({ index }); + ml.api.assertResponseStatusCode(expectedStatusCode, status, body); + + return body; + } + + const testData = [ + { + user: USER.ML_POWERUSER, + index: [ + { + names: ['ft_farequote_small'], + privileges: ['read'], + }, + { + names: ['ft_farequote_small'], + privileges: ['write'], + }, + ], + expectedResponse: { + hasPrivileges: { + username: 'ft_ml_poweruser', + has_all_requested: false, + cluster: {}, + index: { + ft_farequote_small: { + read: true, + write: false, + }, + }, + application: {}, + }, + upgradeInProgress: false, + }, + expectedStatusCode: 200, + }, + { + user: USER.ML_VIEWER, + index: [ + { + names: ['ft_farequote_small'], + privileges: ['read'], + }, + { + names: ['ft_farequote_small'], + privileges: ['write'], + }, + ], + expectedResponse: { + hasPrivileges: { + username: 'ft_ml_viewer', + has_all_requested: false, + cluster: {}, + index: { + ft_farequote_small: { + read: true, + write: false, + }, + }, + application: {}, + }, + upgradeInProgress: false, + }, + + expectedStatusCode: 200, + }, + { + user: USER.ML_UNAUTHORIZED, + index: [ + { + names: ['ft_farequote_small'], + privileges: ['read'], + }, + { + names: ['ft_farequote_small'], + privileges: ['write'], + }, + ], + expectedResponse: { statusCode: 403, error: 'Forbidden', message: 'Forbidden' }, + expectedStatusCode: 403, + }, + ]; + + describe("ML's _has_privileges", () => { + before(async () => { + await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote_small'); + }); + after(async () => { + await ml.api.setUpgradeMode(false); + }); + + it('should return correct privileges for test data', async () => { + for (const { user, index, expectedResponse, expectedStatusCode } of testData) { + const response = await runRequest(user, index, expectedStatusCode); + expect(response).to.eql( + expectedResponse, + `expected ${JSON.stringify(expectedResponse)}, got ${JSON.stringify(response)}` + ); + } + }); + + it('should return correct upgrade in progress', async () => { + const index = testData[0].index; + const expectedResponse = { ...testData[0].expectedResponse, upgradeInProgress: true }; + await ml.api.setUpgradeMode(true); + await ml.api.assertUpgradeMode(true); + + const response = await runRequest(USER.ML_POWERUSER, index); + expect(response).to.eql( + expectedResponse, + `expected ${JSON.stringify(expectedResponse)}, got ${JSON.stringify(response)}` + ); + }); + }); +}; diff --git a/x-pack/test/api_integration/apis/ml/system/index.ts b/x-pack/test/api_integration/apis/ml/system/index.ts index 0ddd4b80a0ee5..42e02b5fbb808 100644 --- a/x-pack/test/api_integration/apis/ml/system/index.ts +++ b/x-pack/test/api_integration/apis/ml/system/index.ts @@ -14,5 +14,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./index_exists')); loadTestFile(require.resolve('./info')); loadTestFile(require.resolve('./node_count')); + loadTestFile(require.resolve('./has_privileges')); }); } diff --git a/x-pack/test/functional/services/ml/api.ts b/x-pack/test/functional/services/ml/api.ts index 8b2c46d474c0c..0a3d988fd750c 100644 --- a/x-pack/test/functional/services/ml/api.ts +++ b/x-pack/test/functional/services/ml/api.ts @@ -1696,5 +1696,33 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) { this.assertResponseStatusCode(200, status, module); return module; }, + + async setUpgradeMode(enabled: boolean) { + log.debug(`Setting upgrade mode to "${enabled}"`); + const { body, status } = await esSupertest.post(`/_ml/set_upgrade_mode?enabled=${enabled}`); + this.assertResponseStatusCode(200, status, body); + + log.debug(`Upgrade mode set to "${enabled}"`); + }, + + async assertUpgradeMode(expectedMode: boolean) { + log.debug(`Asserting upgrade mode is "${expectedMode}"`); + const { body, status } = await esSupertest.get('/_ml/info'); + this.assertResponseStatusCode(200, status, body); + + expect(body.upgrade_mode).to.eql( + expectedMode, + `Expected upgrade mode to be ${expectedMode}, got ${body.upgrade_mode}` + ); + }, + + async getMlInfo() { + log.debug(`Getting ML info`); + const { body, status } = await kbnSupertest + .get(`/internal/ml/info`) + .set(getCommonRequestHeader('1')); + this.assertResponseStatusCode(200, status, body); + return body; + }, }; } From dc1eb11071d3852bc8db4663528b2907c4eb0d39 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:48:39 +1100 Subject: [PATCH 21/33] [8.x] [SecuritySolution] Update entity store source field (#197186) (#197376) # Backport This will backport the following commits from `main` to `8.x`: - [[SecuritySolution] Update entity store source field (#197186)](https://github.com/elastic/kibana/pull/197186) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Pablo Machado --- .../output/kibana.serverless.staging.yaml | 8 +- oas_docs/output/kibana.serverless.yaml | 8 +- oas_docs/output/kibana.staging.yaml | 8 +- oas_docs/output/kibana.yaml | 8 +- .../entity_store/entities/common.gen.ts | 4 +- .../entity_store/entities/common.schema.yaml | 12 +-- ...alytics_api_2023_10_31.bundled.schema.yaml | 8 +- ...alytics_api_2023_10_31.bundled.schema.yaml | 8 +- .../components/entity_source_filter.tsx | 16 ++-- .../entity_store/entities_list.test.tsx | 2 +- .../components/entity_store/entities_list.tsx | 6 +- .../components/entity_store/helpers.test.ts | 86 +++++++++++++------ .../components/entity_store/helpers.tsx | 46 ++++++++++ .../hooks/use_entities_list_columns.tsx | 6 +- .../hooks/use_entities_list_filters.test.ts | 55 +++++++++--- .../hooks/use_entities_list_filters.ts | 60 ++++++++++--- .../entity_store/{helpers.ts => types.ts} | 12 ++- .../entity_types/common.ts | 5 +- .../get_united_definition.test.ts | 18 ++-- 19 files changed, 248 insertions(+), 128 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.tsx rename x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/{helpers.ts => types.ts} (52%) diff --git a/oas_docs/output/kibana.serverless.staging.yaml b/oas_docs/output/kibana.serverless.staging.yaml index 7423338ee66aa..ecfc211c98e1e 100644 --- a/oas_docs/output/kibana.serverless.staging.yaml +++ b/oas_docs/output/kibana.serverless.staging.yaml @@ -30472,9 +30472,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source @@ -30626,9 +30624,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source diff --git a/oas_docs/output/kibana.serverless.yaml b/oas_docs/output/kibana.serverless.yaml index 7423338ee66aa..ecfc211c98e1e 100644 --- a/oas_docs/output/kibana.serverless.yaml +++ b/oas_docs/output/kibana.serverless.yaml @@ -30472,9 +30472,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source @@ -30626,9 +30624,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source diff --git a/oas_docs/output/kibana.staging.yaml b/oas_docs/output/kibana.staging.yaml index f7c5e34257336..508148435fbea 100644 --- a/oas_docs/output/kibana.staging.yaml +++ b/oas_docs/output/kibana.staging.yaml @@ -39302,9 +39302,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source @@ -39456,9 +39454,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml index f7c5e34257336..508148435fbea 100644 --- a/oas_docs/output/kibana.yaml +++ b/oas_docs/output/kibana.yaml @@ -39302,9 +39302,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source @@ -39456,9 +39454,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.gen.ts b/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.gen.ts index 7359d36c9cbfa..77607a6ceb863 100644 --- a/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.gen.ts +++ b/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.gen.ts @@ -24,7 +24,7 @@ export const UserEntity = z.object({ '@timestamp': z.string().datetime(), entity: z.object({ name: z.string(), - source: z.array(z.string()), + source: z.string(), }), user: z.object({ full_name: z.array(z.string()).optional(), @@ -48,7 +48,7 @@ export const HostEntity = z.object({ '@timestamp': z.string().datetime(), entity: z.object({ name: z.string(), - source: z.array(z.string()), + source: z.string(), }), host: z.object({ hostname: z.array(z.string()).optional(), diff --git a/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.schema.yaml b/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.schema.yaml index 35314dfed9f54..045a04ff4867a 100644 --- a/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.schema.yaml +++ b/x-pack/plugins/security_solution/common/api/entity_analytics/entity_store/entities/common.schema.yaml @@ -22,12 +22,10 @@ components: - name - source properties: - name: + name: type: string source: - type: array - items: - type: string + type: string user: type: object properties: @@ -84,12 +82,10 @@ components: - name - source properties: - name: + name: type: string source: - type: array - items: - type: string + type: string host: type: object properties: diff --git a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml index c758cd5484d22..1c7be495492c6 100644 --- a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml @@ -910,9 +910,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source @@ -1062,9 +1060,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source diff --git a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml index 6f1ad9a51a158..9d736030856d9 100644 --- a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml @@ -910,9 +910,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source @@ -1062,9 +1060,7 @@ components: name: type: string source: - items: - type: string - type: array + type: string required: - name - source diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/entity_source_filter.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/entity_source_filter.tsx index aac8aad170f3f..bc295b6cde439 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/entity_source_filter.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/components/entity_source_filter.tsx @@ -8,30 +8,26 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { MultiselectFilter } from '../../../../common/components/multiselect_filter'; +import { EntitySourceTag } from '../types'; interface SourceFilterProps { - selectedItems: EntitySource[]; - onChange: (selectedItems: EntitySource[]) => void; + selectedItems: EntitySourceTag[]; + onChange: (selectedItems: EntitySourceTag[]) => void; } -export enum EntitySource { - CSV_UPLOAD = 'CSV upload', - EVENTS = 'Events', -} -// TODO Fix the Entity Source field before using it export const EntitySourceFilter: React.FC = ({ selectedItems, onChange }) => { return ( - + title={i18n.translate( 'xpack.securitySolution.entityAnalytics.entityStore.entitySource.filterTitle', { defaultMessage: 'Source', } )} - items={Object.values(EntitySource)} + items={Object.values(EntitySourceTag)} selectedItems={selectedItems} onSelectionChange={onChange} - width={140} + width={190} /> ); }; diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx index b105a87fd8720..68039f94dd0ee 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx @@ -33,7 +33,7 @@ const responseData: ListEntitiesResponse = { user: { name: entityName }, entity: { name: entityName, - source: ['source'], + source: 'test-index', }, }, ], diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx index a6e058af34392..fc821bead61f0 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx @@ -21,12 +21,13 @@ import { EntityType } from '../../../../common/api/entity_analytics/entity_store import type { Criteria } from '../../../explore/components/paginated_table'; import { PaginatedTable } from '../../../explore/components/paginated_table'; import { SeverityFilter } from '../severity/severity_filter'; -import type { EntitySource } from './components/entity_source_filter'; +import { EntitySourceFilter } from './components/entity_source_filter'; import { useEntitiesListFilters } from './hooks/use_entities_list_filters'; import { AssetCriticalityFilter } from '../asset_criticality/asset_criticality_filter'; import { useEntitiesListQuery } from './hooks/use_entities_list_query'; import { ENTITIES_LIST_TABLE_ID, rowItems } from './constants'; import { useEntitiesListColumns } from './hooks/use_entities_list_columns'; +import type { EntitySourceTag } from './types'; export const EntitiesList: React.FC = () => { const { deleteQuery, setQuery, isInitializing, from, to } = useGlobalTime(); @@ -40,7 +41,7 @@ export const EntitiesList: React.FC = () => { const [selectedSeverities, setSelectedSeverities] = useState([]); const [selectedCriticalities, setSelectedCriticalities] = useState([]); - const [selectedSources, _] = useState([]); + const [selectedSources, setSelectedSources] = useState([]); const filter = useEntitiesListFilters({ selectedSeverities, @@ -147,6 +148,7 @@ export const EntitiesList: React.FC = () => { selectedItems={selectedCriticalities} onChange={setSelectedCriticalities} /> + diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.test.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.test.ts index 6e3ba0e6d09d1..55fb85bf9158b 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.test.ts @@ -5,40 +5,70 @@ * 2.0. */ -import { isUserEntity } from './helpers'; +import { isUserEntity, sourceFieldToText } from './helpers'; import type { Entity, UserEntity, } from '../../../../common/api/entity_analytics/entity_store/entities/common.gen'; +import { render } from '@testing-library/react'; +import { TestProviders } from '@kbn/timelines-plugin/public/mock'; -describe('isUserEntity', () => { - it('should return true if the record is a UserEntity', () => { - const userEntity: UserEntity = { - '@timestamp': '2021-08-02T14:00:00.000Z', - user: { - name: 'test_user', - }, - entity: { - name: 'test_user', - source: ['logs-test'], - }, - }; - - expect(isUserEntity(userEntity)).toBe(true); +describe('helpers', () => { + describe('isUserEntity', () => { + it('should return true if the record is a UserEntity', () => { + const userEntity: UserEntity = { + '@timestamp': '2021-08-02T14:00:00.000Z', + user: { + name: 'test_user', + }, + entity: { + name: 'test_user', + source: 'logs-test', + }, + }; + + expect(isUserEntity(userEntity)).toBe(true); + }); + + it('should return false if the record is not a UserEntity', () => { + const nonUserEntity: Entity = { + '@timestamp': '2021-08-02T14:00:00.000Z', + host: { + name: 'test_host', + }, + entity: { + name: 'test_host', + source: 'logs-test', + }, + }; + + expect(isUserEntity(nonUserEntity)).toBe(false); + }); }); - it('should return false if the record is not a UserEntity', () => { - const nonUserEntity: Entity = { - '@timestamp': '2021-08-02T14:00:00.000Z', - host: { - name: 'test_host', - }, - entity: { - name: 'test_host', - source: ['logs-test'], - }, - }; - - expect(isUserEntity(nonUserEntity)).toBe(false); + describe('sourceFieldToText', () => { + it("should return 'Events' if the value isn't risk or asset", () => { + const { container } = render(sourceFieldToText('anything'), { + wrapper: TestProviders, + }); + + expect(container).toHaveTextContent('Events'); + }); + + it("should return 'Risk' if the value is a risk index", () => { + const { container } = render(sourceFieldToText('risk-score.risk-score-default'), { + wrapper: TestProviders, + }); + + expect(container).toHaveTextContent('Risk'); + }); + + it("should return 'Asset Criticality' if the value is a asset criticality index", () => { + const { container } = render(sourceFieldToText('.asset-criticality.asset-criticality-*'), { + wrapper: TestProviders, + }); + + expect(container).toHaveTextContent('Asset Criticality'); + }); }); }); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.tsx new file mode 100644 index 0000000000000..e339a63be7064 --- /dev/null +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.tsx @@ -0,0 +1,46 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import React from 'react'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { + ASSET_CRITICALITY_INDEX_PATTERN, + RISK_SCORE_INDEX_PATTERN, +} from '../../../../common/constants'; +import type { + Entity, + UserEntity, +} from '../../../../common/api/entity_analytics/entity_store/entities/common.gen'; + +export const isUserEntity = (record: Entity): record is UserEntity => + !!(record as UserEntity)?.user; + +export const sourceFieldToText = (source: string) => { + if (source.match(`^${RISK_SCORE_INDEX_PATTERN}`)) { + return ( + + ); + } + + if (source.match(`^${ASSET_CRITICALITY_INDEX_PATTERN}`)) { + return ( + + ); + } + + return ( + + ); +}; diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx index 52439d10a0000..e1af7152a843d 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx @@ -17,9 +17,9 @@ import { RiskScoreLevel } from '../../severity/common'; import { getEmptyTagValue } from '../../../../common/components/empty_value'; import type { Columns } from '../../../../explore/components/paginated_table'; import type { Entity } from '../../../../../common/api/entity_analytics/entity_store/entities/common.gen'; -import type { CriticalityLevels } from '../../../../../common/constants'; +import { type CriticalityLevels } from '../../../../../common/constants'; import { ENTITIES_LIST_TABLE_ID } from '../constants'; -import { isUserEntity } from '../helpers'; +import { isUserEntity, sourceFieldToText } from '../helpers'; import { CRITICALITY_LEVEL_TITLE } from '../../asset_criticality/translations'; export type EntitiesListColumns = [ @@ -110,7 +110,7 @@ export const useEntitiesListColumns = (): EntitiesListColumns => { truncateText: { lines: 2 }, render: (source: string | undefined) => { if (source != null) { - return {source}; + return sourceFieldToText(source); } return getEmptyTagValue(); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.test.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.test.ts index de5f706d4524c..cdf0583374538 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.test.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.test.ts @@ -11,7 +11,7 @@ import { useGlobalFilterQuery } from '../../../../common/hooks/use_global_filter import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; import { CriticalityLevels } from '../../../../../common/constants'; import { RiskSeverity } from '../../../../../common/search_strategy'; -import { EntitySource } from '../components/entity_source_filter'; +import { EntitySourceTag } from '../types'; jest.mock('../../../../common/hooks/use_global_filter_query'); @@ -52,7 +52,6 @@ describe('useEntitiesListFilters', () => { { term: { 'host.risk.calculated_level': RiskSeverity.High } }, { term: { 'user.risk.calculated_level': RiskSeverity.High } }, ], - minimum_should_match: 1, }, }, ]; @@ -72,7 +71,6 @@ describe('useEntitiesListFilters', () => { const expectedFilters: QueryDslQueryContainer[] = [ { bool: { - minimum_should_match: 1, should: [ { term: { @@ -97,13 +95,48 @@ describe('useEntitiesListFilters', () => { useEntitiesListFilters({ selectedSeverities: [], selectedCriticalities: [], - selectedSources: [EntitySource.CSV_UPLOAD, EntitySource.EVENTS], + selectedSources: [EntitySourceTag.criticality, EntitySourceTag.risk], }) ); const expectedFilters: QueryDslQueryContainer[] = [ - { term: { 'entity.source': EntitySource.CSV_UPLOAD } }, - { term: { 'entity.source': EntitySource.EVENTS } }, + { + bool: { + should: [ + { wildcard: { 'entity.source': '.asset-criticality.asset-criticality-*' } }, + { wildcard: { 'entity.source': 'risk-score.risk-score-*' } }, + ], + }, + }, + ]; + + expect(result.current).toEqual(expectedFilters); + }); + + it('should return source events filters when events is selected', () => { + const { result } = renderHook(() => + useEntitiesListFilters({ + selectedSeverities: [], + selectedCriticalities: [], + selectedSources: [EntitySourceTag.events], + }) + ); + + const expectedFilters: QueryDslQueryContainer[] = [ + { + bool: { + should: [ + { + bool: { + must_not: [ + { wildcard: { 'entity.source': '.asset-criticality.asset-criticality-*' } }, + { wildcard: { 'entity.source': 'risk-score.risk-score-*' } }, + ], + }, + }, + ], + }, + }, ]; expect(result.current).toEqual(expectedFilters); @@ -132,7 +165,7 @@ describe('useEntitiesListFilters', () => { useEntitiesListFilters({ selectedSeverities: [RiskSeverity.Low], selectedCriticalities: [CriticalityLevels.HIGH_IMPACT], - selectedSources: [EntitySource.CSV_UPLOAD], + selectedSources: [EntitySourceTag.risk], }) ); @@ -143,16 +176,18 @@ describe('useEntitiesListFilters', () => { { term: { 'host.risk.calculated_level': RiskSeverity.Low } }, { term: { 'user.risk.calculated_level': RiskSeverity.Low } }, ], - minimum_should_match: 1, }, }, { bool: { should: [{ term: { 'asset.criticality': CriticalityLevels.HIGH_IMPACT } }], - minimum_should_match: 1, }, }, - { term: { 'entity.source': EntitySource.CSV_UPLOAD } }, + { + bool: { + should: [{ wildcard: { 'entity.source': 'risk-score.risk-score-*' } }], + }, + }, globalQuery, ]; diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.ts index 634f3f61c1590..ba720025f4a59 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_filters.ts @@ -7,15 +7,19 @@ import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; import { useMemo } from 'react'; -import type { CriticalityLevels } from '../../../../../common/constants'; +import { + ASSET_CRITICALITY_INDEX_PATTERN, + RISK_SCORE_INDEX_PATTERN, + type CriticalityLevels, +} from '../../../../../common/constants'; import type { RiskSeverity } from '../../../../../common/search_strategy'; import { useGlobalFilterQuery } from '../../../../common/hooks/use_global_filter_query'; -import type { EntitySource } from '../components/entity_source_filter'; +import { EntitySourceTag } from '../types'; interface UseEntitiesListFiltersParams { selectedSeverities: RiskSeverity[]; selectedCriticalities: CriticalityLevels[]; - selectedSources: EntitySource[]; + selectedSources: EntitySourceTag[]; } export const useEntitiesListFilters = ({ @@ -35,17 +39,20 @@ export const useEntitiesListFilters = ({ 'asset.criticality': value, }, })), - minimum_should_match: 1, }, }, ] : []; - const sourceFilter: QueryDslQueryContainer[] = selectedSources.map((value) => ({ - term: { - 'entity.source': value, - }, - })); + const sourceFilter: QueryDslQueryContainer[] = selectedSources.length + ? [ + { + bool: { + should: selectedSources.map((tag) => getSourceTagFilterQuery(tag)), + }, + }, + ] + : []; const severityFilter: QueryDslQueryContainer[] = selectedSeverities.length ? [ @@ -63,7 +70,6 @@ export const useEntitiesListFilters = ({ }, }, ]), - minimum_should_match: 1, }, }, ] @@ -80,3 +86,37 @@ export const useEntitiesListFilters = ({ return filterList; }, [globalQuery, selectedCriticalities, selectedSeverities, selectedSources]); }; + +const getSourceTagFilterQuery = (tag: EntitySourceTag): QueryDslQueryContainer => { + if (tag === EntitySourceTag.risk) { + return { + wildcard: { + 'entity.source': RISK_SCORE_INDEX_PATTERN, + }, + }; + } + if (tag === EntitySourceTag.criticality) { + return { + wildcard: { + 'entity.source': ASSET_CRITICALITY_INDEX_PATTERN, + }, + }; + } + + return { + bool: { + must_not: [ + { + wildcard: { + 'entity.source': ASSET_CRITICALITY_INDEX_PATTERN, + }, + }, + { + wildcard: { + 'entity.source': RISK_SCORE_INDEX_PATTERN, + }, + }, + ], + }, + }; +}; diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/types.ts similarity index 52% rename from x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.ts rename to x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/types.ts index 61e9b2be8b0ab..0adabf36eb436 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/helpers.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/types.ts @@ -5,10 +5,8 @@ * 2.0. */ -import type { - Entity, - UserEntity, -} from '../../../../common/api/entity_analytics/entity_store/entities/common.gen'; - -export const isUserEntity = (record: Entity): record is UserEntity => - !!(record as UserEntity)?.user; +export enum EntitySourceTag { + 'risk' = 'Risk', + 'criticality' = 'Asset Criticality', + 'events' = 'Events', +} diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/entity_types/common.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/entity_types/common.ts index 2f0213d5f3820..ac974bf119d4a 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/entity_types/common.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/entity_types/common.ts @@ -7,7 +7,7 @@ import type { EntityType } from '../../../../../../common/api/entity_analytics/entity_store'; import { getIdentityFieldForEntityType } from '../../utils'; -import { collectValues, newestValue } from '../definition_utils'; +import { oldestValue, newestValue } from '../definition_utils'; import type { UnitedDefinitionField } from '../types'; export const getCommonUnitedFieldDefinitions = ({ @@ -19,10 +19,9 @@ export const getCommonUnitedFieldDefinitions = ({ }): UnitedDefinitionField[] => { const identityField = getIdentityFieldForEntityType(entityType); return [ - collectValues({ + oldestValue({ sourceField: '_index', field: 'entity.source', - fieldHistoryLength, }), newestValue({ field: 'asset.criticality' }), newestValue({ diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/get_united_definition.test.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/get_united_definition.test.ts index 2657917d45a78..81a381bc91873 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/get_united_definition.test.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/united_entity_definitions/get_united_definition.test.ts @@ -117,8 +117,7 @@ describe('getUnitedEntityDefinition', () => { }, Object { "field": "entity.source", - "maxLength": 10, - "operation": "collect_values", + "operation": "prefer_oldest_value", }, Object { "field": "asset.criticality", @@ -219,8 +218,10 @@ describe('getUnitedEntityDefinition', () => { }, Object { "aggregation": Object { - "limit": 10, - "type": "terms", + "sort": Object { + "@timestamp": "asc", + }, + "type": "top_value", }, "destination": "entity.source", "source": "_index", @@ -373,8 +374,7 @@ describe('getUnitedEntityDefinition', () => { }, Object { "field": "entity.source", - "maxLength": 10, - "operation": "collect_values", + "operation": "prefer_oldest_value", }, Object { "field": "asset.criticality", @@ -467,8 +467,10 @@ describe('getUnitedEntityDefinition', () => { }, Object { "aggregation": Object { - "limit": 10, - "type": "terms", + "sort": Object { + "@timestamp": "asc", + }, + "type": "top_value", }, "destination": "entity.source", "source": "_index", From cb5cd2dd53b286b6e6aa0cc08b32010389be6bfa Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:59:26 +1100 Subject: [PATCH 22/33] [8.x] [SecuritySolution] Fix EntitiesList 'name' column sorting (#197225) (#197375) # Backport This will backport the following commits from `main` to `8.x`: - [[SecuritySolution] Fix EntitiesList 'name' column sorting (#197225)](https://github.com/elastic/kibana/pull/197225) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Pablo Machado --- .../components/entity_store/entities_list.test.tsx | 2 +- .../components/entity_store/hooks/use_entities_list_columns.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx index 68039f94dd0ee..0e598d6463c5a 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx @@ -106,7 +106,7 @@ describe('EntitiesList', () => { fireEvent.click(columnHeader); expect(mockUseEntitiesListQuery).toHaveBeenCalledWith( expect.objectContaining({ - sortField: 'entity.displayName.keyword', + sortField: 'entity.name.text', sortOrder: 'asc', }) ); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx index e1af7152a843d..974a80454ee21 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx @@ -79,7 +79,7 @@ export const useEntitiesListColumns = (): EntitiesListColumns => { width: '5%', }, { - field: 'entity.displayName.keyword', + field: 'entity.name.text', name: ( Date: Wed, 23 Oct 2024 21:03:55 +1100 Subject: [PATCH 23/33] [8.x] [Observability Onboarding] Fix EDOT collector permissions (#197248) (#197299) # Backport This will backport the following commits from `main` to `8.x`: - [[Observability Onboarding] Fix EDOT collector permissions (#197248)](https://github.com/elastic/kibana/pull/197248) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Thom Heymann <190132+thomheymann@users.noreply.github.com> --- .../server/lib/api_key/create_shipper_api_key.ts | 9 ++++++--- .../server/lib/api_key/has_log_monitoring_privileges.ts | 9 ++++++--- .../server/lib/api_key/privileges.ts | 9 ++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/create_shipper_api_key.ts b/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/create_shipper_api_key.ts index bdfdd202a962e..9279ae0e1dfd1 100644 --- a/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/create_shipper_api_key.ts +++ b/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/create_shipper_api_key.ts @@ -6,7 +6,11 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import { MONITOR_CLUSTER, INDEX_LOGS_AND_METRICS, WRITE_APM_EVENTS } from './privileges'; +import { + MONITOR_CLUSTER, + INDEX_LOGS_AND_METRICS, + INDEX_LOGS_METRICS_AND_TRACES, +} from './privileges'; export function createShipperApiKey(esClient: ElasticsearchClient, name: string, withAPM = false) { // Based on https://www.elastic.co/guide/en/fleet/master/grant-access-to-elasticsearch.html#create-api-key-standalone-agent @@ -20,8 +24,7 @@ export function createShipperApiKey(esClient: ElasticsearchClient, name: string, role_descriptors: { standalone_agent: { cluster: [MONITOR_CLUSTER], - indices: [INDEX_LOGS_AND_METRICS], - applications: withAPM ? [WRITE_APM_EVENTS] : undefined, + indices: [withAPM ? INDEX_LOGS_METRICS_AND_TRACES : INDEX_LOGS_AND_METRICS], }, }, }, diff --git a/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/has_log_monitoring_privileges.ts b/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/has_log_monitoring_privileges.ts index 0593a7f761e1e..ce5897936b741 100644 --- a/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/has_log_monitoring_privileges.ts +++ b/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/has_log_monitoring_privileges.ts @@ -6,14 +6,17 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import { MONITOR_CLUSTER, INDEX_LOGS_AND_METRICS, WRITE_APM_EVENTS } from './privileges'; +import { + MONITOR_CLUSTER, + INDEX_LOGS_AND_METRICS, + INDEX_LOGS_METRICS_AND_TRACES, +} from './privileges'; export async function hasLogMonitoringPrivileges(esClient: ElasticsearchClient, withAPM = false) { const res = await esClient.security.hasPrivileges({ body: { cluster: [MONITOR_CLUSTER, 'manage_own_api_key'], - index: [INDEX_LOGS_AND_METRICS], - application: withAPM ? [WRITE_APM_EVENTS] : undefined, + index: [withAPM ? INDEX_LOGS_METRICS_AND_TRACES : INDEX_LOGS_AND_METRICS], }, }); diff --git a/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/privileges.ts b/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/privileges.ts index 7c3b5999842bd..8a28849ef1003 100644 --- a/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/privileges.ts +++ b/x-pack/plugins/observability_solution/observability_onboarding/server/lib/api_key/privileges.ts @@ -18,9 +18,8 @@ export const INDEX_LOGS_AND_METRICS: estypes.SecurityIndicesPrivileges = { privileges: ['auto_configure', 'create_doc'], }; -// https://www.elastic.co/guide/en/observability/master/apm-api-key.html#apm-create-api-key-workflow-es -export const WRITE_APM_EVENTS: estypes.SecurityApplicationPrivileges = { - application: 'apm', - privileges: ['event:write', 'config_agent:read'], - resources: ['*'], +// https://www.elastic.co/guide/en/fleet/master/grant-access-to-elasticsearch.html#create-api-key-standalone-agent +export const INDEX_LOGS_METRICS_AND_TRACES: estypes.SecurityIndicesPrivileges = { + names: ['logs-*-*', 'metrics-*-*', 'traces-*-*'], + privileges: ['auto_configure', 'create_doc'], }; From e42a5d3db6632efb9c546584f6fb75bf3fb232f7 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:06:07 +1100 Subject: [PATCH 24/33] [8.x] [SecuritySolution][Onboarding] Send Telemetry when integration tabs or cards clicked (#196291) (#197297) # Backport This will backport the following commits from `main` to `8.x`: - [[SecuritySolution][Onboarding] Send Telemetry when integration tabs or cards clicked (#196291)](https://github.com/elastic/kibana/pull/196291) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Angela Chuang <6295984+angorayc@users.noreply.github.com> --- .../public/common/lib/telemetry/constants.ts | 2 + .../common/lib/__mocks__/telemetry.ts | 8 ++++ .../public/onboarding/common/lib/telemetry.ts | 12 ++++++ .../callouts/agent_required_callout.test.tsx | 10 +++++ .../callouts/agent_required_callout.tsx | 14 ++++-- .../agentless_available_callout.test.tsx | 16 +++++-- .../callouts/agentless_available_callout.tsx | 9 +++- .../callouts/endpoint_callout.test.tsx | 43 +++++++++++++++++++ .../callouts/endpoint_callout.tsx | 8 +++- .../callouts/manage_integrations_callout.tsx | 15 ++++++- .../cards/integrations/constants.ts | 6 +++ .../integration_card_grid_tabs.test.tsx | 29 +++++++++++++ .../integration_card_grid_tabs.tsx | 4 ++ .../use_integration_card_list.test.ts | 17 +++++++- .../integrations/use_integration_card_list.ts | 4 ++ 15 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 x-pack/plugins/security_solution/public/onboarding/common/lib/__mocks__/telemetry.ts create mode 100644 x-pack/plugins/security_solution/public/onboarding/common/lib/telemetry.ts create mode 100644 x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/endpoint_callout.test.tsx diff --git a/x-pack/plugins/security_solution/public/common/lib/telemetry/constants.ts b/x-pack/plugins/security_solution/public/common/lib/telemetry/constants.ts index 5126d75178f5f..cb247891d79b3 100644 --- a/x-pack/plugins/security_solution/public/common/lib/telemetry/constants.ts +++ b/x-pack/plugins/security_solution/public/common/lib/telemetry/constants.ts @@ -35,6 +35,8 @@ export enum TELEMETRY_EVENT { DASHBOARD = 'navigate_to_dashboard', CREATE_DASHBOARD = 'create_dashboard', + ONBOARDING = 'onboarding', + // value list OPEN_VALUE_LIST_MODAL = 'open_value_list_modal', CREATE_VALUE_LIST_ITEM = 'create_value_list_item', diff --git a/x-pack/plugins/security_solution/public/onboarding/common/lib/__mocks__/telemetry.ts b/x-pack/plugins/security_solution/public/onboarding/common/lib/__mocks__/telemetry.ts new file mode 100644 index 0000000000000..5d1c3feb56ed9 --- /dev/null +++ b/x-pack/plugins/security_solution/public/onboarding/common/lib/__mocks__/telemetry.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const trackOnboardingLinkClick = jest.fn(); diff --git a/x-pack/plugins/security_solution/public/onboarding/common/lib/telemetry.ts b/x-pack/plugins/security_solution/public/onboarding/common/lib/telemetry.ts new file mode 100644 index 0000000000000..a88ae651ae600 --- /dev/null +++ b/x-pack/plugins/security_solution/public/onboarding/common/lib/telemetry.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { METRIC_TYPE, TELEMETRY_EVENT, track } from '../../../common/lib/telemetry'; + +export const trackOnboardingLinkClick = (linkId: string) => { + track(METRIC_TYPE.CLICK, `${TELEMETRY_EVENT.ONBOARDING}_${linkId}`); +}; diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.test.tsx b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.test.tsx index dbd0c105d27a1..53e8b6c34e8f2 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.test.tsx +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.test.tsx @@ -14,8 +14,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import { AgentRequiredCallout } from './agent_required_callout'; import { TestProviders } from '../../../../../../common/mock/test_providers'; +import { trackOnboardingLinkClick } from '../../../../../common/lib/telemetry'; jest.mock('../../../../../../common/lib/kibana'); +jest.mock('../../../../../common/lib/telemetry'); describe('AgentRequiredCallout', () => { beforeEach(() => { @@ -30,4 +32,12 @@ describe('AgentRequiredCallout', () => { ).toBeInTheDocument(); expect(getByTestId('agentLink')).toBeInTheDocument(); }); + + it('should track the agent link click', () => { + const { getByTestId } = render(, { wrapper: TestProviders }); + + getByTestId('agentLink').click(); + + expect(trackOnboardingLinkClick).toHaveBeenCalledWith('agent_required'); + }); }); diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.tsx b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.tsx index aad22c959bc65..b1d18b138487b 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.tsx +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agent_required_callout.tsx @@ -11,16 +11,22 @@ import { EuiIcon } from '@elastic/eui'; import { LinkAnchor } from '../../../../../../common/components/links'; import { CardCallOut } from '../../common/card_callout'; import { useNavigation } from '../../../../../../common/lib/kibana'; -import { FLEET_APP_ID, ADD_AGENT_PATH } from '../constants'; +import { FLEET_APP_ID, ADD_AGENT_PATH, TELEMETRY_AGENT_REQUIRED } from '../constants'; +import { trackOnboardingLinkClick } from '../../../../../common/lib/telemetry'; const fleetAgentLinkProps = { appId: FLEET_APP_ID, path: ADD_AGENT_PATH }; export const AgentRequiredCallout = React.memo(() => { const { getAppUrl, navigateTo } = useNavigation(); const addAgentLink = getAppUrl(fleetAgentLinkProps); - const onAddAgentClick = useCallback(() => { - navigateTo(fleetAgentLinkProps); - }, [navigateTo]); + const onAddAgentClick = useCallback( + (e: React.MouseEvent) => { + e.preventDefault(); + trackOnboardingLinkClick(TELEMETRY_AGENT_REQUIRED); + navigateTo(fleetAgentLinkProps); + }, + [navigateTo] + ); return ( ({ - useKibana: jest.fn(), -})); +jest.mock('../../../../../../common/lib/kibana'); +jest.mock('../../../../../common/lib/telemetry'); describe('AgentlessAvailableCallout', () => { const mockUseKibana = useKibana as jest.Mock; @@ -62,4 +62,14 @@ describe('AgentlessAvailableCallout', () => { ).toBeInTheDocument(); expect(getByTestId('agentlessLearnMoreLink')).toBeInTheDocument(); }); + + it('should track the agentless learn more link click', () => { + const { getByTestId } = render(, { + wrapper: TestProviders, + }); + + getByTestId('agentlessLearnMoreLink').click(); + + expect(trackOnboardingLinkClick).toHaveBeenCalledWith('agentless_learn_more'); + }); }); diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agentless_available_callout.tsx b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agentless_available_callout.tsx index f802f83efb7e5..eaf8cbaa3b287 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agentless_available_callout.tsx +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/agentless_available_callout.tsx @@ -5,19 +5,25 @@ * 2.0. */ -import React from 'react'; +import React, { useCallback } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiIcon, useEuiTheme } from '@elastic/eui'; import { css } from '@emotion/react'; import { useKibana } from '../../../../../../common/lib/kibana'; import { LinkAnchor } from '../../../../../../common/components/links'; +import { trackOnboardingLinkClick } from '../../../../../common/lib/telemetry'; import { CardCallOut } from '../../common/card_callout'; +import { TELEMETRY_AGENTLESS_LEARN_MORE } from '../constants'; export const AgentlessAvailableCallout = React.memo(() => { const { euiTheme } = useEuiTheme(); const { docLinks } = useKibana().services; + const onClick = useCallback(() => { + trackOnboardingLinkClick(TELEMETRY_AGENTLESS_LEARN_MORE); + }, []); + /* @ts-expect-error: add the blog link to `packages/kbn-doc-links/src/get_doc_links.ts` when it is ready and remove this exit condition*/ if (!docLinks.links.fleet.agentlessBlog) { return null; @@ -54,6 +60,7 @@ export const AgentlessAvailableCallout = React.memo(() => { { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('renders the callout', () => { + const { getByTestId, getByText } = render(, { wrapper: TestProviders }); + + expect( + getByText('Orchestrate response across endpoint vendors with bidirectional integrations') + ).toBeInTheDocument(); + expect(getByTestId('endpointLearnMoreLink')).toBeInTheDocument(); + }); + + it('should track the agent link click', () => { + const { getByTestId } = render(, { wrapper: TestProviders }); + + getByTestId('endpointLearnMoreLink').click(); + + expect(trackOnboardingLinkClick).toHaveBeenCalledWith('endpoint_learn_more'); + }); +}); diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/endpoint_callout.tsx b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/endpoint_callout.tsx index 2ff48a1992d1d..d5b0199c9f401 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/endpoint_callout.tsx +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/callouts/endpoint_callout.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React from 'react'; +import React, { useCallback } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiIcon, useEuiTheme } from '@elastic/eui'; import { css } from '@emotion/react'; @@ -13,10 +13,15 @@ import { css } from '@emotion/react'; import { useKibana } from '../../../../../../common/lib/kibana/kibana_react'; import { LinkAnchor } from '../../../../../../common/components/links'; import { CardCallOut } from '../../common/card_callout'; +import { trackOnboardingLinkClick } from '../../../../../common/lib/telemetry'; +import { TELEMETRY_ENDPOINT_LEARN_MORE } from '../constants'; export const EndpointCallout = React.memo(() => { const { euiTheme } = useEuiTheme(); const { docLinks } = useKibana().services; + const onClick = useCallback(() => { + trackOnboardingLinkClick(TELEMETRY_ENDPOINT_LEARN_MORE); + }, []); return ( { data-test-subj="endpointLearnMoreLink" external={true} target="_blank" + onClick={onClick} > { const { href: integrationUrl, onClick: onAddIntegrationClicked } = useAddIntegrationsUrl(); + const onClick = useCallback( + (e: React.MouseEvent) => { + e.preventDefault(); + trackOnboardingLinkClick(TELEMETRY_MANAGE_INTEGRATIONS); + onAddIntegrationClicked(e); + }, + [onAddIntegrationClicked] + ); + if (!installedIntegrationsCount) { return null; } @@ -41,7 +52,7 @@ export const ManageIntegrationsCallout = React.memo( ), link: ( diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/constants.ts b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/constants.ts index e245de6129478..c748f5205e7aa 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/constants.ts +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/constants.ts @@ -24,3 +24,9 @@ export const SCROLL_ELEMENT_ID = 'integrations-scroll-container'; export const SEARCH_FILTER_CATEGORIES: CategoryFacet[] = []; export const WITH_SEARCH_BOX_HEIGHT = '568px'; export const WITHOUT_SEARCH_BOX_HEIGHT = '513px'; +export const TELEMETRY_MANAGE_INTEGRATIONS = `manage_integrations`; +export const TELEMETRY_ENDPOINT_LEARN_MORE = `endpoint_learn_more`; +export const TELEMETRY_AGENTLESS_LEARN_MORE = `agentless_learn_more`; +export const TELEMETRY_AGENT_REQUIRED = `agent_required`; +export const TELEMETRY_INTEGRATION_CARD = `card`; +export const TELEMETRY_INTEGRATION_TAB = `tab`; diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.test.tsx b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.test.tsx index f55cc8cd50b2d..c88ffb6a598b7 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.test.tsx @@ -15,9 +15,11 @@ import { useStoredIntegrationTabId, } from '../../../../hooks/use_stored_state'; import { DEFAULT_TAB } from './constants'; +import { trackOnboardingLinkClick } from '../../../../common/lib/telemetry'; jest.mock('../../../onboarding_context'); jest.mock('../../../../hooks/use_stored_state'); +jest.mock('../../../../common/lib/telemetry'); jest.mock('../../../../../common/lib/kibana', () => ({ ...jest.requireActual('../../../../../common/lib/kibana'), @@ -118,6 +120,33 @@ describe('IntegrationsCardGridTabsComponent', () => { expect(mockSetTabId).toHaveBeenCalledWith('user'); }); + it('tracks the tab clicks', () => { + (useStoredIntegrationTabId as jest.Mock).mockReturnValue(['recommended', mockSetTabId]); + + mockUseAvailablePackages.mockReturnValue({ + isLoading: false, + filteredCards: [], + setCategory: mockSetCategory, + setSelectedSubCategory: mockSetSelectedSubCategory, + setSearchTerm: mockSetSearchTerm, + }); + + const { getByTestId } = render( + + ); + + const tabButton = getByTestId('user'); + + act(() => { + fireEvent.click(tabButton); + }); + + expect(trackOnboardingLinkClick).toHaveBeenCalledWith('tab_user'); + }); + it('renders no search tools when showSearchTools is false', async () => { mockUseAvailablePackages.mockReturnValue({ isLoading: false, diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.tsx b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.tsx index fc30fb0d6c617..e1ce7f5cdecf1 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.tsx +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs.tsx @@ -21,6 +21,7 @@ import { LOADING_SKELETON_TEXT_LINES, SCROLL_ELEMENT_ID, SEARCH_FILTER_CATEGORIES, + TELEMETRY_INTEGRATION_TAB, WITHOUT_SEARCH_BOX_HEIGHT, WITH_SEARCH_BOX_HEIGHT, } from './constants'; @@ -28,6 +29,7 @@ import { INTEGRATION_TABS, INTEGRATION_TABS_BY_ID } from './integration_tabs_con import { useIntegrationCardList } from './use_integration_card_list'; import { IntegrationTabId } from './types'; import { IntegrationCardTopCallout } from './callouts/integration_card_top_callout'; +import { trackOnboardingLinkClick } from '../../../../common/lib/telemetry'; export interface IntegrationsCardGridTabsProps { installedIntegrationsCount: number; @@ -55,8 +57,10 @@ export const IntegrationsCardGridTabsComponent = React.memo { const id = stringId as IntegrationTabId; + const trackId = `${TELEMETRY_INTEGRATION_TAB}_${id}`; scrollElement.current?.scrollTo?.(0, 0); setSelectedTabIdToStorage(id); + trackOnboardingLinkClick(trackId); }, [setSelectedTabIdToStorage] ); diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.test.ts b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.test.ts index 9c4e1978f27b7..19ab340276b83 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.test.ts +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.test.ts @@ -6,12 +6,14 @@ */ import { renderHook } from '@testing-library/react-hooks'; import { useIntegrationCardList } from './use_integration_card_list'; +import { trackOnboardingLinkClick } from '../../../../common/lib/telemetry'; +jest.mock('../../../../common/lib/telemetry'); jest.mock('../../../../../common/lib/kibana', () => ({ ...jest.requireActual('../../../../../common/lib/kibana'), useNavigation: jest.fn().mockReturnValue({ navigateTo: jest.fn(), - getAppUrl: jest.fn(), + getAppUrl: jest.fn().mockReturnValue(''), }), })); @@ -73,4 +75,17 @@ describe('useIntegrationCardList', () => { expect(result.current).toEqual([mockFilteredCards.featuredCards['epr:endpoint']]); }); + + it('tracks integration card click', () => { + const { result } = renderHook(() => + useIntegrationCardList({ + integrationsList: mockIntegrationsList, + }) + ); + + const card = result.current[0]; + card.onCardClick?.(); + + expect(trackOnboardingLinkClick).toHaveBeenCalledWith('card_epr:endpoint'); + }); }); diff --git a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.ts b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.ts index 2a9675f91e9a8..ccea5299551c1 100644 --- a/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.ts +++ b/x-pack/plugins/security_solution/public/onboarding/components/onboarding_body/cards/integrations/use_integration_card_list.ts @@ -20,8 +20,10 @@ import { MAX_CARD_HEIGHT_IN_PX, ONBOARDING_APP_ID, ONBOARDING_LINK, + TELEMETRY_INTEGRATION_CARD, } from './constants'; import type { GetAppUrl, NavigateTo } from '../../../../../common/lib/kibana'; +import { trackOnboardingLinkClick } from '../../../../common/lib/telemetry'; const addPathParamToUrl = (url: string, onboardingLink: string) => { const encoded = encodeURIComponent(onboardingLink); @@ -97,6 +99,8 @@ const addSecuritySpecificProps = ({ showInstallationStatus: true, url, onCardClick: () => { + const trackId = `${TELEMETRY_INTEGRATION_CARD}_${card.id}`; + trackOnboardingLinkClick(trackId); if (url.startsWith(APP_INTEGRATIONS_PATH)) { navigateTo({ appId: INTEGRATION_APP_ID, From 7c3334f03ce67441e081e2f5cdd48d92055b7454 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:24:12 +1100 Subject: [PATCH 25/33] [8.x] [SecuritySolution][Endpoint] Re-enabled skipped tests (#197220) (#197380) # Backport This will backport the following commits from `main` to `8.x`: - [[SecuritySolution][Endpoint] Re-enabled skipped tests (#197220)](https://github.com/elastic/kibana/pull/197220) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Ash <1849116+ashokaditya@users.noreply.github.com> --- .../actions_log_users_filter.test.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/components/actions_log_users_filter.test.tsx b/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/components/actions_log_users_filter.test.tsx index 5d47cfb3b43c3..535c0114426dd 100644 --- a/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/components/actions_log_users_filter.test.tsx +++ b/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/components/actions_log_users_filter.test.tsx @@ -15,9 +15,7 @@ import { import { ActionsLogUsersFilter } from './actions_log_users_filter'; import { MANAGEMENT_PATH } from '../../../../../common/constants'; -// FLAKY: https://github.com/elastic/kibana/issues/193554 -// FLAKY: https://github.com/elastic/kibana/issues/193092 -describe.skip('Users filter', () => { +describe('Users filter', () => { let render: ( props?: React.ComponentProps ) => ReturnType; @@ -29,7 +27,7 @@ describe.skip('Users filter', () => { const filterPrefix = 'users-filter'; let onChangeUsersFilter: jest.Mock; - beforeEach(async () => { + beforeEach(() => { onChangeUsersFilter = jest.fn(); mockedContext = createAppRootMockRenderer(); ({ history } = mockedContext); @@ -58,8 +56,8 @@ describe.skip('Users filter', () => { render(); const searchInput = renderResult.getByTestId(`${testPrefix}-${filterPrefix}-search`); - await userEvent.type(searchInput, 'usernameX'); - await userEvent.type(searchInput, '{enter}'); + await userEvent.type(searchInput, 'usernameX', { delay: 10 }); + await userEvent.keyboard('{enter}'); expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX']); }); @@ -67,8 +65,8 @@ describe.skip('Users filter', () => { render(); const searchInput = renderResult.getByTestId(`${testPrefix}-${filterPrefix}-search`); - await userEvent.type(searchInput, 'usernameX,usernameY,usernameZ'); - await userEvent.type(searchInput, '{enter}'); + await userEvent.type(searchInput, 'usernameX,usernameY,usernameZ', { delay: 10 }); + await userEvent.keyboard('{enter}'); expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX', 'usernameY', 'usernameZ']); }); @@ -76,8 +74,8 @@ describe.skip('Users filter', () => { render(); const searchInput = renderResult.getByTestId(`${testPrefix}-${filterPrefix}-search`); - await userEvent.type(searchInput, ' usernameX '); - await userEvent.type(searchInput, '{enter}'); + await userEvent.type(searchInput, ' usernameX ', { delay: 10 }); + await userEvent.keyboard('{enter}'); expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX']); }); @@ -85,8 +83,8 @@ describe.skip('Users filter', () => { render(); const searchInput = renderResult.getByTestId(`${testPrefix}-${filterPrefix}-search`); - await userEvent.type(searchInput, ' , usernameX ,usernameY , '); - await userEvent.type(searchInput, '{enter}'); + await userEvent.type(searchInput, ' , usernameX ,usernameY , ', { delay: 10 }); + await userEvent.keyboard('{enter}'); expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX', 'usernameY']); }); }); From 831f205aa80377154a6d9d6a3a12cd76b0fcd1bf Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 22:10:12 +1100 Subject: [PATCH 26/33] [8.x] [Index Management] Added docs count and size for serverless (#191985) (#197387) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[Index Management] Added docs count and size for serverless (#191985)](https://github.com/elastic/kibana/pull/191985) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Yulia Čech <6585477+yuliacech@users.noreply.github.com> --- .../test_suites/core_plugins/rendering.ts | 1 + .../home/data_streams_tab.helpers.ts | 12 +- .../home/data_streams_tab.test.ts | 98 +++++++++++++--- .../home/indices_tab.test.tsx | 33 +++++- ...tion.test.ts => data_stream_utils.test.ts} | 4 +- .../common/lib/data_stream_utils.ts | 64 ++++++++++ .../index_management/common/lib/index.ts | 6 +- .../common/lib/template_serialization.ts | 2 +- .../common/types/data_streams.ts | 5 + .../component_template_create.test.tsx | 2 +- .../component_template_form.tsx | 5 +- .../template_form/template_form.tsx | 2 +- .../data_stream_detail_panel.tsx | 110 ++++++++++++------ .../data_stream_list/data_stream_list.tsx | 61 +++++----- .../data_stream_table/data_stream_table.tsx | 74 ++++++++---- .../details_page_overview.tsx | 5 +- .../size_doc_count_details.tsx | 79 +++++++++++++ .../index_list/index_table/index_table.js | 43 ++++--- .../template_details/tabs/tab_summary.tsx | 2 +- .../plugins/index_management/public/plugin.ts | 6 +- .../plugins/index_management/server/config.ts | 1 + .../lib/data_stream_serialization.ts | 68 ++--------- .../server/lib/fetch_indices.ts | 7 +- .../index_management/server/lib/types.ts | 12 ++ .../api/data_streams/register_get_route.ts | 41 ++++++- .../common/index_management/datastreams.ts | 3 + 26 files changed, 531 insertions(+), 215 deletions(-) rename x-pack/plugins/index_management/common/lib/{data_stream_serialization.test.ts => data_stream_utils.test.ts} (81%) create mode 100644 x-pack/plugins/index_management/common/lib/data_stream_utils.ts create mode 100644 x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/size_doc_count_details.tsx rename x-pack/plugins/index_management/{common => server}/lib/data_stream_serialization.ts (58%) create mode 100644 x-pack/plugins/index_management/server/lib/types.ts diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index e3a1282ccc1cf..dd4188472a341 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -291,6 +291,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) { 'xpack.index_management.enableLegacyTemplates (boolean?|never)', 'xpack.index_management.enableIndexStats (boolean?|never)', 'xpack.index_management.enableDataStreamStats (boolean?|never)', + 'xpack.index_management.enableSizeAndDocCount (boolean?|never)', 'xpack.index_management.editableIndexSettings (all?|limited?|never)', 'xpack.index_management.enableMappingsSourceFieldSection (boolean?|never)', 'xpack.index_management.dev.enableSemanticText (boolean?)', diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts index 8b97b24eadb7a..bd119a77378af 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts @@ -24,7 +24,7 @@ export interface DataStreamsTabTestBed extends TestBed { actions: { goToDataStreamsList: () => void; clickEmptyPromptIndexTemplateLink: () => void; - clickIncludeStatsSwitch: () => void; + clickIncludeStatsSwitch: () => Promise; toggleViewFilterAt: (index: number) => void; sortTableOnStorageSize: () => void; sortTableOnName: () => void; @@ -90,9 +90,13 @@ export const setup = async ( component.update(); }; - const clickIncludeStatsSwitch = () => { - const { find } = testBed; - find('includeStatsSwitch').simulate('click'); + const clickIncludeStatsSwitch = async () => { + const { find, component } = testBed; + + await act(async () => { + find('includeStatsSwitch').simulate('click'); + }); + component.update(); }; const toggleViewFilterAt = (index: number) => { diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts index 26eb9eab172b3..a4ea7b9296e28 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts @@ -156,6 +156,10 @@ describe('Data Streams tab', () => { name: 'dataStream1', storageSize: '5b', storageSizeBytes: 5, + // metering API mock + meteringStorageSize: '156kb', + meteringStorageSizeBytes: 156000, + meteringDocsCount: 10000, }); setLoadDataStreamsResponse([ @@ -164,6 +168,10 @@ describe('Data Streams tab', () => { name: 'dataStream2', storageSize: '1kb', storageSizeBytes: 1000, + // metering API mock + meteringStorageSize: '156kb', + meteringStorageSizeBytes: 156000, + meteringDocsCount: 10000, lifecycle: { enabled: true, data_retention: '7d', @@ -224,15 +232,12 @@ describe('Data Streams tab', () => { }); test('has a switch that will reload the data streams with additional stats when clicked', async () => { - const { exists, actions, table, component } = testBed; + const { exists, actions, table } = testBed; expect(exists('includeStatsSwitch')).toBe(true); // Changing the switch will automatically reload the data streams. - await act(async () => { - actions.clickIncludeStatsSwitch(); - }); - component.update(); + await actions.clickIncludeStatsSwitch(); expect(httpSetup.get).toHaveBeenLastCalledWith( `${API_BASE_PATH}/data_streams`, @@ -267,12 +272,9 @@ describe('Data Streams tab', () => { test('sorting on stats sorts by bytes value instead of human readable value', async () => { // Guards against regression of #86122. - const { actions, table, component } = testBed; + const { actions, table } = testBed; - await act(async () => { - actions.clickIncludeStatsSwitch(); - }); - component.update(); + await actions.clickIncludeStatsSwitch(); actions.sortTableOnStorageSize(); @@ -306,7 +308,7 @@ describe('Data Streams tab', () => { actions.sortTableOnName(); }); - test('hides stats toggle if enableDataStreamStats===false', async () => { + test(`doesn't hide stats toggle if enableDataStreamStats===false`, async () => { testBed = await setup(httpSetup, { config: { enableDataStreamStats: false, @@ -321,14 +323,82 @@ describe('Data Streams tab', () => { component.update(); - expect(exists('includeStatsSwitch')).toBeFalsy(); + expect(exists('includeStatsSwitch')).toBeTruthy(); + }); + + test('shows storage size and documents count if enableSizeAndDocCount===true, enableDataStreamStats==false', async () => { + testBed = await setup(httpSetup, { + config: { + enableSizeAndDocCount: true, + enableDataStreamStats: false, + }, + }); + + const { actions, component, table } = testBed; + + await act(async () => { + actions.goToDataStreamsList(); + }); + + component.update(); + + await actions.clickIncludeStatsSwitch(); + + const { tableCellsValues } = table.getMetaData('dataStreamTable'); + expect(tableCellsValues).toEqual([ + ['', 'dataStream1', 'green', '156kb', '10000', '1', '7 days', 'Delete'], + ['', 'dataStream2', 'green', '156kb', '10000', '1', '5 days ', 'Delete'], + ]); + }); + + test('shows last updated and storage size if enableDataStreamStats===true, enableSizeAndDocCount===false', async () => { + testBed = await setup(httpSetup, { + config: { + enableDataStreamStats: true, + enableSizeAndDocCount: false, + }, + }); + + const { actions, component, table } = testBed; + + await act(async () => { + actions.goToDataStreamsList(); + }); + + component.update(); + + await actions.clickIncludeStatsSwitch(); + + const { tableCellsValues } = table.getMetaData('dataStreamTable'); + expect(tableCellsValues).toEqual([ + [ + '', + 'dataStream1', + 'green', + 'December 31st, 1969 7:00:00 PM', + '5b', + '1', + '7 days', + 'Delete', + ], + [ + '', + 'dataStream2', + 'green', + 'December 31st, 1969 7:00:00 PM', + '1kb', + '1', + '5 days ', + 'Delete', + ], + ]); }); test('clicking the indices count navigates to the backing indices', async () => { const { table, actions } = testBed; await actions.clickIndicesAt(0); expect(table.getMetaData('indexTable').tableCellsValues).toEqual([ - ['', 'data-stream-index', '', '', '', '', '', '', 'dataStream1'], + ['', 'data-stream-index', '', '', '', '', '0', '', 'dataStream1'], ]); }); @@ -707,7 +777,7 @@ describe('Data Streams tab', () => { const { table, actions } = testBed; await actions.clickIndicesAt(0); expect(table.getMetaData('indexTable').tableCellsValues).toEqual([ - ['', 'data-stream-index', '', '', '', '', '', '', '%dataStream'], + ['', 'data-stream-index', '', '', '', '', '0', '', '%dataStream'], ]); }); }); diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.tsx index 1bb5e6e26c9ea..351bc068f36a0 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.tsx @@ -394,7 +394,7 @@ describe('', () => { component.update(); }); - test('renders the table column with index stats by default', () => { + test('renders the table column with all index stats when enableIndexStats is true', () => { const { table } = testBed; const { tableCellsValues } = table.getMetaData('indexTable'); @@ -403,7 +403,7 @@ describe('', () => { ]); }); - describe('Disabled', () => { + describe('renders only size and docs count when enableIndexStats is false, enableSizeAndDocCount is true', () => { beforeEach(async () => { await act(async () => { testBed = await setup(httpSetup, { @@ -411,6 +411,7 @@ describe('', () => { enableLegacyTemplates: true, enableIndexActions: true, enableIndexStats: false, + enableSizeAndDocCount: true, }, }); }); @@ -420,7 +421,33 @@ describe('', () => { component.update(); }); - test('hides index stats information from table', async () => { + test('hides some index stats information from table', async () => { + const { table } = testBed; + const { tableCellsValues } = table.getMetaData('indexTable'); + + expect(tableCellsValues).toEqual([['', 'test', '10,000', '156kb', '']]); + }); + }); + + describe('renders no index stats when enableIndexStats is false, enableSizeAndDocCount is false', () => { + beforeEach(async () => { + await act(async () => { + testBed = await setup(httpSetup, { + config: { + enableLegacyTemplates: true, + enableIndexActions: true, + enableIndexStats: false, + enableSizeAndDocCount: false, + }, + }); + }); + + const { component } = testBed; + + component.update(); + }); + + test('hides all index stats information from table', async () => { const { table } = testBed; const { tableCellsValues } = table.getMetaData('indexTable'); diff --git a/x-pack/plugins/index_management/common/lib/data_stream_serialization.test.ts b/x-pack/plugins/index_management/common/lib/data_stream_utils.test.ts similarity index 81% rename from x-pack/plugins/index_management/common/lib/data_stream_serialization.test.ts rename to x-pack/plugins/index_management/common/lib/data_stream_utils.test.ts index 334e6bbf97de0..afbcf7835f764 100644 --- a/x-pack/plugins/index_management/common/lib/data_stream_serialization.test.ts +++ b/x-pack/plugins/index_management/common/lib/data_stream_utils.test.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { splitSizeAndUnits } from './data_stream_serialization'; +import { splitSizeAndUnits } from './data_stream_utils'; -describe('Data stream serialization', () => { +describe('Data stream utils', () => { test('can split size and units from lifecycle string', () => { expect(splitSizeAndUnits('1h')).toEqual({ size: '1', unit: 'h' }); expect(splitSizeAndUnits('20micron')).toEqual({ size: '20', unit: 'micron' }); diff --git a/x-pack/plugins/index_management/common/lib/data_stream_utils.ts b/x-pack/plugins/index_management/common/lib/data_stream_utils.ts new file mode 100644 index 0000000000000..443373f8a6b4b --- /dev/null +++ b/x-pack/plugins/index_management/common/lib/data_stream_utils.ts @@ -0,0 +1,64 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { DataStream, DataRetention } from '../types'; + +export const splitSizeAndUnits = (field: string): { size: string; unit: string } => { + let size = ''; + let unit = ''; + + const result = /(\d+)(\w+)/.exec(field); + if (result) { + size = result[1]; + unit = result[2]; + } + + return { + size, + unit, + }; +}; + +export const serializeAsESLifecycle = (lifecycle?: DataRetention): DataStream['lifecycle'] => { + if (!lifecycle || !lifecycle?.enabled) { + return undefined; + } + + const { infiniteDataRetention, value, unit } = lifecycle; + + if (infiniteDataRetention) { + return { + enabled: true, + }; + } + + return { + enabled: true, + data_retention: `${value}${unit}`, + }; +}; + +export const deserializeESLifecycle = (lifecycle?: DataStream['lifecycle']): DataRetention => { + if (!lifecycle || !lifecycle?.enabled) { + return { enabled: false }; + } + + if (!lifecycle.data_retention) { + return { + enabled: true, + infiniteDataRetention: true, + }; + } + + const { size, unit } = splitSizeAndUnits(lifecycle.data_retention as string); + + return { + enabled: true, + value: Number(size), + unit, + }; +}; diff --git a/x-pack/plugins/index_management/common/lib/index.ts b/x-pack/plugins/index_management/common/lib/index.ts index d46d3d8b6a1d4..da29f3289bcd4 100644 --- a/x-pack/plugins/index_management/common/lib/index.ts +++ b/x-pack/plugins/index_management/common/lib/index.ts @@ -6,10 +6,10 @@ */ export { - deserializeDataStream, - deserializeDataStreamList, splitSizeAndUnits, -} from './data_stream_serialization'; + serializeAsESLifecycle, + deserializeESLifecycle, +} from './data_stream_utils'; export { deserializeTemplate, diff --git a/x-pack/plugins/index_management/common/lib/template_serialization.ts b/x-pack/plugins/index_management/common/lib/template_serialization.ts index aacbc15aab3b8..f8b4ed47a22f7 100644 --- a/x-pack/plugins/index_management/common/lib/template_serialization.ts +++ b/x-pack/plugins/index_management/common/lib/template_serialization.ts @@ -12,7 +12,7 @@ import { TemplateListItem, TemplateType, } from '../types'; -import { deserializeESLifecycle } from './data_stream_serialization'; +import { deserializeESLifecycle } from './data_stream_utils'; import { allowAutoCreateRadioValues, allowAutoCreateRadioIds } from '../constants'; const hasEntries = (data: object = {}) => Object.entries(data).length > 0; diff --git a/x-pack/plugins/index_management/common/types/data_streams.ts b/x-pack/plugins/index_management/common/types/data_streams.ts index 4e20252792d71..c44305edb9d8f 100644 --- a/x-pack/plugins/index_management/common/types/data_streams.ts +++ b/x-pack/plugins/index_management/common/types/data_streams.ts @@ -37,6 +37,8 @@ export interface EnhancedDataStreamFromEs extends IndicesDataStream { store_size?: IndicesDataStreamsStatsDataStreamsStatsItem['store_size']; store_size_bytes?: IndicesDataStreamsStatsDataStreamsStatsItem['store_size_bytes']; maximum_timestamp?: IndicesDataStreamsStatsDataStreamsStatsItem['maximum_timestamp']; + metering_size_in_bytes?: number; + metering_doc_count?: number; indices: DataStreamIndexFromEs[]; privileges: { delete_index: boolean; @@ -55,6 +57,9 @@ export interface DataStream { storageSize?: ByteSize; storageSizeBytes?: number; maxTimeStamp?: number; + meteringStorageSizeBytes?: number; + meteringStorageSize?: string; + meteringDocsCount?: number; _meta?: Metadata; privileges: Privileges; hidden: boolean; diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx index 729ca7680ad6c..787aa68907730 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx @@ -12,7 +12,7 @@ import { breadcrumbService, IndexManagementBreadcrumb } from '../../../../servic import { setupEnvironment } from './helpers'; import { API_BASE_PATH } from './helpers/constants'; import { setup, ComponentTemplateCreateTestBed } from './helpers/component_template_create.helpers'; -import { serializeAsESLifecycle } from '../../../../../../common/lib/data_stream_serialization'; +import { serializeAsESLifecycle } from '../../../../../../common/lib'; jest.mock('@kbn/code-editor', () => { const original = jest.requireActual('@kbn/code-editor'); diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx index 1cbc33fc05135..ca791311d2408 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx @@ -19,10 +19,7 @@ import { StepMappingsContainer, StepAliasesContainer, } from '../../shared_imports'; -import { - serializeAsESLifecycle, - deserializeESLifecycle, -} from '../../../../../../common/lib/data_stream_serialization'; +import { serializeAsESLifecycle, deserializeESLifecycle } from '../../../../../../common/lib'; import { useComponentTemplatesContext } from '../../component_templates_context'; import { StepLogisticsContainer, StepReviewContainer } from './steps'; diff --git a/x-pack/plugins/index_management/public/application/components/template_form/template_form.tsx b/x-pack/plugins/index_management/public/application/components/template_form/template_form.tsx index ac247500e3248..2da3eef609a65 100644 --- a/x-pack/plugins/index_management/public/application/components/template_form/template_form.tsx +++ b/x-pack/plugins/index_management/public/application/components/template_form/template_form.tsx @@ -22,7 +22,7 @@ import { } from '../shared'; import { documentationService } from '../../services/documentation'; import { SectionError } from '../section_error'; -import { serializeAsESLifecycle } from '../../../../common/lib/data_stream_serialization'; +import { serializeAsESLifecycle } from '../../../../common/lib'; import { SimulateTemplateFlyoutContent, SimulateTemplateProps, diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx index da53b0241095d..974ba6f082042 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx @@ -52,13 +52,14 @@ import { useAppContext } from '../../../../app_context'; import { DataStreamsBadges } from '../data_stream_badges'; import { useIlmLocator } from '../../../../services/use_ilm_locator'; +interface Detail { + name: string; + toolTip: string; + content: any; + dataTestSubj: string; +} interface DetailsListProps { - details: Array<{ - name: string; - toolTip: string; - content: any; - dataTestSubj: string; - }>; + details: Detail[]; } const DetailsList: React.FunctionComponent = ({ details }) => { @@ -162,6 +163,8 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ ilmPolicyName, storageSize, maxTimeStamp, + meteringStorageSize, + meteringDocsCount, lifecycle, } = dataStream; @@ -222,7 +225,7 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ ); - const defaultDetails = [ + const defaultDetails: Detail[] = [ { name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.healthTitle', { defaultMessage: 'Health', @@ -233,34 +236,67 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ content: , dataTestSubj: 'healthDetail', }, - { - name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampTitle', { - defaultMessage: 'Last updated', - }), - toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampToolTip', { - defaultMessage: 'The most recent document to be added to the data stream.', - }), - content: maxTimeStamp ? ( - humanizeTimeStamp(maxTimeStamp) - ) : ( - - {i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampNoneMessage', { - defaultMessage: `Never`, - })} - - ), - dataTestSubj: 'lastUpdatedDetail', - }, - { - name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeTitle', { - defaultMessage: 'Storage size', - }), - toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeToolTip', { - defaultMessage: `The total size of all shards in the data stream’s backing indices.`, - }), - content: storageSize, - dataTestSubj: 'storageSizeDetail', - }, + ]; + + // add either documents count and size or last updated and size + if (config.enableSizeAndDocCount) { + defaultDetails.push( + { + name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.meteringDocsCountTitle', { + defaultMessage: 'Documents count', + }), + toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.meteringDocsCountToolTip', { + defaultMessage: 'The number of documents in this data stream.', + }), + content: meteringDocsCount, + dataTestSubj: 'docsCountDetail', + }, + { + name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeTitle', { + defaultMessage: 'Storage size', + }), + toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeToolTip', { + defaultMessage: `The total size of all shards in the data stream’s backing indices.`, + }), + content: meteringStorageSize, + dataTestSubj: 'meteringStorageSizeDetail', + } + ); + } + if (config.enableDataStreamStats) { + defaultDetails.push( + { + name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampTitle', { + defaultMessage: 'Last updated', + }), + toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampToolTip', { + defaultMessage: 'The most recent document to be added to the data stream.', + }), + content: maxTimeStamp ? ( + humanizeTimeStamp(maxTimeStamp) + ) : ( + + {i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampNoneMessage', { + defaultMessage: `Never`, + })} + + ), + dataTestSubj: 'lastUpdatedDetail', + }, + { + name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeTitle', { + defaultMessage: 'Storage size', + }), + toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeToolTip', { + defaultMessage: `The total size of all shards in the data stream’s backing indices.`, + }), + content: storageSize, + dataTestSubj: 'storageSizeDetail', + } + ); + } + + defaultDetails.push( { name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.indicesTitle', { defaultMessage: 'Indices', @@ -328,8 +364,8 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ ), dataTestSubj: 'dataRetentionDetail', - }, - ]; + } + ); // If both rentention types are available, we wanna surface to the user both if (lifecycle?.effective_retention && lifecycle?.data_retention) { diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx index 0103b51f1f51d..125f676897ffb 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx @@ -60,11 +60,8 @@ export const DataStreamList: React.FunctionComponent - {isDataStreamStatsEnabled && ( - - - - setIsIncludeStatsChecked(e.target.checked)} - data-test-subj="includeStatsSwitch" - /> - + + + + setIsIncludeStatsChecked(e.target.checked)} + data-test-subj="includeStatsSwitch" + /> + - - - - - - )} + + + + + filters={filters} onChange={setFilters} /> diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx index b4dbb663e0859..47b170babc5a6 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx @@ -104,31 +104,55 @@ export const DataStreamTable: React.FunctionComponent = ({ }); if (includeStats) { - columns.push({ - field: 'maxTimeStamp', - name: i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnTitle', { - defaultMessage: 'Last updated', - }), - truncateText: true, - sortable: true, - render: (maxTimeStamp: DataStream['maxTimeStamp']) => - maxTimeStamp - ? humanizeTimeStamp(maxTimeStamp) - : i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnNoneMessage', { - defaultMessage: 'Never', - }), - }); - - columns.push({ - field: 'storageSizeBytes', - name: i18n.translate('xpack.idxMgmt.dataStreamList.table.storageSizeColumnTitle', { - defaultMessage: 'Storage size', - }), - truncateText: true, - sortable: true, - render: (storageSizeBytes: DataStream['storageSizeBytes'], dataStream: DataStream) => - dataStream.storageSize, - }); + if (config.enableSizeAndDocCount) { + // datastreams stats from metering API on serverless + columns.push({ + field: 'meteringStorageSizeBytes', + name: i18n.translate('xpack.idxMgmt.dataStreamList.table.storageSizeColumnTitle', { + defaultMessage: 'Storage size', + }), + truncateText: true, + sortable: true, + render: ( + meteringStorageSizeBytes: DataStream['meteringStorageSizeBytes'], + dataStream: DataStream + ) => dataStream.meteringStorageSize, + }); + columns.push({ + field: 'meteringDocsCount', + name: i18n.translate('xpack.idxMgmt.dataStreamList.table.docsCountColumnTitle', { + defaultMessage: 'Documents count', + }), + truncateText: true, + sortable: true, + }); + } + if (config.enableDataStreamStats) { + columns.push({ + field: 'maxTimeStamp', + name: i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnTitle', { + defaultMessage: 'Last updated', + }), + truncateText: true, + sortable: true, + render: (maxTimeStamp: DataStream['maxTimeStamp']) => + maxTimeStamp + ? humanizeTimeStamp(maxTimeStamp) + : i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnNoneMessage', { + defaultMessage: 'Never', + }), + }); + columns.push({ + field: 'storageSizeBytes', + name: i18n.translate('xpack.idxMgmt.dataStreamList.table.storageSizeColumnTitle', { + defaultMessage: 'Storage size', + }), + truncateText: true, + sortable: true, + render: (storageSizeBytes: DataStream['storageSizeBytes'], dataStream: DataStream) => + dataStream.storageSize, + }); + } } columns.push({ diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/details_page_overview.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/details_page_overview.tsx index a3be075ec9731..6a767eef29fd5 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/details_page_overview.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/details_page_overview.tsx @@ -26,14 +26,15 @@ import { getLanguageDefinitionCodeSnippet, getConsoleRequest, } from '@kbn/search-api-panels'; -import { StatusDetails } from './status_details'; import type { Index } from '../../../../../../../common'; import { useAppContext } from '../../../../../app_context'; import { documentationService } from '../../../../../services'; import { languageDefinitions, curlDefinition } from './languages'; +import { StatusDetails } from './status_details'; import { DataStreamDetails } from './data_stream_details'; import { StorageDetails } from './storage_details'; import { AliasesDetails } from './aliases_details'; +import { SizeDocCountDetails } from './size_doc_count_details'; interface Props { indexDetails: Index; @@ -89,6 +90,8 @@ export const DetailsPageOverview: React.FunctionComponent = ({ indexDetai health={health} /> + + {dataStream && } diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/size_doc_count_details.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/size_doc_count_details.tsx new file mode 100644 index 0000000000000..40294d76b2698 --- /dev/null +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_overview/size_doc_count_details.tsx @@ -0,0 +1,79 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { FunctionComponent } from 'react'; +import { css } from '@emotion/react'; +import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText, EuiTextColor } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { euiThemeVars } from '@kbn/ui-theme'; +import type { Index } from '../../../../../../../common'; +import { useAppContext } from '../../../../../app_context'; +import { OverviewCard } from './overview_card'; + +export const SizeDocCountDetails: FunctionComponent<{ + size: Index['size']; + documents: Index['documents']; +}> = ({ size, documents }) => { + const { config } = useAppContext(); + if (!config.enableSizeAndDocCount) { + return null; + } + return ( + + + + {size} + + + + + {i18n.translate('xpack.idxMgmt.indexDetails.overviewTab.storage.totalSizeLabel', { + defaultMessage: 'Total', + })} + + + + ), + right: null, + }} + footer={{ + left: ( + + + + + {documents} + + + {i18n.translate( + 'xpack.idxMgmt.indexDetails.overviewTab.status.meteringDocumentsLabel', + { + defaultMessage: '{documents, plural, one {Document} other {Documents}}', + values: { + documents, + }, + } + )} + + + + ), + }} + /> + ); +}; diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js index d955fd29d847f..9567aee715c3b 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js @@ -52,6 +52,7 @@ import { IndexTablePagination, PAGE_SIZE_OPTIONS } from './index_table_paginatio const getColumnConfigs = ({ showIndexStats, + showSizeAndDocCount, history, filterChanged, extensionsService, @@ -111,6 +112,28 @@ const getColumnConfigs = ({ }, ]; + // size and docs count enabled by either "enableIndexStats" or "enableSizeAndDocCount" configs + if (showIndexStats || showSizeAndDocCount) { + columns.push( + { + fieldName: 'documents', + label: i18n.translate('xpack.idxMgmt.indexTable.headers.documentsHeader', { + defaultMessage: 'Documents count', + }), + order: 60, + render: (index) => { + return Number(index.documents ?? 0).toLocaleString(); + }, + }, + { + fieldName: 'size', + label: i18n.translate('xpack.idxMgmt.indexTable.headers.storageSizeHeader', { + defaultMessage: 'Storage size', + }), + order: 70, + } + ); + } if (showIndexStats) { columns.push( { @@ -141,25 +164,6 @@ const getColumnConfigs = ({ defaultMessage: 'Replicas', }), order: 50, - }, - { - fieldName: 'documents', - label: i18n.translate('xpack.idxMgmt.indexTable.headers.documentsHeader', { - defaultMessage: 'Docs count', - }), - order: 60, - render: (index) => { - if (index.documents) { - return Number(index.documents).toLocaleString(); - } - }, - }, - { - fieldName: 'size', - label: i18n.translate('xpack.idxMgmt.indexTable.headers.storageSizeHeader', { - defaultMessage: 'Storage size', - }), - order: 70, } ); } @@ -545,6 +549,7 @@ export class IndexTable extends Component { const { application, http } = core; const columnConfigs = getColumnConfigs({ showIndexStats: config.enableIndexStats, + showSizeAndDocCount: config.enableSizeAndDocCount, extensionsService, filterChanged, history, diff --git a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx index c2aa548100b57..513377714ffe0 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx @@ -22,7 +22,7 @@ import { } from '@elastic/eui'; import { reactRouterNavigate } from '../../../../../../shared_imports'; import { useAppContext } from '../../../../../app_context'; -import { serializeAsESLifecycle } from '../../../../../../../common/lib/data_stream_serialization'; +import { serializeAsESLifecycle } from '../../../../../../../common/lib'; import { getLifecycleValue } from '../../../../../lib/data_streams'; import { TemplateDeserialized } from '../../../../../../../common'; import { ILM_PAGES_POLICY_EDIT } from '../../../../../constants'; diff --git a/x-pack/plugins/index_management/public/plugin.ts b/x-pack/plugins/index_management/public/plugin.ts index 3b2d9ad68de20..d0c92da025fe0 100644 --- a/x-pack/plugins/index_management/public/plugin.ts +++ b/x-pack/plugins/index_management/public/plugin.ts @@ -48,8 +48,8 @@ export class IndexMgmtUIPlugin enableIndexActions: boolean; enableLegacyTemplates: boolean; enableIndexStats: boolean; - enableSizeAndDocCount: boolean; enableDataStreamStats: boolean; + enableSizeAndDocCount: boolean; editableIndexSettings: 'all' | 'limited'; isIndexManagementUiEnabled: boolean; enableMappingsSourceFieldSection: boolean; @@ -67,8 +67,8 @@ export class IndexMgmtUIPlugin enableIndexActions, enableLegacyTemplates, enableIndexStats, - enableSizeAndDocCount, enableDataStreamStats, + enableSizeAndDocCount, editableIndexSettings, enableMappingsSourceFieldSection, enableTogglingDataRetention, @@ -79,8 +79,8 @@ export class IndexMgmtUIPlugin enableIndexActions: enableIndexActions ?? true, enableLegacyTemplates: enableLegacyTemplates ?? true, enableIndexStats: enableIndexStats ?? true, - enableSizeAndDocCount: enableSizeAndDocCount ?? true, enableDataStreamStats: enableDataStreamStats ?? true, + enableSizeAndDocCount: enableSizeAndDocCount ?? false, editableIndexSettings: editableIndexSettings ?? 'all', enableMappingsSourceFieldSection: enableMappingsSourceFieldSection ?? true, enableTogglingDataRetention: enableTogglingDataRetention ?? true, diff --git a/x-pack/plugins/index_management/server/config.ts b/x-pack/plugins/index_management/server/config.ts index 3480e380281e5..9bddc6417cc1b 100644 --- a/x-pack/plugins/index_management/server/config.ts +++ b/x-pack/plugins/index_management/server/config.ts @@ -83,6 +83,7 @@ const configLatest: PluginConfigDescriptor = { enableLegacyTemplates: true, enableIndexStats: true, enableDataStreamStats: true, + enableSizeAndDocCount: true, editableIndexSettings: true, enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, diff --git a/x-pack/plugins/index_management/common/lib/data_stream_serialization.ts b/x-pack/plugins/index_management/server/lib/data_stream_serialization.ts similarity index 58% rename from x-pack/plugins/index_management/common/lib/data_stream_serialization.ts rename to x-pack/plugins/index_management/server/lib/data_stream_serialization.ts index ceedd072139aa..ffe058907e000 100644 --- a/x-pack/plugins/index_management/common/lib/data_stream_serialization.ts +++ b/x-pack/plugins/index_management/server/lib/data_stream_serialization.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { DataStream, EnhancedDataStreamFromEs, Health, DataRetention } from '../types'; +import { ByteSizeValue } from '@kbn/config-schema'; +import type { DataStream, EnhancedDataStreamFromEs, Health } from '../../common'; export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs): DataStream { const { @@ -19,12 +20,18 @@ export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs store_size: storageSize, store_size_bytes: storageSizeBytes, maximum_timestamp: maxTimeStamp, + metering_size_in_bytes: meteringStorageSizeBytes, + metering_doc_count: meteringDocsCount, _meta, privileges, hidden, lifecycle, next_generation_managed_by: nextGenerationManagedBy, } = dataStreamFromEs; + const meteringStorageSize = + meteringStorageSizeBytes !== undefined + ? new ByteSizeValue(meteringStorageSizeBytes).toString() + : undefined; return { name, @@ -54,6 +61,9 @@ export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs storageSize, storageSizeBytes, maxTimeStamp, + meteringStorageSize, + meteringStorageSizeBytes, + meteringDocsCount, _meta, privileges, hidden, @@ -67,59 +77,3 @@ export function deserializeDataStreamList( ): DataStream[] { return dataStreamsFromEs.map((dataStream) => deserializeDataStream(dataStream)); } - -export const splitSizeAndUnits = (field: string): { size: string; unit: string } => { - let size = ''; - let unit = ''; - - const result = /(\d+)(\w+)/.exec(field); - if (result) { - size = result[1]; - unit = result[2]; - } - - return { - size, - unit, - }; -}; - -export const serializeAsESLifecycle = (lifecycle?: DataRetention): DataStream['lifecycle'] => { - if (!lifecycle || !lifecycle?.enabled) { - return undefined; - } - - const { infiniteDataRetention, value, unit } = lifecycle; - - if (infiniteDataRetention) { - return { - enabled: true, - }; - } - - return { - enabled: true, - data_retention: `${value}${unit}`, - }; -}; - -export const deserializeESLifecycle = (lifecycle?: DataStream['lifecycle']): DataRetention => { - if (!lifecycle || !lifecycle?.enabled) { - return { enabled: false }; - } - - if (!lifecycle.data_retention) { - return { - enabled: true, - infiniteDataRetention: true, - }; - } - - const { size, unit } = splitSizeAndUnits(lifecycle.data_retention as string); - - return { - enabled: true, - value: Number(size), - unit, - }; -}; diff --git a/x-pack/plugins/index_management/server/lib/fetch_indices.ts b/x-pack/plugins/index_management/server/lib/fetch_indices.ts index 1df453d1042cd..0e82f03f7308f 100644 --- a/x-pack/plugins/index_management/server/lib/fetch_indices.ts +++ b/x-pack/plugins/index_management/server/lib/fetch_indices.ts @@ -10,13 +10,10 @@ import { IScopedClusterClient } from '@kbn/core/server'; import { IndexDataEnricher } from '../services'; import { Index } from '..'; import { RouteDependencies } from '../types'; +import type { MeteringStats } from './types'; interface MeteringStatsResponse { - indices: Array<{ - name: string; - num_docs: number; - size_in_bytes: number; - }>; + indices: MeteringStats[]; } async function fetchIndicesCall( diff --git a/x-pack/plugins/index_management/server/lib/types.ts b/x-pack/plugins/index_management/server/lib/types.ts new file mode 100644 index 0000000000000..1657c4bbbb6e0 --- /dev/null +++ b/x-pack/plugins/index_management/server/lib/types.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export interface MeteringStats { + name: string; + num_docs: number; + size_in_bytes: number; +} diff --git a/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts b/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts index 11db019eacf6a..78c0328f52617 100644 --- a/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts @@ -13,18 +13,27 @@ import { IndicesDataStreamsStatsDataStreamsStatsItem, SecurityHasPrivilegesResponse, } from '@elastic/elasticsearch/lib/api/types'; -import { deserializeDataStream, deserializeDataStreamList } from '../../../../common/lib'; +import type { MeteringStats } from '../../../lib/types'; +import { + deserializeDataStream, + deserializeDataStreamList, +} from '../../../lib/data_stream_serialization'; import { EnhancedDataStreamFromEs } from '../../../../common/types'; import { RouteDependencies } from '../../../types'; import { addBasePath } from '..'; +interface MeteringStatsResponse { + datastreams: MeteringStats[]; +} const enhanceDataStreams = ({ dataStreams, dataStreamsStats, + meteringStats, dataStreamsPrivileges, }: { dataStreams: IndicesDataStream[]; dataStreamsStats?: IndicesDataStreamsStatsDataStreamsStatsItem[]; + meteringStats?: MeteringStats[]; dataStreamsPrivileges?: SecurityHasPrivilegesResponse; }): EnhancedDataStreamFromEs[] => { return dataStreams.map((dataStream) => { @@ -51,6 +60,14 @@ const enhanceDataStreams = ({ } } + if (meteringStats) { + const datastreamMeteringStats = meteringStats.find((s) => s.name === dataStream.name); + if (datastreamMeteringStats) { + enhancedDataStream.metering_size_in_bytes = datastreamMeteringStats.size_in_bytes; + enhancedDataStream.metering_doc_count = datastreamMeteringStats.num_docs; + } + } + return enhancedDataStream; }); }; @@ -70,6 +87,17 @@ const getDataStreamsStats = (client: IScopedClusterClient, name = '*') => { }); }; +const getMeteringStats = (client: IScopedClusterClient, name?: string) => { + let path = `/_metering/stats`; + if (name) { + path = `${path}/${name}`; + } + return client.asSecondaryAuthUser.transport.request({ + method: 'GET', + path, + }); +}; + const getDataStreamsPrivileges = (client: IScopedClusterClient, names: string[]) => { return client.asCurrentUser.security.hasPrivileges({ body: { @@ -99,10 +127,14 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }: let dataStreamsStats; let dataStreamsPrivileges; + let meteringStats; if (includeStats && config.isDataStreamStatsEnabled !== false) { ({ data_streams: dataStreamsStats } = await getDataStreamsStats(client)); } + if (includeStats && config.isSizeAndDocCountEnabled !== false) { + ({ datastreams: meteringStats } = await getMeteringStats(client)); + } if (config.isSecurityEnabled() && dataStreams.length > 0) { dataStreamsPrivileges = await getDataStreamsPrivileges( @@ -114,6 +146,7 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }: const enhancedDataStreams = enhanceDataStreams({ dataStreams, dataStreamsStats, + meteringStats, dataStreamsPrivileges, }); @@ -138,6 +171,7 @@ export function registerGetOneRoute({ router, lib: { handleEsError }, config }: const { name } = request.params as TypeOf; const { client } = (await context.core).elasticsearch; let dataStreamsStats; + let meteringStats; try { const { data_streams: dataStreams } = await getDataStreams(client, name); @@ -146,6 +180,10 @@ export function registerGetOneRoute({ router, lib: { handleEsError }, config }: ({ data_streams: dataStreamsStats } = await getDataStreamsStats(client, name)); } + if (config.isSizeAndDocCountEnabled !== false) { + ({ datastreams: meteringStats } = await getMeteringStats(client, name)); + } + if (dataStreams[0]) { let dataStreamsPrivileges; @@ -156,6 +194,7 @@ export function registerGetOneRoute({ router, lib: { handleEsError }, config }: const enhancedDataStreams = enhanceDataStreams({ dataStreams, dataStreamsStats, + meteringStats, dataStreamsPrivileges, }); const body = deserializeDataStream(enhancedDataStreams[0]); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts b/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts index 961c9a73bdf47..de3a92587d6b9 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts @@ -118,6 +118,9 @@ export default function ({ getService }: FtrProviderContext) { lifecycle: { enabled: true, }, + meteringDocsCount: 0, + meteringStorageSize: '0b', + meteringStorageSizeBytes: 0, }); }); }); From c8e498409c83b11ebf659a8a0b2b1ac9832469d5 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 22:29:39 +1100 Subject: [PATCH 27/33] [8.x] [ES|QL] Fix incorrect suggestions after a field is accepted in EVAL (#197139) (#197393) # Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Fix incorrect suggestions after a field is accepted in EVAL (#197139)](https://github.com/elastic/kibana/pull/197139) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Quynh Nguyen (Quinn) <43350163+qn895@users.noreply.github.com> --- .../__tests__/autocomplete.suggest.eval.test.ts | 7 +++++++ .../src/autocomplete/autocomplete.ts | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts index dcb6fe76f184b..81fd8f7f43902 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts @@ -51,6 +51,13 @@ describe('autocomplete.suggest', () => { ...getFieldNamesByType('any'), ...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }), ]); + + await assertSuggestions('from a | eval doubleField/', [ + 'doubleField, ', + 'doubleField | ', + 'var0 = ', + ]); + await assertSuggestions('from a | eval doubleField /', [ ...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [ 'double', diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.ts index cbc84232b8eb6..98a26b0c8dd4b 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.ts @@ -596,6 +596,17 @@ async function getExpressionSuggestionsByType( const suggestions: SuggestionRawDefinition[] = []; + // When user types and accepts autocomplete suggestion, and cursor is placed at the end of a valid field + // we should not show irrelevant functions that might have words matching + const columnWithActiveCursor = commands.find( + (c) => + c.name === command.name && + command.name === 'eval' && + c.args.some((arg) => isColumnItem(arg) && arg.name.includes(EDITOR_MARKER)) + ); + + const shouldShowFunctions = !columnWithActiveCursor; + // in this flow there's a clear plan here from argument definitions so try to follow it if (argDef) { if (argDef.type === 'column' || argDef.type === 'any' || argDef.type === 'function') { @@ -722,7 +733,7 @@ async function getExpressionSuggestionsByType( option?.name, getFieldsByType, { - functions: true, + functions: shouldShowFunctions, fields: false, variables: nodeArg ? undefined : anyVariables, literals: argDef.constantOnly, From 19dde645c8c352d11efdfe8dc13e166103dcdb35 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Wed, 23 Oct 2024 12:51:08 +0100 Subject: [PATCH 28/33] [8.x] [Entity Store] [FTR Tests] Fix flakiness + poll for engine started on setup (#196564) (#197050) # Backport This will backport the following commits from `main` to `8.x`: - [[Entity Store] [FTR Tests] Fix flakiness + poll for engine started on setup (#196564)](https://github.com/elastic/kibana/pull/196564) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --- .../elasticsearch_assets/enrich_policy.ts | 30 ++++- .../entity_store/entity_store_data_client.ts | 5 +- .../trial_license_complete_tier/engine.ts | 21 ++- .../engine_nondefault_spaces.ts | 18 +-- .../utils/elastic_asset_checker.ts | 127 +++++++++++------- .../entity_analytics/utils/entity_store.ts | 33 ++++- 6 files changed, 151 insertions(+), 83 deletions(-) diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/elasticsearch_assets/enrich_policy.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/elasticsearch_assets/enrich_policy.ts index 7d6fc6fd8bc24..4b8ce594a6cb7 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/elasticsearch_assets/enrich_policy.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/elasticsearch_assets/enrich_policy.ts @@ -72,10 +72,36 @@ export const executeFieldRetentionEnrichPolicy = async ({ export const deleteFieldRetentionEnrichPolicy = async ({ unitedDefinition, esClient, + logger, + attempts = 5, + delayMs = 2000, }: { - esClient: ElasticsearchClient; unitedDefinition: DefinitionMetadata; + esClient: ElasticsearchClient; + logger: Logger; + attempts?: number; + delayMs?: number; }) => { const name = getFieldRetentionEnrichPolicyName(unitedDefinition); - return esClient.enrich.deletePolicy({ name }, { ignore: [404] }); + let currentAttempt = 1; + while (currentAttempt <= attempts) { + try { + await esClient.enrich.deletePolicy({ name }, { ignore: [404] }); + return; + } catch (e) { + // a 429 status code indicates that the enrich policy is being executed + if (currentAttempt === attempts || e.statusCode !== 429) { + logger.error( + `Error deleting enrich policy ${name}: ${e.message} after ${currentAttempt} attempts` + ); + throw e; + } + + logger.info( + `Enrich policy ${name} is being executed, waiting for it to finish before deleting` + ); + await new Promise((resolve) => setTimeout(resolve, delayMs)); + currentAttempt++; + } + } }; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/entity_store_data_client.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/entity_store_data_client.ts index ce695f417b045..2cb119e6d37fe 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/entity_store_data_client.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/entity_store/entity_store_data_client.ts @@ -247,7 +247,7 @@ export class EntityStoreDataClient { logger, taskManager, }); - logger.info(`Entity store initialized`); + logger.info(`Entity store initialized for ${entityType}`); return updated; } catch (err) { @@ -364,6 +364,7 @@ export class EntityStoreDataClient { await deleteFieldRetentionEnrichPolicy({ unitedDefinition, esClient: this.esClient, + logger, }); if (deleteData) { @@ -464,7 +465,7 @@ export class EntityStoreDataClient { originalStatus === ENGINE_STATUS.UPDATING ) { throw new Error( - `Error updating entity store: There is an changes already in progress for engine ${id}` + `Error updating entity store: There are changes already in progress for engine ${id}` ); } diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine.ts index 63a1530744440..f51fbd15ceead 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine.ts @@ -14,9 +14,7 @@ export default ({ getService }: FtrProviderContext) => { const supertest = getService('supertest'); const utils = EntityStoreUtils(getService); - - // Failing: See https://github.com/elastic/kibana/issues/196526 - describe.skip('@ess @skipInServerlessMKI Entity Store Engine APIs', () => { + describe('@ess @skipInServerlessMKI Entity Store Engine APIs', () => { const dataView = dataViewRouteHelpersFactory(supertest); before(async () => { @@ -34,22 +32,19 @@ export default ({ getService }: FtrProviderContext) => { }); it('should have installed the expected user resources', async () => { - await utils.initEntityEngineForEntityType('user'); + await utils.initEntityEngineForEntityTypesAndWait(['user']); await utils.expectEngineAssetsExist('user'); }); it('should have installed the expected host resources', async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); await utils.expectEngineAssetsExist('host'); }); }); describe('get and list', () => { before(async () => { - await Promise.all([ - utils.initEntityEngineForEntityType('host'), - utils.initEntityEngineForEntityType('user'), - ]); + await utils.initEntityEngineForEntityTypesAndWait(['host', 'user']); }); after(async () => { @@ -119,7 +114,7 @@ export default ({ getService }: FtrProviderContext) => { describe('start and stop', () => { before(async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); }); after(async () => { @@ -161,7 +156,7 @@ export default ({ getService }: FtrProviderContext) => { describe('delete', () => { it('should delete the host entity engine', async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); await api .deleteEntityEngine({ @@ -174,7 +169,7 @@ export default ({ getService }: FtrProviderContext) => { }); it('should delete the user entity engine', async () => { - await utils.initEntityEngineForEntityType('user'); + await utils.initEntityEngineForEntityTypesAndWait(['user']); await api .deleteEntityEngine({ @@ -189,7 +184,7 @@ export default ({ getService }: FtrProviderContext) => { describe('apply_dataview_indices', () => { before(async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); }); after(async () => { diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine_nondefault_spaces.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine_nondefault_spaces.ts index 481f7aa4056f6..64809533fec7b 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine_nondefault_spaces.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/entity_store/trial_license_complete_tier/engine_nondefault_spaces.ts @@ -18,8 +18,7 @@ export default ({ getService }: FtrProviderContextWithSpaces) => { const supertest = getService('supertest'); const utils = EntityStoreUtils(getService, namespace); - // Failing: See https://github.com/elastic/kibana/issues/196546 - describe.skip('@ess Entity Store Engine APIs in non-default space', () => { + describe('@ess Entity Store Engine APIs in non-default space', () => { const dataView = dataViewRouteHelpersFactory(supertest, namespace); before(async () => { @@ -43,22 +42,19 @@ export default ({ getService }: FtrProviderContextWithSpaces) => { }); it('should have installed the expected user resources', async () => { - await utils.initEntityEngineForEntityType('user'); + await utils.initEntityEngineForEntityTypesAndWait(['user']); await utils.expectEngineAssetsExist('user'); }); it('should have installed the expected host resources', async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); await utils.expectEngineAssetsExist('host'); }); }); describe('get and list', () => { before(async () => { - await Promise.all([ - utils.initEntityEngineForEntityType('host'), - utils.initEntityEngineForEntityType('user'), - ]); + await utils.initEntityEngineForEntityTypesAndWait(['host', 'user']); }); after(async () => { @@ -134,7 +130,7 @@ export default ({ getService }: FtrProviderContextWithSpaces) => { describe('start and stop', () => { before(async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); }); after(async () => { @@ -188,7 +184,7 @@ export default ({ getService }: FtrProviderContextWithSpaces) => { describe('delete', () => { it('should delete the host entity engine', async () => { - await utils.initEntityEngineForEntityType('host'); + await utils.initEntityEngineForEntityTypesAndWait(['host']); await api .deleteEntityEngine( @@ -204,7 +200,7 @@ export default ({ getService }: FtrProviderContextWithSpaces) => { }); it('should delete the user entity engine', async () => { - await utils.initEntityEngineForEntityType('user'); + await utils.initEntityEngineForEntityTypesAndWait(['user']); await api .deleteEntityEngine( diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/elastic_asset_checker.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/elastic_asset_checker.ts index 8e8635cefc26b..c0dddb4ddb093 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/elastic_asset_checker.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/elastic_asset_checker.ts @@ -9,6 +9,8 @@ import { FtrProviderContext } from '@kbn/ftr-common-functional-services'; export const elasticAssetCheckerFactory = (getService: FtrProviderContext['getService']) => { const es = getService('es'); + const retry = getService('retry'); + const log = getService('log'); const expectTransformExists = async (transformId: string) => { return expectTransformStatus(transformId, true); @@ -18,45 +20,43 @@ export const elasticAssetCheckerFactory = (getService: FtrProviderContext['getSe return expectTransformStatus(transformId, false); }; - const expectTransformStatus = async ( - transformId: string, - exists: boolean, - attempts: number = 5, - delayMs: number = 2000 - ) => { - let currentAttempt = 1; - while (currentAttempt <= attempts) { - try { - await es.transform.getTransform({ transform_id: transformId }); - if (!exists) { - throw new Error(`Expected transform ${transformId} to not exist, but it does`); + const expectTransformStatus = async (transformId: string, exists: boolean) => { + await retry.waitForWithTimeout( + `transform ${transformId} to ${exists ? 'exist' : 'not exist'}`, + 10_000, + async () => { + try { + await es.transform.getTransform({ transform_id: transformId }); + return exists; + } catch (e) { + log.debug(`Transform ${transformId} not found: ${e}`); + return !exists; } - return; // Transform exists, exit the loop - } catch (e) { - if (currentAttempt === attempts) { - if (exists) { - throw new Error(`Expected transform ${transformId} to exist, but it does not: ${e}`); - } else { - return; // Transform does not exist, exit the loop - } - } - await new Promise((resolve) => setTimeout(resolve, delayMs)); - currentAttempt++; } - } + ); }; const expectEnrichPolicyStatus = async (policyId: string, exists: boolean) => { - try { - await es.enrich.getPolicy({ name: policyId }); - if (!exists) { - throw new Error(`Expected enrich policy ${policyId} to not exist, but it does`); - } - } catch (e) { - if (exists) { - throw new Error(`Expected enrich policy ${policyId} to exist, but it does not: ${e}`); + await retry.waitForWithTimeout( + `enrich policy ${policyId} to ${exists ? 'exist' : 'not exist'}`, + 20_000, + async () => { + try { + const res = await es.enrich.getPolicy({ name: policyId }); + const policy = res.policies?.[0]; + if (policy) { + log.debug(`Enrich policy ${policyId} found: ${JSON.stringify(res)}`); + return exists; + } else { + log.debug(`Enrich policy ${policyId} not found: ${JSON.stringify(res)}`); + return !exists; + } + } catch (e) { + log.debug(`Enrich policy ${policyId} not found: ${e}`); + return !exists; + } } - } + ); }; const expectEnrichPolicyExists = async (policyId: string) => @@ -66,18 +66,19 @@ export const elasticAssetCheckerFactory = (getService: FtrProviderContext['getSe expectEnrichPolicyStatus(policyId, false); const expectComponentTemplatStatus = async (templateName: string, exists: boolean) => { - try { - await es.cluster.getComponentTemplate({ name: templateName }); - if (!exists) { - throw new Error(`Expected component template ${templateName} to not exist, but it does`); - } - } catch (e) { - if (exists) { - throw new Error( - `Expected component template ${templateName} to exist, but it does not: ${e}` - ); + await retry.waitForWithTimeout( + `component template ${templateName} to ${exists ? 'exist' : 'not exist'}`, + 10_000, + async () => { + try { + await es.cluster.getComponentTemplate({ name: templateName }); + return exists; // Component template exists + } catch (e) { + log.debug(`Component template ${templateName} not found: ${e}`); + return !exists; // Component template does not exist + } } - } + ); }; const expectComponentTemplateExists = async (templateName: string) => @@ -87,23 +88,45 @@ export const elasticAssetCheckerFactory = (getService: FtrProviderContext['getSe expectComponentTemplatStatus(templateName, false); const expectIngestPipelineStatus = async (pipelineId: string, exists: boolean) => { + await retry.waitForWithTimeout( + `ingest pipeline ${pipelineId} to ${exists ? 'exist' : 'not exist'}`, + 10_000, + async () => { + try { + await es.ingest.getPipeline({ id: pipelineId }); + return exists; // Ingest pipeline exists + } catch (e) { + log.debug(`Ingest pipeline ${pipelineId} not found: ${e}`); + return !exists; // Ingest pipeline does not exist + } + } + ); + }; + + const expectIngestPipelineExists = async (pipelineId: string) => + expectIngestPipelineStatus(pipelineId, true); + + const expectIngestPipelineNotFound = async (pipelineId: string) => + expectIngestPipelineStatus(pipelineId, false); + + const expectIndexStatus = async (indexName: string, exists: boolean) => { try { - await es.ingest.getPipeline({ id: pipelineId }); + await es.indices.get({ index: indexName }); if (!exists) { - throw new Error(`Expected ingest pipeline ${pipelineId} to not exist, but it does`); + throw new Error(`Expected index ${indexName} to not exist, but it does`); } } catch (e) { if (exists) { - throw new Error(`Expected ingest pipeline ${pipelineId} to exist, but it does not: ${e}`); + throw new Error(`Expected index ${indexName} to exist, but it does not: ${e}`); } } }; - const expectIngestPipelineExists = async (pipelineId: string) => - expectIngestPipelineStatus(pipelineId, true); + const expectEntitiesIndexExists = async (entityType: string, namespace: string) => + expectIndexStatus(`.entities.v1.latest.security_${entityType}_${namespace}`, true); - const expectIngestPipelineNotFound = async (pipelineId: string) => - expectIngestPipelineStatus(pipelineId, false); + const expectEntitiesIndexNotFound = async (entityType: string, namespace: string) => + expectIndexStatus(`.entities.v1.latest.security_${entityType}_${namespace}`, false); return { expectComponentTemplateExists, @@ -112,6 +135,8 @@ export const elasticAssetCheckerFactory = (getService: FtrProviderContext['getSe expectEnrichPolicyNotFound, expectIngestPipelineExists, expectIngestPipelineNotFound, + expectEntitiesIndexExists, + expectEntitiesIndexNotFound, expectTransformExists, expectTransformNotFound, }; diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/entity_store.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/entity_store.ts index 24c1434b5e4a5..029103425af68 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/entity_store.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/entity_store.ts @@ -17,6 +17,7 @@ export const EntityStoreUtils = ( const api = getService('securitySolutionApi'); const es = getService('es'); const log = getService('log'); + const retry = getService('retry'); const { expectTransformExists, expectTransformNotFound, @@ -26,6 +27,8 @@ export const EntityStoreUtils = ( expectComponentTemplateNotFound, expectIngestPipelineExists, expectIngestPipelineNotFound, + expectEntitiesIndexExists, + expectEntitiesIndexNotFound, } = elasticAssetCheckerFactory(getService); log.debug(`EntityStoreUtils namespace: ${namespace}`); @@ -48,7 +51,7 @@ export const EntityStoreUtils = ( } }; - const initEntityEngineForEntityType = async (entityType: EntityType) => { + const _initEntityEngineForEntityType = async (entityType: EntityType) => { log.info( `Initializing engine for entity type ${entityType} in namespace ${namespace || 'default'}` ); @@ -68,6 +71,22 @@ export const EntityStoreUtils = ( expect(res.status).to.eql(200); }; + const initEntityEngineForEntityTypesAndWait = async (entityTypes: EntityType[]) => { + await Promise.all(entityTypes.map((entityType) => _initEntityEngineForEntityType(entityType))); + + await retry.waitForWithTimeout( + `Engines to start for entity types: ${entityTypes.join(', ')}`, + 60_000, + async () => { + const { body } = await api.listEntityEngines(namespace).expect(200); + if (body.engines.every((engine: any) => engine.status === 'started')) { + return true; + } + return false; + } + ); + }; + const expectTransformStatus = async ( transformId: string, exists: boolean, @@ -98,21 +117,27 @@ export const EntityStoreUtils = ( const expectEngineAssetsExist = async (entityType: EntityType) => { await expectTransformExists(`entities-v1-latest-security_${entityType}_${namespace}`); - await expectEnrichPolicyExists(`entity_store_field_retention_${entityType}_${namespace}_v1`); + await expectEnrichPolicyExists( + `entity_store_field_retention_${entityType}_${namespace}_v1.0.0` + ); await expectComponentTemplateExists(`security_${entityType}_${namespace}-latest@platform`); await expectIngestPipelineExists(`security_${entityType}_${namespace}-latest@platform`); + await expectEntitiesIndexExists(entityType, namespace); }; const expectEngineAssetsDoNotExist = async (entityType: EntityType) => { await expectTransformNotFound(`entities-v1-latest-security_${entityType}_${namespace}`); - await expectEnrichPolicyNotFound(`entity_store_field_retention_${entityType}_${namespace}_v1`); + await expectEnrichPolicyNotFound( + `entity_store_field_retention_${entityType}_${namespace}_v1.0.0` + ); await expectComponentTemplateNotFound(`security_${entityType}_${namespace}-latest@platform`); await expectIngestPipelineNotFound(`security_${entityType}_${namespace}-latest@platform`); + await expectEntitiesIndexNotFound(entityType, namespace); }; return { cleanEngines, - initEntityEngineForEntityType, + initEntityEngineForEntityTypesAndWait, expectTransformStatus, expectEngineAssetsExist, expectEngineAssetsDoNotExist, From b3b8a3ed74593f811f8688820d2585d30d2a8d03 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 23 Oct 2024 14:46:43 +0200 Subject: [PATCH 29/33] [8.x] [OAS] Support setting availability (#196647) (#197394) # Backport This will backport the following commits from `main` to `8.x`: - [[OAS] Support setting availability (#196647)](https://github.com/elastic/kibana/pull/196647) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) \n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by: Jean-Louis Leysens "}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --- .../src/router.test.ts | 8 ++ .../core_versioned_route.test.ts | 43 +++++++- .../http/core-http-server/src/router/route.ts | 17 ++++ .../core-http-server/src/versioning/types.ts | 2 +- .../openapi-types.d.ts | 2 +- .../src/generate_oas.test.ts | 99 +++++++++++++++++++ .../src/process_router.ts | 6 +- .../src/process_versioned_router.ts | 4 + .../kbn-router-to-openapispec/src/type.ts | 5 + .../kbn-router-to-openapispec/src/util.ts | 16 ++- 10 files changed, 197 insertions(+), 5 deletions(-) diff --git a/packages/core/http/core-http-router-server-internal/src/router.test.ts b/packages/core/http/core-http-router-server-internal/src/router.test.ts index c318e9312546a..f611e3b6308fe 100644 --- a/packages/core/http/core-http-router-server-internal/src/router.test.ts +++ b/packages/core/http/core-http-router-server-internal/src/router.test.ts @@ -54,6 +54,10 @@ describe('Router', () => { discontinued: 'post test discontinued', summary: 'post test summary', description: 'post test description', + availability: { + since: '1.0.0', + stability: 'experimental', + }, }, }, (context, req, res) => res.ok() @@ -72,6 +76,10 @@ describe('Router', () => { discontinued: 'post test discontinued', summary: 'post test summary', description: 'post test description', + availability: { + since: '1.0.0', + stability: 'experimental', + }, }, }); }); diff --git a/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.test.ts b/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.test.ts index 3938b8addfc25..1442467012d8b 100644 --- a/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.test.ts +++ b/packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.test.ts @@ -52,6 +52,46 @@ describe('Versioned route', () => { jest.clearAllMocks(); }); + describe('#getRoutes', () => { + it('returns the expected metadata', () => { + const versionedRouter = CoreVersionedRouter.from({ router }); + versionedRouter + .get({ + path: '/test/{id}', + access: 'public', + options: { + httpResource: true, + availability: { + since: '1.0.0', + stability: 'experimental', + }, + excludeFromOAS: true, + tags: ['1', '2', '3'], + }, + description: 'test', + summary: 'test', + enableQueryVersion: false, + }) + .addVersion({ version: '2023-10-31', validate: false }, handlerFn); + + expect(versionedRouter.getRoutes()[0].options).toMatchObject({ + access: 'public', + enableQueryVersion: false, + description: 'test', + summary: 'test', + options: { + httpResource: true, + availability: { + since: '1.0.0', + stability: 'experimental', + }, + excludeFromOAS: true, + tags: ['1', '2', '3'], + }, + }); + }); + }); + it('can register multiple handlers', () => { const versionedRouter = CoreVersionedRouter.from({ router }); versionedRouter @@ -133,6 +173,8 @@ describe('Versioned route', () => { const opts: Parameters[0] = { path: '/test/{id}', access: 'internal', + summary: 'test', + description: 'test', options: { authRequired: true, tags: ['access:test'], @@ -140,7 +182,6 @@ describe('Versioned route', () => { xsrfRequired: false, excludeFromOAS: true, httpResource: true, - summary: `test`, }, }; diff --git a/packages/core/http/core-http-server/src/router/route.ts b/packages/core/http/core-http-server/src/router/route.ts index f7bde57ff6c51..635c67f4b3d18 100644 --- a/packages/core/http/core-http-server/src/router/route.ts +++ b/packages/core/http/core-http-server/src/router/route.ts @@ -329,6 +329,23 @@ export interface RouteConfigOptions { * @default false */ httpResource?: boolean; + + /** + * Based on the the ES API specification (see https://github.com/elastic/elasticsearch-specification) + * Kibana APIs can also specify some metadata about API availability. + * + * This setting is only applicable if your route `access` is `public`. + * + * @remark intended to be used for informational purposes only. + */ + availability?: { + /** @default stable */ + stability?: 'experimental' | 'beta' | 'stable'; + /** + * The stack version in which the route was introduced (eg: 8.15.0). + */ + since?: string; + }; } /** diff --git a/packages/core/http/core-http-server/src/versioning/types.ts b/packages/core/http/core-http-server/src/versioning/types.ts index 60cbca014e683..7998c9cc91fa9 100644 --- a/packages/core/http/core-http-server/src/versioning/types.ts +++ b/packages/core/http/core-http-server/src/versioning/types.ts @@ -35,7 +35,7 @@ export type VersionedRouteConfig = Omit< > & { options?: Omit< RouteConfigOptions, - 'access' | 'description' | 'deprecated' | 'discontinued' | 'security' + 'access' | 'description' | 'summary' | 'deprecated' | 'discontinued' | 'security' >; /** See {@link RouteConfigOptions['access']} */ access: Exclude['access'], undefined>; diff --git a/packages/kbn-router-to-openapispec/openapi-types.d.ts b/packages/kbn-router-to-openapispec/openapi-types.d.ts index 90c034a855fdc..9689ed803a152 100644 --- a/packages/kbn-router-to-openapispec/openapi-types.d.ts +++ b/packages/kbn-router-to-openapispec/openapi-types.d.ts @@ -13,7 +13,7 @@ export * from 'openapi-types'; declare module 'openapi-types' { export namespace OpenAPIV3 { export interface BaseSchemaObject { - // Custom OpenAPI field added by Kibana for a new field at the shema level. + // Custom OpenAPI field added by Kibana for a new field at the schema level. 'x-discontinued'?: string; } } diff --git a/packages/kbn-router-to-openapispec/src/generate_oas.test.ts b/packages/kbn-router-to-openapispec/src/generate_oas.test.ts index 6db4237751217..c3532312d3088 100644 --- a/packages/kbn-router-to-openapispec/src/generate_oas.test.ts +++ b/packages/kbn-router-to-openapispec/src/generate_oas.test.ts @@ -321,4 +321,103 @@ describe('generateOpenApiDocument', () => { expect(result.paths['/v2-1']!.get!.tags).toEqual([]); }); }); + + describe('availability', () => { + it('creates the expected availability entries', () => { + const [routers, versionedRouters] = createTestRouters({ + routers: { + testRouter1: { + routes: [ + { + path: '/1-1/{id}/{path*}', + options: { availability: { stability: 'experimental' } }, + }, + { + path: '/1-2/{id}/{path*}', + options: { availability: { stability: 'beta' } }, + }, + { + path: '/1-3/{id}/{path*}', + options: { availability: { stability: 'stable' } }, + }, + ], + }, + testRouter2: { + routes: [{ path: '/2-1/{id}/{path*}' }], + }, + }, + versionedRouters: { + testVersionedRouter1: { + routes: [ + { + path: '/v1-1', + options: { + access: 'public', + options: { availability: { stability: 'experimental' } }, + }, + }, + { + path: '/v1-2', + options: { + access: 'public', + options: { availability: { stability: 'beta' } }, + }, + }, + { + path: '/v1-3', + options: { + access: 'public', + options: { availability: { stability: 'stable' } }, + }, + }, + ], + }, + testVersionedRouter2: { + routes: [{ path: '/v2-1', options: { access: 'public' } }], + }, + }, + }); + const result = generateOpenApiDocument( + { + routers, + versionedRouters, + }, + { + title: 'test', + baseUrl: 'https://test.oas', + version: '99.99.99', + } + ); + + // router paths + expect(result.paths['/1-1/{id}/{path*}']!.get).toMatchObject({ + 'x-state': 'Technical Preview', + }); + expect(result.paths['/1-2/{id}/{path*}']!.get).toMatchObject({ + 'x-state': 'Beta', + }); + + expect(result.paths['/1-3/{id}/{path*}']!.get).not.toMatchObject({ + 'x-state': expect.any(String), + }); + expect(result.paths['/2-1/{id}/{path*}']!.get).not.toMatchObject({ + 'x-state': expect.any(String), + }); + + // versioned router paths + expect(result.paths['/v1-1']!.get).toMatchObject({ + 'x-state': 'Technical Preview', + }); + expect(result.paths['/v1-2']!.get).toMatchObject({ + 'x-state': 'Beta', + }); + + expect(result.paths['/v1-3']!.get).not.toMatchObject({ + 'x-state': expect.any(String), + }); + expect(result.paths['/v2-1']!.get).not.toMatchObject({ + 'x-state': expect.any(String), + }); + }); + }); }); diff --git a/packages/kbn-router-to-openapispec/src/process_router.ts b/packages/kbn-router-to-openapispec/src/process_router.ts index 4437e35ea1f3e..1884b6dddf863 100644 --- a/packages/kbn-router-to-openapispec/src/process_router.ts +++ b/packages/kbn-router-to-openapispec/src/process_router.ts @@ -23,9 +23,11 @@ import { getVersionedHeaderParam, mergeResponseContent, prepareRoutes, + setXState, } from './util'; import type { OperationIdCounter } from './operation_id_counter'; import type { GenerateOpenApiDocumentOptionsFilters } from './generate_oas'; +import type { CustomOperationObject } from './type'; export const processRouter = ( appRouter: Router, @@ -61,7 +63,7 @@ export const processRouter = ( parameters.push(...pathObjects, ...queryObjects); } - const operation: OpenAPIV3.OperationObject = { + const operation: CustomOperationObject = { summary: route.options.summary ?? '', tags: route.options.tags ? extractTags(route.options.tags) : [], ...(route.options.description ? { description: route.options.description } : {}), @@ -81,6 +83,8 @@ export const processRouter = ( operationId: getOpId(route.path), }; + setXState(route.options.availability, operation); + const path: OpenAPIV3.PathItemObject = { [route.method]: operation, }; diff --git a/packages/kbn-router-to-openapispec/src/process_versioned_router.ts b/packages/kbn-router-to-openapispec/src/process_versioned_router.ts index 97b92f92fde57..5446f1409760d 100644 --- a/packages/kbn-router-to-openapispec/src/process_versioned_router.ts +++ b/packages/kbn-router-to-openapispec/src/process_versioned_router.ts @@ -29,6 +29,7 @@ import { extractTags, mergeResponseContent, getXsrfHeaderForMethod, + setXState, } from './util'; export const processVersionedRouter = ( @@ -112,6 +113,9 @@ export const processVersionedRouter = ( parameters, operationId: getOpId(route.path), }; + + setXState(route.options.options?.availability, operation); + const path: OpenAPIV3.PathItemObject = { [route.method]: operation, }; diff --git a/packages/kbn-router-to-openapispec/src/type.ts b/packages/kbn-router-to-openapispec/src/type.ts index 09dc247e5a5c9..5c5f992a0de0f 100644 --- a/packages/kbn-router-to-openapispec/src/type.ts +++ b/packages/kbn-router-to-openapispec/src/type.ts @@ -34,3 +34,8 @@ export interface OpenAPIConverter { is(type: unknown): boolean; } + +export type CustomOperationObject = OpenAPIV3.OperationObject<{ + // Custom OpenAPI from ES API spec based on @availability + 'x-state'?: 'Technical Preview' | 'Beta'; +}>; diff --git a/packages/kbn-router-to-openapispec/src/util.ts b/packages/kbn-router-to-openapispec/src/util.ts index 55f7348dc199a..beefbebc0aec7 100644 --- a/packages/kbn-router-to-openapispec/src/util.ts +++ b/packages/kbn-router-to-openapispec/src/util.ts @@ -17,7 +17,7 @@ import { type RouterRoute, type RouteValidatorConfig, } from '@kbn/core-http-server'; -import { KnownParameters } from './type'; +import { CustomOperationObject, KnownParameters } from './type'; import type { GenerateOpenApiDocumentOptionsFilters } from './generate_oas'; const tagPrefix = 'oas-tag:'; @@ -165,3 +165,17 @@ export const getXsrfHeaderForMethod = ( }, ]; }; + +export function setXState( + availability: RouteConfigOptions['availability'], + operation: CustomOperationObject +): void { + if (availability) { + if (availability.stability === 'experimental') { + operation['x-state'] = 'Technical Preview'; + } + if (availability.stability === 'beta') { + operation['x-state'] = 'Beta'; + } + } +} From e083f4089b6a791a4025f900676cb5ec9480e909 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 23 Oct 2024 23:49:31 +1100 Subject: [PATCH 30/33] [8.x] Render 'preview' instead of chat on Search mode (#197236) (#197406) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [Render 'preview' instead of chat on Search mode (#197236)](https://github.com/elastic/kibana/pull/197236) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Efe Gürkan YALAMAN --- .../public/components/header.test.tsx | 96 +++++++++++++++++++ .../public/components/header.tsx | 11 ++- 2 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 x-pack/plugins/search_playground/public/components/header.test.tsx diff --git a/x-pack/plugins/search_playground/public/components/header.test.tsx b/x-pack/plugins/search_playground/public/components/header.test.tsx new file mode 100644 index 0000000000000..be80e2925a853 --- /dev/null +++ b/x-pack/plugins/search_playground/public/components/header.test.tsx @@ -0,0 +1,96 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +// create @testing-library/react tests for Header component +// check if EuiButtonGroup is differently labeled based on the selectedPageMode prop + +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import { Header } from './header'; +import { ChatFormFields, PlaygroundPageMode } from '../types'; +import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; +import { EuiForm } from '@elastic/eui'; +import { FormProvider, useForm } from 'react-hook-form'; + +const MockFormProvider = ({ children }: { children: React.ReactElement }) => { + const methods = useForm({ + values: { + [ChatFormFields.indices]: ['index1', 'index2'], + [ChatFormFields.queryFields]: { index1: ['field1'], index2: ['field1'] }, + [ChatFormFields.sourceFields]: { + index1: ['field1'], + index2: ['field1'], + }, + [ChatFormFields.elasticsearchQuery]: { + retriever: { + rrf: { + retrievers: [ + { standard: { query: { multi_match: { query: '{query}', fields: ['field1'] } } } }, + { standard: { query: { multi_match: { query: '{query}', fields: ['field1'] } } } }, + ], + }, + }, + }, + }, + }); + return {children}; +}; +const MockChatForm = ({ + children, + handleSubmit, +}: { + children: React.ReactElement; + handleSubmit: React.FormEventHandler; +}) => ( + + + {children} + + +); + +describe('Header', () => { + it('renders correctly', () => { + render( + + {}}> +
{}} + selectedPageMode={PlaygroundPageMode.chat} + onSelectPageModeChange={() => {}} + /> + + + ); + + expect(screen.getByTestId('chatMode')).toHaveTextContent('Chat'); + expect(screen.getByTestId('queryMode')).toHaveTextContent('Query'); + }); + + it('renders correctly with preview mode', () => { + render( + + {}}> +
{}} + selectedPageMode={PlaygroundPageMode.search} + onSelectPageModeChange={() => {}} + /> + + + ); + + expect(screen.getByTestId('chatMode')).toHaveTextContent('Preview'); + expect(screen.getByTestId('queryMode')).toHaveTextContent('Query'); + }); +}); diff --git a/x-pack/plugins/search_playground/public/components/header.tsx b/x-pack/plugins/search_playground/public/components/header.tsx index 0d6d48a903462..bc3b310d8c41f 100644 --- a/x-pack/plugins/search_playground/public/components/header.tsx +++ b/x-pack/plugins/search_playground/public/components/header.tsx @@ -46,9 +46,14 @@ export const Header: React.FC = ({ const options = [ { id: ViewMode.chat, - label: i18n.translate('xpack.searchPlayground.header.view.chat', { - defaultMessage: 'Chat', - }), + label: + selectedPageMode === PlaygroundPageMode.chat + ? i18n.translate('xpack.searchPlayground.header.view.chat', { + defaultMessage: 'Chat', + }) + : i18n.translate('xpack.searchPlayground.header.view.preview', { + defaultMessage: 'Preview', + }), 'data-test-subj': 'chatMode', }, { From ce8ef51a59762055f78ea602e26804e3fc6834ca Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 24 Oct 2024 00:18:35 +1100 Subject: [PATCH 31/33] [8.x] [Synthetics] Show rules created in Obs Rules page !! (#197215) (#197411) # Backport This will backport the following commits from `main` to `8.x`: - [[Synthetics] Show rules created in Obs Rules page !! (#197215)](https://github.com/elastic/kibana/pull/197215) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Shahzad --- .../src/rule_types/o11y_rules.ts | 3 + .../observability/server/plugin.ts | 4 + .../platform_security/authorization.ts | 920 ++++++++++++++++++ 3 files changed, 927 insertions(+) diff --git a/packages/kbn-rule-data-utils/src/rule_types/o11y_rules.ts b/packages/kbn-rule-data-utils/src/rule_types/o11y_rules.ts index 8743052e84664..5dae1c99b210f 100644 --- a/packages/kbn-rule-data-utils/src/rule_types/o11y_rules.ts +++ b/packages/kbn-rule-data-utils/src/rule_types/o11y_rules.ts @@ -20,3 +20,6 @@ export enum ApmRuleType { TransactionDuration = 'apm.transaction_duration', Anomaly = 'apm.anomaly', } + +export const SYNTHETICS_STATUS_RULE = 'xpack.synthetics.alerts.monitorStatus'; +export const SYNTHETICS_TLS_RULE = 'xpack.synthetics.alerts.tls'; diff --git a/x-pack/plugins/observability_solution/observability/server/plugin.ts b/x-pack/plugins/observability_solution/observability/server/plugin.ts index 6bc21bf5dddf2..7f9a37a5a26c4 100644 --- a/x-pack/plugins/observability_solution/observability/server/plugin.ts +++ b/x-pack/plugins/observability_solution/observability/server/plugin.ts @@ -31,6 +31,8 @@ import { METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, OBSERVABILITY_THRESHOLD_RULE_TYPE_ID, SLO_BURN_RATE_RULE_TYPE_ID, + SYNTHETICS_STATUS_RULE, + SYNTHETICS_TLS_RULE, } from '@kbn/rule-data-utils'; import { RuleRegistryPluginSetupContract } from '@kbn/rule-registry-plugin/server'; import { SharePluginSetup } from '@kbn/share-plugin/server'; @@ -83,6 +85,8 @@ const o11yRuleTypes = [ ML_ANOMALY_DETECTION_RULE_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, ...Object.values(ApmRuleType), + SYNTHETICS_STATUS_RULE, + SYNTHETICS_TLS_RULE, ]; export class ObservabilityPlugin implements Plugin { diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/platform_security/authorization.ts b/x-pack/test_serverless/api_integration/test_suites/observability/platform_security/authorization.ts index 885a34572c1f3..d4cca44448676 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/platform_security/authorization.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/platform_security/authorization.ts @@ -655,6 +655,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -700,6 +756,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_all": Array [ "login:", @@ -1307,6 +1373,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -1352,6 +1474,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_read": Array [ "login:", @@ -1601,6 +1733,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -1637,6 +1787,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "read": Array [ "login:", @@ -1886,6 +2044,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -1922,6 +2098,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "settings_save": Array [ "login:", @@ -2851,6 +3035,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -2896,6 +3136,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "generate_report": Array [ "login:", @@ -3228,6 +3478,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -3273,6 +3579,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_read": Array [ "login:", @@ -3403,6 +3719,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -3439,6 +3773,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "read": Array [ "login:", @@ -3577,6 +3919,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -3613,6 +3973,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "store_search_session": Array [ "login:", @@ -5333,6 +5701,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -5378,6 +5802,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_all": Array [ "login:", @@ -6026,6 +6460,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -6071,6 +6561,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_read": Array [ "login:", @@ -6335,6 +6835,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -6371,6 +6889,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "read": Array [ "login:", @@ -6635,6 +7161,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -6671,6 +7215,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], }, "reporting": Object { @@ -7145,6 +7697,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -7190,6 +7798,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_all": Array [ "login:", @@ -7544,6 +8162,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -7589,6 +8263,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_read": Array [ "login:", @@ -7728,6 +8412,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -7764,6 +8466,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "read": Array [ "login:", @@ -7903,6 +8613,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -7939,6 +8667,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], }, "uptime": Object { @@ -8515,6 +9251,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -8560,6 +9352,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "elastic_managed_locations_enabled": Array [ "login:", @@ -9137,6 +9939,62 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/runSoon", "alerting:apm.anomaly/observability/rule/scheduleBackfill", "alerting:apm.anomaly/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/create", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/delete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/enable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/disable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/deleteBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/create", + "alerting:xpack.synthetics.alerts.tls/observability/rule/delete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/update", + "alerting:xpack.synthetics.alerts.tls/observability/rule/updateApiKey", + "alerting:xpack.synthetics.alerts.tls/observability/rule/enable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/disable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAll", + "alerting:xpack.synthetics.alerts.tls/observability/rule/muteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unmuteAlert", + "alerting:xpack.synthetics.alerts.tls/observability/rule/snooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEdit", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDelete", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkEnable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/bulkDisable", + "alerting:xpack.synthetics.alerts.tls/observability/rule/unsnooze", + "alerting:xpack.synthetics.alerts.tls/observability/rule/runSoon", + "alerting:xpack.synthetics.alerts.tls/observability/rule/scheduleBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/deleteBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -9182,6 +10040,16 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", "alerting:apm.anomaly/observability/alert/update", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/update", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/update", ], "minimal_read": Array [ "login:", @@ -9411,6 +10279,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -9447,6 +10333,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], "read": Array [ "login:", @@ -9676,6 +10570,24 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/rule/getRuleExecutionKPI", "alerting:apm.anomaly/observability/rule/getBackfill", "alerting:apm.anomaly/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/rule/findBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/get", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleState", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getExecutionLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getActionErrorLog", + "alerting:xpack.synthetics.alerts.tls/observability/rule/find", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getRuleExecutionKPI", + "alerting:xpack.synthetics.alerts.tls/observability/rule/getBackfill", + "alerting:xpack.synthetics.alerts.tls/observability/rule/findBackfill", "alerting:slo.rules.burnRate/observability/alert/get", "alerting:slo.rules.burnRate/observability/alert/find", "alerting:slo.rules.burnRate/observability/alert/getAuthorizedAlertsIndices", @@ -9712,6 +10624,14 @@ export default function ({ getService }: FtrProviderContext) { "alerting:apm.anomaly/observability/alert/find", "alerting:apm.anomaly/observability/alert/getAuthorizedAlertsIndices", "alerting:apm.anomaly/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/get", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/find", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.monitorStatus/observability/alert/getAlertSummary", + "alerting:xpack.synthetics.alerts.tls/observability/alert/get", + "alerting:xpack.synthetics.alerts.tls/observability/alert/find", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAuthorizedAlertsIndices", + "alerting:xpack.synthetics.alerts.tls/observability/alert/getAlertSummary", ], }, } From 0bd80e508aa7d5c9b8b1ca6f163c645f933c9e80 Mon Sep 17 00:00:00 2001 From: Ash <1849116+ashokaditya@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:49:56 +0200 Subject: [PATCH 32/33] [8.x] [DataUsage][Serverless] Data usage charts enhancements (#196559) (#196996) # Backport This will backport the following commits from `main` to `8.x`: - [[DataUsage][Serverless] Data usage charts enhancements (#196559)](https://github.com/elastic/kibana/pull/196559) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) \n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by: Ash <1849116+ashokaditya@users.noreply.github.com>"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --- .../public/app/components/chart_panel.tsx | 7 +- .../app/components/data_usage_metrics.tsx | 76 ++++++++---- .../app/components/filters/charts_filter.tsx | 114 ++++++++---------- .../app/components/filters/charts_filters.tsx | 25 ++-- .../components/filters/clear_all_button.tsx | 43 ------- .../public/app/hooks/use_charts_filter.tsx | 46 +++---- .../app/hooks/use_charts_url_params.tsx | 4 +- .../data_usage/public/app/translations.tsx | 3 - .../public/hooks/use_get_data_streams.ts | 17 +-- .../public/hooks/use_get_usage_metrics.ts | 3 +- .../data_usage/public/utils/format_bytes.ts | 12 ++ .../routes/internal/data_streams_handler.ts | 2 +- .../routes/internal/usage_metrics_handler.ts | 2 + x-pack/plugins/data_usage/tsconfig.json | 1 - 14 files changed, 160 insertions(+), 195 deletions(-) delete mode 100644 x-pack/plugins/data_usage/public/app/components/filters/clear_all_button.tsx create mode 100644 x-pack/plugins/data_usage/public/utils/format_bytes.ts diff --git a/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx b/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx index 1ba3f0fe3f454..7554716c59492 100644 --- a/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx +++ b/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx @@ -5,7 +5,7 @@ * 2.0. */ import React, { useCallback, useMemo } from 'react'; -import numeral from '@elastic/numeral'; + import { EuiFlexItem, EuiPanel, EuiTitle, useEuiTheme } from '@elastic/eui'; import { Chart, @@ -20,6 +20,7 @@ import { import { i18n } from '@kbn/i18n'; import { LegendAction } from './legend_action'; import { MetricTypes, MetricSeries } from '../../../common/rest_types'; +import { formatBytes } from '../../utils/format_bytes'; // TODO: Remove this when we have a title for each metric type type ChartKey = Extract; @@ -118,7 +119,3 @@ export const ChartPanel: React.FC = ({ ); }; - -const formatBytes = (bytes: number) => { - return numeral(bytes).format('0.0 b'); -}; diff --git a/x-pack/plugins/data_usage/public/app/components/data_usage_metrics.tsx b/x-pack/plugins/data_usage/public/app/components/data_usage_metrics.tsx index cc443c78562ee..48b6566df9e66 100644 --- a/x-pack/plugins/data_usage/public/app/components/data_usage_metrics.tsx +++ b/x-pack/plugins/data_usage/public/app/components/data_usage_metrics.tsx @@ -5,9 +5,9 @@ * 2.0. */ -import React, { useCallback, useEffect, memo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { css } from '@emotion/react'; -import { EuiFlexGroup, EuiFlexItem, EuiLoadingElastic, EuiCallOut } from '@elastic/eui'; +import { EuiFlexGroup, EuiFlexItem, EuiLoadingElastic } from '@elastic/eui'; import { Charts } from './charts'; import { useBreadcrumbs } from '../../utils/use_breadcrumbs'; import { useKibanaContextForPlugin } from '../../utils/use_kibana'; @@ -16,21 +16,22 @@ import { useGetDataUsageMetrics } from '../../hooks/use_get_usage_metrics'; import { useDataUsageMetricsUrlParams } from '../hooks/use_charts_url_params'; import { DEFAULT_DATE_RANGE_OPTIONS, useDateRangePicker } from '../hooks/use_date_picker'; import { DEFAULT_METRIC_TYPES, UsageMetricsRequestBody } from '../../../common/rest_types'; -import { ChartFilters } from './filters/charts_filters'; -import { UX_LABELS } from '../translations'; +import { ChartFilters, ChartFiltersProps } from './filters/charts_filters'; +import { useGetDataUsageDataStreams } from '../../hooks/use_get_data_streams'; const EuiItemCss = css` width: 100%; `; -const FlexItemWithCss = memo(({ children }: { children: React.ReactNode }) => ( +const FlexItemWithCss = ({ children }: { children: React.ReactNode }) => ( {children} -)); +); export const DataUsageMetrics = () => { const { services: { chrome, appParams }, } = useKibanaContextForPlugin(); + useBreadcrumbs([{ text: PLUGIN_NAME }], appParams, chrome); const { metricTypes: metricTypesFromUrl, @@ -38,9 +39,17 @@ export const DataUsageMetrics = () => { startDate: startDateFromUrl, endDate: endDateFromUrl, setUrlMetricTypesFilter, + setUrlDataStreamsFilter, setUrlDateRangeFilter, } = useDataUsageMetricsUrlParams(); + const { data: dataStreams, isFetching: isFetchingDataStreams } = useGetDataUsageDataStreams({ + selectedDataStreams: dataStreamsFromUrl, + options: { + enabled: true, + }, + }); + const [metricsFilters, setMetricsFilters] = useState({ metricTypes: [...DEFAULT_METRIC_TYPES], dataStreams: [], @@ -52,15 +61,22 @@ export const DataUsageMetrics = () => { if (!metricTypesFromUrl) { setUrlMetricTypesFilter(metricsFilters.metricTypes.join(',')); } + if (!dataStreamsFromUrl && dataStreams) { + setUrlDataStreamsFilter(dataStreams.map((ds) => ds.name).join(',')); + } if (!startDateFromUrl || !endDateFromUrl) { setUrlDateRangeFilter({ startDate: metricsFilters.from, endDate: metricsFilters.to }); } }, [ + dataStreams, + dataStreamsFromUrl, endDateFromUrl, metricTypesFromUrl, + metricsFilters.dataStreams, metricsFilters.from, metricsFilters.metricTypes, metricsFilters.to, + setUrlDataStreamsFilter, setUrlDateRangeFilter, setUrlMetricTypesFilter, startDateFromUrl, @@ -77,7 +93,6 @@ export const DataUsageMetrics = () => { const { dateRangePickerState, onRefreshChange, onTimeChange } = useDateRangePicker(); const { - error, data, isFetching, isFetched, @@ -90,6 +105,7 @@ export const DataUsageMetrics = () => { }, { retry: false, + enabled: !!metricsFilters.dataStreams.length, } ); @@ -111,33 +127,51 @@ export const DataUsageMetrics = () => { [setMetricsFilters] ); - useBreadcrumbs([{ text: PLUGIN_NAME }], appParams, chrome); + const filterOptions: ChartFiltersProps['filterOptions'] = useMemo(() => { + const dataStreamsOptions = dataStreams?.reduce>((acc, ds) => { + acc[ds.name] = ds.storageSizeBytes; + return acc; + }, {}); + + return { + dataStreams: { + filterName: 'dataStreams', + options: dataStreamsOptions ? Object.keys(dataStreamsOptions) : metricsFilters.dataStreams, + appendOptions: dataStreamsOptions, + selectedOptions: metricsFilters.dataStreams, + onChangeFilterOptions: onChangeDataStreamsFilter, + isFilterLoading: isFetchingDataStreams, + }, + metricTypes: { + filterName: 'metricTypes', + options: metricsFilters.metricTypes, + onChangeFilterOptions: onChangeMetricTypesFilter, + }, + }; + }, [ + dataStreams, + isFetchingDataStreams, + metricsFilters.dataStreams, + metricsFilters.metricTypes, + onChangeDataStreamsFilter, + onChangeMetricTypesFilter, + ]); return ( - {!isFetching && error?.message && ( - - - - )} + {isFetched && data?.metrics ? ( diff --git a/x-pack/plugins/data_usage/public/app/components/filters/charts_filter.tsx b/x-pack/plugins/data_usage/public/app/components/filters/charts_filter.tsx index 466bc6debae77..83d417565f012 100644 --- a/x-pack/plugins/data_usage/public/app/components/filters/charts_filter.tsx +++ b/x-pack/plugins/data_usage/public/app/components/filters/charts_filter.tsx @@ -7,7 +7,7 @@ import { orderBy } from 'lodash/fp'; import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { EuiFlexGroup, EuiFlexItem, EuiPopoverTitle, EuiSelectable } from '@elastic/eui'; +import { EuiPopoverTitle, EuiSelectable } from '@elastic/eui'; import { useTestIdGenerator } from '../../../hooks/use_test_id_generator'; import { @@ -15,7 +15,6 @@ import { type MetricTypes, } from '../../../../common/rest_types'; -import { ClearAllButton } from './clear_all_button'; import { UX_LABELS } from '../../translations'; import { ChartsFilterPopover } from './charts_filter_popover'; import { FilterItems, FilterName, useChartsFilter } from '../../hooks'; @@ -27,20 +26,34 @@ const getSearchPlaceholder = (filterName: FilterName) => { return UX_LABELS.filterSearchPlaceholder('metric types'); }; -export const ChartsFilter = memo( +export interface ChartsFilterProps { + filterOptions: { + filterName: FilterName; + options: string[]; + appendOptions?: Record; + selectedOptions?: string[]; + onChangeFilterOptions: (selectedOptions: string[]) => void; + isFilterLoading?: boolean; + }; + 'data-test-subj'?: string; +} + +export const ChartsFilter = memo( ({ - filterName, - onChangeFilterOptions, + filterOptions: { + filterName, + options, + appendOptions, + selectedOptions, + onChangeFilterOptions, + isFilterLoading = false, + }, 'data-test-subj': dataTestSubj, - }: { - filterName: FilterName; - onChangeFilterOptions?: (selectedOptions: string[]) => void; - 'data-test-subj'?: string; }) => { const getTestId = useTestIdGenerator(dataTestSubj); - const isMetricsFilter = filterName === 'metricTypes'; const isDataStreamsFilter = filterName === 'dataStreams'; + // popover states and handlers const [isPopoverOpen, setIsPopoverOpen] = useState(false); const onPopoverButtonClick = useCallback(() => { @@ -50,11 +63,8 @@ export const ChartsFilter = memo( setIsPopoverOpen(false); }, [setIsPopoverOpen]); - // search string state - const [searchString, setSearchString] = useState(''); const { areDataStreamsSelectedOnMount, - isLoading, items, setItems, hasActiveFilters, @@ -64,17 +74,18 @@ export const ChartsFilter = memo( setUrlDataStreamsFilter, setUrlMetricTypesFilter, } = useChartsFilter({ - filterName, - searchString, + filterOptions: { + filterName, + options, + appendOptions, + selectedOptions, + onChangeFilterOptions, + isFilterLoading, + }, }); // track popover state to pin selected options const wasPopoverOpen = useRef(isPopoverOpen); - useEffect(() => { - return () => { - wasPopoverOpen.current = isPopoverOpen; - }; - }, [isPopoverOpen, wasPopoverOpen]); // compute if selected dataStreams should be pinned const shouldPinSelectedDataStreams = useCallback( @@ -104,8 +115,16 @@ export const ChartsFilter = memo( const onOptionsChange = useCallback( (newOptions: FilterItems) => { + const optionItemsToSet = newOptions.map((option) => option); + const currChecks = optionItemsToSet.filter((option) => option.checked === 'on'); + + // don't update filter state if trying to uncheck all options + if (currChecks.length < 1) { + return; + } + // update filter UI options state - setItems(newOptions.map((option) => option)); + setItems(optionItemsToSet); // compute a selected list of options const selectedItems = newOptions.reduce((acc, curr) => { @@ -129,10 +148,7 @@ export const ChartsFilter = memo( shouldPinSelectedDataStreams(false); setAreDataStreamsSelectedOnMount(false); - // update overall query state - if (typeof onChangeFilterOptions !== 'undefined') { - onChangeFilterOptions(selectedItems); - } + onChangeFilterOptions(selectedItems); }, [ setItems, @@ -146,35 +162,11 @@ export const ChartsFilter = memo( ] ); - // clear all selected options - const onClearAll = useCallback(() => { - // update filter UI options state - setItems( - items.map((option) => { - option.checked = undefined; - return option; - }) - ); - - // update URL params based on filter on page - if (isMetricsFilter) { - setUrlMetricTypesFilter(''); - } else if (isDataStreamsFilter) { - setUrlDataStreamsFilter(''); - } - - if (typeof onChangeFilterOptions !== 'undefined') { - onChangeFilterOptions([]); - } - }, [ - setItems, - items, - isMetricsFilter, - isDataStreamsFilter, - onChangeFilterOptions, - setUrlMetricTypesFilter, - setUrlDataStreamsFilter, - ]); + useEffect(() => { + return () => { + wasPopoverOpen.current = isPopoverOpen; + }; + }, [isPopoverOpen, wasPopoverOpen]); return ( setSearchString(searchValue.trim()), }} > {(list, search) => { @@ -215,17 +206,6 @@ export const ChartsFilter = memo( )} {list} - {!isMetricsFilter && ( - - - - - - )} ); }} diff --git a/x-pack/plugins/data_usage/public/app/components/filters/charts_filters.tsx b/x-pack/plugins/data_usage/public/app/components/filters/charts_filters.tsx index 72608f4a62c75..6f3b07e37dc83 100644 --- a/x-pack/plugins/data_usage/public/app/components/filters/charts_filters.tsx +++ b/x-pack/plugins/data_usage/public/app/components/filters/charts_filters.tsx @@ -14,13 +14,13 @@ import type { import { useTestIdGenerator } from '../../../hooks/use_test_id_generator'; import { useGetDataUsageMetrics } from '../../../hooks/use_get_usage_metrics'; import { DateRangePickerValues, UsageMetricsDateRangePicker } from './date_picker'; -import { ChartsFilter } from './charts_filter'; +import { ChartsFilter, ChartsFilterProps } from './charts_filter'; +import { FilterName } from '../../hooks'; -interface ChartFiltersProps { +export interface ChartFiltersProps { dateRangePickerState: DateRangePickerValues; isDataLoading: boolean; - onChangeDataStreamsFilter: (selectedDataStreams: string[]) => void; - onChangeMetricTypesFilter?: (selectedMetricTypes: string[]) => void; + filterOptions: Record; onRefresh: () => void; onRefreshChange: (evt: OnRefreshChangeProps) => void; onTimeChange: ({ start, end }: DurationRange) => void; @@ -33,9 +33,8 @@ export const ChartFilters = memo( ({ dateRangePickerState, isDataLoading, + filterOptions, onClick, - onChangeMetricTypesFilter, - onChangeDataStreamsFilter, onRefresh, onRefreshChange, onTimeChange, @@ -47,19 +46,13 @@ export const ChartFilters = memo( const filters = useMemo(() => { return ( <> - {showMetricsTypesFilter && ( - + {showMetricsTypesFilter && } + {!filterOptions.dataStreams.isFilterLoading && ( + )} - ); - }, [onChangeDataStreamsFilter, onChangeMetricTypesFilter, showMetricsTypesFilter]); + }, [filterOptions, showMetricsTypesFilter]); const onClickRefreshButton = useCallback(() => onClick(), [onClick]); diff --git a/x-pack/plugins/data_usage/public/app/components/filters/clear_all_button.tsx b/x-pack/plugins/data_usage/public/app/components/filters/clear_all_button.tsx deleted file mode 100644 index afa4c2fe72917..0000000000000 --- a/x-pack/plugins/data_usage/public/app/components/filters/clear_all_button.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import React, { memo } from 'react'; -import { css } from '@emotion/react'; -import { euiThemeVars } from '@kbn/ui-theme'; -import { EuiButtonEmpty } from '@elastic/eui'; -import { UX_LABELS } from '../../translations'; - -const buttonCss = css` - border-top: ${euiThemeVars.euiBorderThin}; - border-radius: 0; -`; -export const ClearAllButton = memo( - ({ - 'data-test-subj': dataTestSubj, - isDisabled, - onClick, - }: { - 'data-test-subj'?: string; - isDisabled: boolean; - onClick: () => void; - }) => { - return ( - - {UX_LABELS.filterClearAll} - - ); - } -); - -ClearAllButton.displayName = 'ClearAllButton'; diff --git a/x-pack/plugins/data_usage/public/app/hooks/use_charts_filter.tsx b/x-pack/plugins/data_usage/public/app/hooks/use_charts_filter.tsx index 330c9a633396d..5cff100d9752e 100644 --- a/x-pack/plugins/data_usage/public/app/hooks/use_charts_filter.tsx +++ b/x-pack/plugins/data_usage/public/app/hooks/use_charts_filter.tsx @@ -11,9 +11,10 @@ import { METRIC_TYPE_API_VALUES_TO_UI_OPTIONS_MAP, METRIC_TYPE_VALUES, } from '../../../common/rest_types'; -import { useGetDataUsageDataStreams } from '../../hooks/use_get_data_streams'; import { FILTER_NAMES } from '../translations'; import { useDataUsageMetricsUrlParams } from './use_charts_url_params'; +import { formatBytes } from '../../utils/format_bytes'; +import { ChartsFilterProps } from '../components/filters/charts_filter'; export type FilterName = keyof typeof FILTER_NAMES; @@ -26,14 +27,11 @@ export type FilterItems = Array<{ }>; export const useChartsFilter = ({ - filterName, - searchString, + filterOptions, }: { - filterName: FilterName; - searchString: string; + filterOptions: ChartsFilterProps['filterOptions']; }): { areDataStreamsSelectedOnMount: boolean; - isLoading: boolean; items: FilterItems; setItems: React.Dispatch>; hasActiveFilters: boolean; @@ -52,12 +50,8 @@ export const useChartsFilter = ({ setUrlMetricTypesFilter, setUrlDataStreamsFilter, } = useDataUsageMetricsUrlParams(); - const isMetricTypesFilter = filterName === 'metricTypes'; - const isDataStreamsFilter = filterName === 'dataStreams'; - const { data: dataStreams, isFetching } = useGetDataUsageDataStreams({ - searchString, - selectedDataStreams: selectedDataStreamsFromUrl, - }); + const isMetricTypesFilter = filterOptions.filterName === 'metricTypes'; + const isDataStreamsFilter = filterOptions.filterName === 'dataStreams'; // track the state of selected data streams via URL // when the page is loaded via selected data streams on URL @@ -80,24 +74,23 @@ export const useChartsFilter = ({ label: METRIC_TYPE_API_VALUES_TO_UI_OPTIONS_MAP[metricType], checked: isDefaultMetricType(metricType) ? 'on' : undefined, // default metrics are selected by default disabled: isDefaultMetricType(metricType), - 'data-test-subj': `${filterName}-filter-option`, + 'data-test-subj': `${filterOptions.filterName}-filter-option`, + })) + : isDataStreamsFilter && !!filterOptions.options.length + ? filterOptions.options?.map((filterOption) => ({ + key: filterOption, + label: filterOption, + append: formatBytes(filterOptions.appendOptions?.[filterOption] ?? 0), + checked: selectedDataStreamsFromUrl + ? selectedDataStreamsFromUrl.includes(filterOption) + ? 'on' + : undefined + : 'on', + 'data-test-subj': `${filterOptions.filterName}-filter-option`, })) : [] ); - useEffect(() => { - if (isDataStreamsFilter && dataStreams) { - setItems( - dataStreams?.map((dataStream) => ({ - key: dataStream.name, - label: dataStream.name, - checked: dataStream.selected ? 'on' : undefined, - 'data-test-subj': `${filterName}-filter-option`, - })) - ); - } - }, [dataStreams, filterName, isDataStreamsFilter, setItems]); - const hasActiveFilters = useMemo(() => !!items.find((item) => item.checked === 'on'), [items]); const numActiveFilters = useMemo( () => items.filter((item) => item.checked === 'on').length, @@ -110,7 +103,6 @@ export const useChartsFilter = ({ return { areDataStreamsSelectedOnMount, - isLoading: isDataStreamsFilter && isFetching, items, setItems, hasActiveFilters, diff --git a/x-pack/plugins/data_usage/public/app/hooks/use_charts_url_params.tsx b/x-pack/plugins/data_usage/public/app/hooks/use_charts_url_params.tsx index 0e03da5d9adbd..ed833393ad7eb 100644 --- a/x-pack/plugins/data_usage/public/app/hooks/use_charts_url_params.tsx +++ b/x-pack/plugins/data_usage/public/app/hooks/use_charts_url_params.tsx @@ -53,9 +53,7 @@ export const getDataUsageMetricsFiltersFromUrlParams = ( }, []) : []; - const urlDataStreams = urlParams.dataStreams - ? String(urlParams.dataStreams).split(',').sort() - : []; + const urlDataStreams = urlParams.dataStreams ? String(urlParams.dataStreams).split(',') : []; dataUsageMetricsFilters.metricTypes = urlMetricTypes.length ? urlMetricTypes : undefined; dataUsageMetricsFilters.dataStreams = urlDataStreams.length ? urlDataStreams : undefined; diff --git a/x-pack/plugins/data_usage/public/app/translations.tsx b/x-pack/plugins/data_usage/public/app/translations.tsx index 687cdcf499b0d..ee42d3b58906b 100644 --- a/x-pack/plugins/data_usage/public/app/translations.tsx +++ b/x-pack/plugins/data_usage/public/app/translations.tsx @@ -48,7 +48,4 @@ export const UX_LABELS = Object.freeze({ defaultMessage: 'No {filterName} available', values: { filterName }, }), - noDataStreamsSelected: i18n.translate('xpack.dataUsage.metrics.noDataStreamsSelected', { - defaultMessage: 'Select one or more data streams to view data usage metrics.', - }), }); diff --git a/x-pack/plugins/data_usage/public/hooks/use_get_data_streams.ts b/x-pack/plugins/data_usage/public/hooks/use_get_data_streams.ts index 50a35bb211346..35f53c49e2c28 100644 --- a/x-pack/plugins/data_usage/public/hooks/use_get_data_streams.ts +++ b/x-pack/plugins/data_usage/public/hooks/use_get_data_streams.ts @@ -14,6 +14,7 @@ import { useKibanaContextForPlugin } from '../utils/use_kibana'; type GetDataUsageDataStreamsResponse = Array<{ name: string; + storageSizeBytes: number; selected: boolean; }>; @@ -23,11 +24,11 @@ const PAGING_PARAMS = Object.freeze({ }); export const useGetDataUsageDataStreams = ({ - searchString, selectedDataStreams, - options = {}, + options = { + enabled: false, + }, }: { - searchString: string; selectedDataStreams?: string[]; options?: UseQueryOptions; }): UseQueryResult => { @@ -45,7 +46,7 @@ export const useGetDataUsageDataStreams = ({ DATA_USAGE_DATA_STREAMS_API_ROUTE, { version: '1', - query: {}, + // query: {}, } ); @@ -53,12 +54,14 @@ export const useGetDataUsageDataStreams = ({ selected: GetDataUsageDataStreamsResponse; rest: GetDataUsageDataStreamsResponse; }>( - (acc, list) => { + (acc, ds) => { const item = { - name: list.name, + name: ds.name, + storageSizeBytes: ds.storageSizeBytes, + selected: ds.selected, }; - if (selectedDataStreams?.includes(list.name)) { + if (selectedDataStreams?.includes(ds.name)) { acc.selected.push({ ...item, selected: true }); } else { acc.rest.push({ ...item, selected: false }); diff --git a/x-pack/plugins/data_usage/public/hooks/use_get_usage_metrics.ts b/x-pack/plugins/data_usage/public/hooks/use_get_usage_metrics.ts index e9da41f01db54..bbd0f5d8aa02f 100644 --- a/x-pack/plugins/data_usage/public/hooks/use_get_usage_metrics.ts +++ b/x-pack/plugins/data_usage/public/hooks/use_get_usage_metrics.ts @@ -31,8 +31,9 @@ export const useGetDataUsageMetrics = ( queryKey: ['get-data-usage-metrics', body], ...options, keepPreviousData: true, - queryFn: async () => { + queryFn: async ({ signal }) => { return http.post(DATA_USAGE_METRICS_API_ROUTE, { + signal, version: '1', body: JSON.stringify({ from: body.from, diff --git a/x-pack/plugins/data_usage/public/utils/format_bytes.ts b/x-pack/plugins/data_usage/public/utils/format_bytes.ts new file mode 100644 index 0000000000000..c5f98f3f9e0d9 --- /dev/null +++ b/x-pack/plugins/data_usage/public/utils/format_bytes.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import numeral from '@elastic/numeral'; + +export const formatBytes = (bytes: number) => { + return numeral(bytes).format('0.0 b'); +}; diff --git a/x-pack/plugins/data_usage/server/routes/internal/data_streams_handler.ts b/x-pack/plugins/data_usage/server/routes/internal/data_streams_handler.ts index d9f5d22b44dba..bc8c5e898c35e 100644 --- a/x-pack/plugins/data_usage/server/routes/internal/data_streams_handler.ts +++ b/x-pack/plugins/data_usage/server/routes/internal/data_streams_handler.ts @@ -45,7 +45,7 @@ export const getDataStreamsHandler = ( .sort((a, b) => b.size_in_bytes - a.size_in_bytes) .map((stat) => ({ name: stat.name, - storageSizeBytes: stat.size_in_bytes, + storageSizeBytes: stat.size_in_bytes ?? 0, })); return response.ok({ diff --git a/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts b/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts index 0dd7c9d109c4a..93b31033fc4fb 100644 --- a/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts +++ b/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts @@ -35,6 +35,8 @@ export const getUsageMetricsHandler = ( logger.debug(`Retrieving usage metrics`); const { from, to, metricTypes, dataStreams: requestDsNames } = request.body; + // redundant check as we don't allow making requests via UI without data streams, + // but it's here to make sure the request body is validated before requesting metrics from auto-ops if (!requestDsNames?.length) { return errorHandler( logger, diff --git a/x-pack/plugins/data_usage/tsconfig.json b/x-pack/plugins/data_usage/tsconfig.json index 6d3818b88b9fe..78c501922f239 100644 --- a/x-pack/plugins/data_usage/tsconfig.json +++ b/x-pack/plugins/data_usage/tsconfig.json @@ -28,7 +28,6 @@ "@kbn/core-chrome-browser", "@kbn/features-plugin", "@kbn/index-management-shared-types", - "@kbn/ui-theme", "@kbn/repo-info", "@kbn/cloud-plugin", "@kbn/server-http-tools", From 722dd5d4be6a427f8899e7b11a6e57190beadc27 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 24 Oct 2024 01:03:23 +1100 Subject: [PATCH 33/33] [8.x] [ML] Get buckets and get overall buckets api integration tests (#197226) (#197417) # Backport This will backport the following commits from `main` to `8.x`: - [[ML] Get buckets and get overall buckets api integration tests (#197226)](https://github.com/elastic/kibana/pull/197226) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com> --- .../apis/ml/anomaly_detectors/get_buckets.ts | 110 ++++++++++++++ .../anomaly_detectors/get_overall_buckets.ts | 136 ++++++++++++++++++ .../apis/ml/anomaly_detectors/index.ts | 2 + 3 files changed, 248 insertions(+) create mode 100644 x-pack/test/api_integration/apis/ml/anomaly_detectors/get_buckets.ts create mode 100644 x-pack/test/api_integration/apis/ml/anomaly_detectors/get_overall_buckets.ts diff --git a/x-pack/test/api_integration/apis/ml/anomaly_detectors/get_buckets.ts b/x-pack/test/api_integration/apis/ml/anomaly_detectors/get_buckets.ts new file mode 100644 index 0000000000000..46220acf69c59 --- /dev/null +++ b/x-pack/test/api_integration/apis/ml/anomaly_detectors/get_buckets.ts @@ -0,0 +1,110 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DATAFEED_STATE, JOB_STATE } from '@kbn/ml-plugin/common'; +import expect from '@kbn/expect'; +import { USER } from '../../../../functional/services/ml/security_common'; +import { FtrProviderContext } from '../../../ftr_provider_context'; +import { getCommonRequestHeader } from '../../../../functional/services/ml/common_api'; + +export default ({ getService }: FtrProviderContext) => { + const esArchiver = getService('esArchiver'); + const ml = getService('ml'); + const supertest = getService('supertestWithoutAuth'); + + const jobId = `fq_single_buckets`; + + async function getBuckets({ + _jobId, + timestamp, + expectedStatusCode = 200, + }: { + _jobId: string; + timestamp?: number; + expectedStatusCode?: number; + }) { + const endpoint = `/internal/ml/anomaly_detectors/${_jobId}/results/buckets/${ + timestamp ? `${timestamp}` : '' + }`; + + const { body, status } = await supertest + .post(endpoint) + .auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER)) + .set(getCommonRequestHeader('1')) + .send({}); + + ml.api.assertResponseStatusCode(expectedStatusCode, status, body); + + return body; + } + + describe('POST anomaly_detectors results buckets', () => { + before(async () => { + await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); + await ml.testResources.setKibanaTimeZoneToUTC(); + + const jobConfig = ml.commonConfig.getADFqSingleMetricJobConfig(jobId); + const datafeedConfig = ml.commonConfig.getADFqDatafeedConfig(jobId); + + await ml.api.createAnomalyDetectionJob(jobConfig); + + await ml.api.createDatafeed(datafeedConfig); + + await ml.api.openAnomalyDetectionJob(jobId); + await ml.api.startDatafeed(datafeedConfig.datafeed_id, { + start: '0', + end: String(Date.now()), + }); + await ml.api.waitForDatafeedState(datafeedConfig.datafeed_id, DATAFEED_STATE.STOPPED); + await ml.api.waitForJobState(jobId, JOB_STATE.CLOSED); + }); + + after(async () => { + await ml.api.cleanMlIndices(); + }); + + it('should get buckets with correct structure for a job', async () => { + const result = await getBuckets({ _jobId: jobId }); + + expect(result.count).to.be.greaterThan(0); + expect(result.buckets).not.to.be.empty(); + expect(result.buckets[0]).to.have.keys( + 'job_id', + 'timestamp', + 'anomaly_score', + 'bucket_span', + 'initial_anomaly_score', + 'event_count', + 'is_interim', + 'bucket_influencers', + 'processing_time_ms', + 'result_type' + ); + }); + + it('should get a single bucket when timestamp is specified', async () => { + const allBuckets = await getBuckets({ _jobId: jobId }); + const sampleTimestamp = allBuckets.buckets[0].timestamp; + const result = await getBuckets({ _jobId: jobId, timestamp: sampleTimestamp }); + + expect(result.count).to.eql(1); + expect(result.buckets).to.have.length(1); + }); + + it('should fail with non-existent job', async () => { + await getBuckets({ _jobId: 'non-existent-job', expectedStatusCode: 404 }); + }); + + it('should fail with non-existent timestamp', async () => { + await getBuckets({ + _jobId: jobId, + timestamp: 1, + expectedStatusCode: 404, + }); + }); + }); +}; diff --git a/x-pack/test/api_integration/apis/ml/anomaly_detectors/get_overall_buckets.ts b/x-pack/test/api_integration/apis/ml/anomaly_detectors/get_overall_buckets.ts new file mode 100644 index 0000000000000..e0eab2657d643 --- /dev/null +++ b/x-pack/test/api_integration/apis/ml/anomaly_detectors/get_overall_buckets.ts @@ -0,0 +1,136 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DATAFEED_STATE, JOB_STATE } from '@kbn/ml-plugin/common'; +import expect from '@kbn/expect'; +import { USER } from '../../../../functional/services/ml/security_common'; +import { FtrProviderContext } from '../../../ftr_provider_context'; +import { getCommonRequestHeader } from '../../../../functional/services/ml/common_api'; + +export default ({ getService }: FtrProviderContext) => { + const esArchiver = getService('esArchiver'); + const ml = getService('ml'); + const supertest = getService('supertestWithoutAuth'); + + const jobId1 = `fq_single_overall_buckets_1`; + const jobId2 = `fq_single_overall_buckets_2`; + + async function getOverallBuckets({ + jobId, + topN = 1, + bucketSpan = '1h', + start = 0, + end = Date.now(), + overallScore, + expectedStatusCode = 200, + }: { + jobId: string; + bucketSpan?: string; + topN?: number; + start?: number; + end?: number; + overallScore?: number; + expectedStatusCode?: number; + }) { + const endpoint = `/internal/ml/anomaly_detectors/${jobId}/results/overall_buckets`; + + const { body, status } = await supertest + .post(endpoint) + .auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER)) + .set(getCommonRequestHeader('1')) + .send({ + topN, + bucketSpan, + start, + end, + ...(overallScore !== undefined && { overall_score: overallScore }), + }); + + ml.api.assertResponseStatusCode(expectedStatusCode, status, body); + + return body; + } + + describe('POST anomaly_detectors results overall_buckets', () => { + before(async () => { + await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); + await ml.testResources.setKibanaTimeZoneToUTC(); + + for (const jobId of [jobId1, jobId2]) { + const jobConfig = ml.commonConfig.getADFqSingleMetricJobConfig(jobId); + const datafeedConfig = ml.commonConfig.getADFqDatafeedConfig(jobId); + + await ml.api.createAnomalyDetectionJob(jobConfig); + + await ml.api.createDatafeed(datafeedConfig); + + await ml.api.openAnomalyDetectionJob(jobId); + await ml.api.startDatafeed(datafeedConfig.datafeed_id, { + start: '0', + end: String(Date.now()), + }); + await ml.api.waitForDatafeedState(datafeedConfig.datafeed_id, DATAFEED_STATE.STOPPED); + await ml.api.waitForJobState(jobId, JOB_STATE.CLOSED); + } + }); + + after(async () => { + await ml.api.cleanMlIndices(); + }); + + it('should get overall buckets with correct structure for multiple jobs', async () => { + const result = await getOverallBuckets({ + jobId: `${jobId1},${jobId2}`, + }); + + expect(result.count).to.be.greaterThan(0); + expect(result.overall_buckets).not.to.be.empty(); + expect(result.overall_buckets[0]).to.have.keys( + 'bucket_span', + 'is_interim', + 'jobs', + 'overall_score', + 'result_type', + 'timestamp' + ); + expect(result.overall_buckets[0].jobs.length).to.equal(2); + }); + + it('should respect the bucket_span parameter', async () => { + const result1h = await getOverallBuckets({ + jobId: `${jobId1},${jobId2}`, + bucketSpan: '1h', + }); + const result2h = await getOverallBuckets({ + jobId: `${jobId1},${jobId2}`, + bucketSpan: '2h', + }); + + expect(result1h.overall_buckets[0].bucket_span).to.not.equal( + result2h.overall_buckets[0].bucket_span + ); + }); + + it('should filter results based on overall_score', async () => { + const result = await getOverallBuckets({ + jobId: `${jobId1},${jobId2}`, + overallScore: 5, + }); + + for (const bucket of result.overall_buckets) { + expect(bucket.overall_score).to.be.greaterThan(5); + } + }); + + it('should fail with non-existent job', async () => { + await getOverallBuckets({ + jobId: 'non-existent-job', + expectedStatusCode: 404, + }); + }); + }); +}; diff --git a/x-pack/test/api_integration/apis/ml/anomaly_detectors/index.ts b/x-pack/test/api_integration/apis/ml/anomaly_detectors/index.ts index 89a12cb7f9a76..8176c3cb775f1 100644 --- a/x-pack/test/api_integration/apis/ml/anomaly_detectors/index.ts +++ b/x-pack/test/api_integration/apis/ml/anomaly_detectors/index.ts @@ -19,5 +19,7 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./create_with_spaces')); loadTestFile(require.resolve('./forecast_with_spaces')); loadTestFile(require.resolve('./create_with_datafeed')); + loadTestFile(require.resolve('./get_buckets')); + loadTestFile(require.resolve('./get_overall_buckets')); }); }