Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Extend Elasticsearch query rule with search source based data fetching #124534

Merged
merged 95 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
a0d6a1b
[Discover] introduce .index-threshold rule
dimaanj Feb 3, 2022
ac02e78
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Feb 8, 2022
6954568
[Discover] change filters in alert expression
dimaanj Feb 9, 2022
db9db04
[Discover] fix cursor issue
dimaanj Feb 9, 2022
98da07a
[Discover] add loading
dimaanj Feb 9, 2022
e25ab7c
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Feb 13, 2022
369144d
[Discover] separate validation params
dimaanj Feb 13, 2022
153023b
[Discover] add view alert route
dimaanj Feb 13, 2022
9582ab3
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Feb 15, 2022
37654ff
[Discover] enable "view in app" for alert created from discover
dimaanj Feb 19, 2022
7088f4b
[Discover] fix filter popover
dimaanj Feb 20, 2022
b618cce
[Discover] fix linting, unit tests
dimaanj Feb 21, 2022
67cf91c
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Feb 21, 2022
b46d24d
[Discover] fix remaining tests
dimaanj Feb 21, 2022
3ae3857
[Discover] add unit tests, add link back to stack management for es q…
dimaanj Feb 24, 2022
34cdcfc
Update src/plugins/discover/public/application/view_alert/view_alert_…
dimaanj Feb 24, 2022
1332d26
[Discover] add tool tip for data view without time field
dimaanj Feb 24, 2022
988d4bf
[Discover] add info alert about possible document difference that tri…
dimaanj Feb 24, 2022
fba6d5e
[Discover] update unit test
dimaanj Feb 24, 2022
6e7a0a3
[Discover] fix unit tests
dimaanj Feb 25, 2022
58e2563
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Feb 25, 2022
2528f2f
Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expres…
dimaanj Feb 25, 2022
f8667d5
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj Feb 25, 2022
5af2b95
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj Feb 25, 2022
8d44282
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj Feb 25, 2022
377f035
Update src/plugins/discover/public/application/main/components/top_na…
dimaanj Feb 25, 2022
02b6e43
Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expres…
dimaanj Feb 27, 2022
1cd93a0
[Discover] fix unit tests
dimaanj Feb 28, 2022
a41aeb4
[Discover] fix security solution alerts
dimaanj Feb 28, 2022
7889c47
[Discover] fix eslint errors
dimaanj Mar 1, 2022
17b413e
[Discover] fix unit tests
dimaanj Mar 1, 2022
347252c
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj Mar 1, 2022
bc381b6
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
dimaanj Mar 1, 2022
1819a35
[Discover] apply suggestions
dimaanj Mar 1, 2022
b020ba1
[Discover] fix tests
dimaanj Mar 1, 2022
b671155
Update x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_…
kertal Mar 2, 2022
111ae94
[Discover] remove close button in filters
dimaanj Mar 3, 2022
9113d15
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Mar 3, 2022
ad2b1b3
Improve code structure
kertal Mar 3, 2022
50f9f47
Fix missing name in fetchEsQuery
kertal Mar 4, 2022
a60d7dc
Fix messages
kertal Mar 4, 2022
8a9dcb3
Fix messages, again
kertal Mar 4, 2022
5e0066d
Merge remote-tracking branch 'upstream/main' into test-of-elastic-que…
kertal Mar 4, 2022
c65ec01
Merge main and fix conflicts
kertal Mar 4, 2022
2eb04f3
Refactor
kertal Mar 7, 2022
72698c1
Refactor, add tests + a bit more of documentation
kertal Mar 7, 2022
e49ef25
Merge main and fix conflicts
kertal Mar 7, 2022
59ff266
Merge remote-tracking branch 'upstream/main' into extend-elastic-quer…
kertal Mar 7, 2022
2fc9d06
Move size field, change text
kertal Mar 7, 2022
ae6eb60
Merge remote-tracking branch 'upstream/main' into extend-elastic-quer…
kertal Mar 7, 2022
db705eb
Implement readonly callout
kertal Mar 7, 2022
9c31f83
change icon in callout
andreadelrio Mar 7, 2022
6e2a817
add padding to popover
andreadelrio Mar 7, 2022
f902a8a
Hide query and filter UI if there are no values to display
kertal Mar 8, 2022
d23b730
Merge main and fix conflicts
kertal Mar 8, 2022
184c26d
[Discover] add unit test, improve comparator types
dimaanj Mar 10, 2022
5dddc68
[Discover] fix linting and unit test
dimaanj Mar 10, 2022
9752dbc
[Discover] add es query alert integration tests
dimaanj Mar 14, 2022
20d812f
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Mar 14, 2022
ee029f2
[Discover] fix linting
dimaanj Mar 14, 2022
07e02bf
[Discover] uncomment one expect
dimaanj Mar 14, 2022
ddeb66d
[Discover] fix latesTimestamp for searchSource type, unify test logic
dimaanj Mar 15, 2022
d29fcd5
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 15, 2022
46342d2
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 15, 2022
ae7d4bd
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Mar 16, 2022
8333c8f
Update x-pack/plugins/stack_alerts/public/alert_types/es_query/expres…
dimaanj Mar 17, 2022
6bcded6
[Discover] apply suggestions
dimaanj Mar 17, 2022
3541e65
[Discover] make searchType optional, adjust tests
dimaanj Mar 17, 2022
97a622e
[Discover] remove updated translations
dimaanj Mar 18, 2022
b6a39e9
[Discover] apply suggestions
dimaanj Mar 18, 2022
84112fc
[Discover] fix unit test
dimaanj Mar 18, 2022
da51596
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 18, 2022
63fb6b3
[Discover] close popover on alert rule creation
dimaanj Mar 18, 2022
709e4ce
Merge main and fix conflicts
kertal Mar 20, 2022
c9fe352
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 20, 2022
03a5826
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 21, 2022
4f5db31
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 21, 2022
bfc0025
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 21, 2022
14afdc6
[Discover] apply suggestions
dimaanj Mar 21, 2022
a4c23ec
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Mar 22, 2022
877748a
[Discover] add first functional test
dimaanj Mar 23, 2022
c2a7b10
[Discover] implement tests
dimaanj Mar 23, 2022
a06d37b
Move functionals x-pack since ssl is needed
kertal Mar 24, 2022
5adae74
Fix potential flakiness in functional test
kertal Mar 24, 2022
a36f5de
Fix conflicts
kertal Mar 24, 2022
e4892ea
[Discover] remove timeout waiter
dimaanj Mar 25, 2022
622703c
Fix functional test
kertal Mar 26, 2022
564417b
Merge branch 'main' of https://github.com/elastic/kibana into extend-…
dimaanj Mar 26, 2022
b48e03b
[Discover] add logger
dimaanj Mar 28, 2022
2d7360c
[Discover] add more log points
dimaanj Mar 28, 2022
048fefb
[Discover] wait for indices creation finished
dimaanj Mar 28, 2022
b6b273a
Try to fix the functional flakiness
kertal Mar 28, 2022
6365adb
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 30, 2022
f38e2e1
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 31, 2022
f0b8602
Merge branch 'main' into extend-elastic-query-rule
kibanamachine Mar 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export * from './deprecated';
*/

export { getEsQueryConfig } from '../common';
export { FilterLabel, FilterItem } from './ui';
export { FilterLabel, FilterItem, FilterBar } from './ui';
export { getDisplayValueFromFilter, generateFilters, extractTimeRange } from './query';

/**
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/data/public/ui/filter_bar/filter_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { IDataPluginServices, IIndexPattern } from '../..';

import { UI_SETTINGS } from '../../../common';

interface Props {
export interface FilterBarProps {
filters: Filter[];
onFiltersUpdated?: (filters: Filter[]) => void;
className: string;
Expand All @@ -40,7 +40,7 @@ interface Props {
timeRangeForSuggestionsOverride?: boolean;
}

const FilterBarUI = React.memo(function FilterBarUI(props: Props) {
const FilterBarUI = React.memo(function FilterBarUI(props: FilterBarProps) {
const groupRef = useRef<HTMLDivElement>(null);
const [isAddFilterPopoverOpen, setIsAddFilterPopoverOpen] = useState(false);
const kibana = useKibana<IDataPluginServices>();
Expand Down Expand Up @@ -229,3 +229,6 @@ const FilterBarUI = React.memo(function FilterBarUI(props: Props) {
});

export const FilterBar = injectI18n(FilterBarUI);

// eslint-disable-next-line import/no-default-export
export default FilterBar;
8 changes: 8 additions & 0 deletions src/plugins/data/public/ui/filter_bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React from 'react';
import type { FilterBarProps } from './filter_bar';

const Fallback = () => <div />;

Expand All @@ -23,3 +24,10 @@ export const FilterItem = (props: React.ComponentProps<typeof LazyFilterItem>) =
<LazyFilterItem {...props} />
</React.Suspense>
);

const LazyFilterBar = React.lazy(() => import('./filter_bar'));
export const FilterBar = (props: FilterBarProps) => (
<React.Suspense fallback={<Fallback />}>
<LazyFilterBar {...props} />
</React.Suspense>
);
2 changes: 1 addition & 1 deletion src/plugins/data/public/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

export type { IndexPatternSelectProps } from './index_pattern_select';
export { FilterLabel, FilterItem } from './filter_bar';
export { FilterLabel, FilterItem, FilterBar } from './filter_bar';
export type { QueryStringInputProps } from './query_string_input';
export { QueryStringInput } from './query_string_input';
export type { SearchBarProps, StatefulSearchBarProps } from './search_bar';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discover/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dataViewFieldEditor",
"dataViewEditor"
],
"optionalPlugins": ["home", "share", "usageCollection", "spaces"],
"optionalPlugins": ["home", "share", "usageCollection", "spaces", "triggersActionsUi"],
"requiredBundles": ["kibanaUtils", "home", "kibanaReact", "dataViews"],
"extraPublicDirs": ["common"],
"owner": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import type { DataView, ISearchSource } from 'src/plugins/data/common';
import { showOpenSearchPanel } from './show_open_search_panel';
Expand All @@ -17,6 +18,8 @@ import { onSaveSearch } from './on_save_search';
import { GetStateReturn } from '../../services/discover_state';
import { openOptionsPopover } from './open_options_popover';
import type { TopNavMenuData } from '../../../../../../navigation/public';
import { openAlertsPopover } from './open_alerts_popover';
import { toMountPoint, wrapWithTheme, MarkdownSimple } from '../../../../../../kibana_react/public';

/**
* Helper function to build the top nav links
Expand Down Expand Up @@ -58,6 +61,43 @@ export const getTopNavLinks = ({
testId: 'discoverOptionsButton',
};

const alerts = {
id: 'alerts',
label: i18n.translate('discover.localMenu.localMenu.alertsTitle', {
defaultMessage: 'Alerts',
}),
description: i18n.translate('discover.localMenu.alertsDescription', {
defaultMessage: 'Alerts',
}),
run: (anchorElement: HTMLElement) => {
if (savedSearch.searchSource.getField('index')?.timeFieldName) {
openAlertsPopover({
I18nContext: services.core.i18n.Context,
anchorElement,
searchSource: savedSearch.searchSource,
services,
});
} else {
services.toastNotifications.addDanger({
title: i18n.translate('discover.alert.errorHeader', {
defaultMessage: "Cant't create alert",
kertal marked this conversation as resolved.
Show resolved Hide resolved
}),
text: toMountPoint(
wrapWithTheme(
<MarkdownSimple>
{i18n.translate('discover.alert.dataViewDoesNotHaveTimeFieldErrorMessage', {
defaultMessage: 'Data view does not have time field.',
})}
</MarkdownSimple>,
services.core.theme.theme$
)
),
});
}
},
testId: 'discoverAlertsButton',
};

const newSearch = {
id: 'new',
label: i18n.translate('discover.localMenu.localMenu.newSearchTitle', {
Expand Down Expand Up @@ -161,6 +201,7 @@ export const getTopNavLinks = ({
...(services.capabilities.advancedSettings.save ? [options] : []),
newSearch,
openSearch,
...(services.triggersActionsUi ? [alerts] : []),
shareSearch,
inspectSearch,
...(services.capabilities.discover.save ? [saveSearch] : []),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import React, { useCallback, useState, useMemo } from 'react';
import ReactDOM from 'react-dom';
import { I18nStart } from 'kibana/public';
import { EuiWrappingPopover, EuiLink, EuiContextMenu } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { ISearchSource } from '../../../../../../data/common';
import { KibanaContextProvider } from '../../../../../../kibana_react/public';
import { DiscoverServices } from '../../../../build_services';
import { updateSearchSource } from '../../utils/update_search_source';
import { useDiscoverServices } from '../../../../utils/use_discover_services';

const container = document.createElement('div');
let isOpen = false;

const ALERT_TYPE_ID = '.es-query';

interface AlertsPopoverProps {
onClose: () => void;
anchorElement: HTMLElement;
searchSource: ISearchSource;
}

export function AlertsPopover(props: AlertsPopoverProps) {
const dataView = props.searchSource.getField('index')!;
const searchSource = props.searchSource;
const services = useDiscoverServices();
const { triggersActionsUi } = services;
const [alertFlyoutVisible, setAlertFlyoutVisibility] = useState<boolean>(false);

const onCloseAlertFlyout = useCallback(
() => setAlertFlyoutVisibility(false),
[setAlertFlyoutVisibility]
);
/**
* Provides the default parameters used to initialize the new rule
*/
const getParams = useCallback(() => {
const nextSearchSource = searchSource.createCopy();
updateSearchSource(nextSearchSource, true, {
indexPattern: searchSource.getField('index')!,
services,
sort: [],
useNewFieldsApi: true,
dimaanj marked this conversation as resolved.
Show resolved Hide resolved
});

return {
index: [dataView?.id],
timeField: dataView?.timeFieldName,
searchType: 'searchSource',
searchConfiguration: nextSearchSource.getSerializedFields(),
};
}, [searchSource, services, dataView]);

const SearchThresholdAlertFlyout = useMemo(() => {
if (!alertFlyoutVisible) {
return;
}
return triggersActionsUi?.getAddAlertFlyout({
consumer: 'discover',
onClose: onCloseAlertFlyout,
canChangeTrigger: false,
alertTypeId: ALERT_TYPE_ID,
initialValues: {
params: getParams(),
},
});
}, [getParams, onCloseAlertFlyout, triggersActionsUi, alertFlyoutVisible]);

const panels = [
{
id: 'mainPanel',
name: 'Alerting',
items: [
{
name: (
<>
{SearchThresholdAlertFlyout}
<EuiLink
onClick={() => {
setAlertFlyoutVisibility(true);
}}
>
<FormattedMessage
id="discover.alerts.createSearchThreshold"
defaultMessage="Create search threshold rule"
/>
</EuiLink>
</>
),
icon: 'bell',
disabled: !dataView.timeFieldName,
},
{
name: (
<EuiLink
color="text"
href={services?.application?.getUrlForApp(
'management/insightsAndAlerting/triggersActions/alerts'
)}
>
<FormattedMessage
id="discover.alerts.manageRulesAndConnectors"
defaultMessage="Manage rules and connectors"
/>
</EuiLink>
),
icon: 'tableOfContents',
},
],
},
];

return (
<>
{SearchThresholdAlertFlyout}
<EuiWrappingPopover
ownFocus
button={props.anchorElement}
closePopover={props.onClose}
isOpen={!alertFlyoutVisible}
>
<EuiContextMenu initialPanelId="mainPanel" panels={panels} />
</EuiWrappingPopover>
</>
);
}

function onClose() {
ReactDOM.unmountComponentAtNode(container);
document.body.removeChild(container);
isOpen = false;
}

export function openAlertsPopover({
I18nContext,
anchorElement,
searchSource,
services,
}: {
I18nContext: I18nStart['Context'];
anchorElement: HTMLElement;
searchSource: ISearchSource;
services: DiscoverServices;
}) {
if (isOpen) {
onClose();
return;
}

isOpen = true;
document.body.appendChild(container);

const element = (
<I18nContext>
<KibanaContextProvider services={services}>
<AlertsPopover
onClose={onClose}
anchorElement={anchorElement}
searchSource={searchSource}
/>
</KibanaContextProvider>
</I18nContext>
);
ReactDOM.render(element, container);
}
9 changes: 9 additions & 0 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
IUiSettingsClient,
PluginInitializerContext,
HttpStart,
NotificationsStart,
ApplicationStart,
} from 'kibana/public';
import {
FilterManager,
Expand All @@ -41,12 +43,14 @@ import { EmbeddableStart } from '../../embeddable/public';

import type { SpacesApi } from '../../../../x-pack/plugins/spaces/public';
import { DataViewEditorStart } from '../../../plugins/data_view_editor/public';
import type { TriggersAndActionsUIPublicPluginStart } from '../../../../x-pack/plugins/triggers_actions_ui/public';

export interface HistoryLocationState {
referrer: string;
}

export interface DiscoverServices {
application: ApplicationStart;
addBasePath: (path: string) => string;
capabilities: Capabilities;
chrome: ChromeStart;
Expand All @@ -66,13 +70,15 @@ export interface DiscoverServices {
urlForwarding: UrlForwardingStart;
timefilter: TimefilterContract;
toastNotifications: ToastsStart;
notifications: NotificationsStart;
uiSettings: IUiSettingsClient;
trackUiMetric?: (metricType: UiCounterMetricType, eventName: string | string[]) => void;
dataViewFieldEditor: IndexPatternFieldEditorStart;
dataViewEditor: DataViewEditorStart;
http: HttpStart;
storage: Storage;
spaces?: SpacesApi;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
}

export const buildServices = memoize(function (
Expand All @@ -84,6 +90,7 @@ export const buildServices = memoize(function (
const storage = new Storage(localStorage);

return {
application: core.application,
addBasePath: core.http.basePath.prepend,
capabilities: core.application.capabilities,
chrome: core.chrome,
Expand All @@ -105,12 +112,14 @@ export const buildServices = memoize(function (
urlForwarding: plugins.urlForwarding,
timefilter: plugins.data.query.timefilter.timefilter,
toastNotifications: core.notifications.toasts,
notifications: core.notifications,
uiSettings: core.uiSettings,
storage,
trackUiMetric: usageCollection?.reportUiCounter.bind(usageCollection, 'discover'),
dataViewFieldEditor: plugins.dataViewFieldEditor,
http: core.http,
spaces: plugins.spaces,
dataViewEditor: plugins.dataViewEditor,
triggersActionsUi: plugins.triggersActionsUi,
};
});
2 changes: 2 additions & 0 deletions src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { injectTruncateStyles } from './utils/truncate_styles';
import { DOC_TABLE_LEGACY, TRUNCATE_MAX_HEIGHT } from '../common';
import { DataViewEditorStart } from '../../../plugins/data_view_editor/public';
import { useDiscoverServices } from './utils/use_discover_services';
import type { TriggersAndActionsUIPublicPluginStart } from '../../../../x-pack/plugins/triggers_actions_ui/public';

declare module '../../share/public' {
export interface UrlGeneratorStateMapping {
Expand Down Expand Up @@ -191,6 +192,7 @@ export interface DiscoverStartPlugins {
usageCollection?: UsageCollectionSetup;
dataViewFieldEditor: IndexPatternFieldEditorStart;
spaces?: SpacesPluginStart;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
}

/**
Expand Down
Loading