mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Synthetics] Remove deprecated api (index pattern) usage (#130949)
This commit is contained in:
parent
eb043f7702
commit
b013b9695e
15 changed files with 52 additions and 50 deletions
|
@ -8,6 +8,7 @@
|
|||
"cases",
|
||||
"embeddable",
|
||||
"discover",
|
||||
"dataViews",
|
||||
"encryptedSavedObjects",
|
||||
"features",
|
||||
"inspector",
|
||||
|
|
|
@ -38,6 +38,7 @@ import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
|
|||
import { Start as InspectorPluginStart } from '@kbn/inspector-plugin/public';
|
||||
import { CasesUiStart } from '@kbn/cases-plugin/public';
|
||||
import { CloudSetup } from '@kbn/cloud-plugin/public';
|
||||
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
|
||||
import { PLUGIN } from '../../common/constants/plugin';
|
||||
import {
|
||||
LazySyntheticsPolicyCreateExtension,
|
||||
|
@ -67,6 +68,7 @@ export interface ClientPluginsStart {
|
|||
share: SharePluginStart;
|
||||
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
|
||||
cases: CasesUiStart;
|
||||
dataViews: DataViewsPublicPluginStart;
|
||||
}
|
||||
|
||||
export interface UptimePluginServices extends Partial<CoreStart> {
|
||||
|
|
|
@ -33,7 +33,7 @@ import { UptimeAlertsFlyoutWrapper } from '../components/overview';
|
|||
import { store, storage } from '../state';
|
||||
import { kibanaService } from '../state/kibana_service';
|
||||
import { ActionMenu } from '../components/common/header/action_menu';
|
||||
import { UptimeIndexPatternContextProvider } from '../contexts/uptime_index_pattern_context';
|
||||
import { UptimeDataViewContextProvider } from '../contexts/uptime_data_view_context';
|
||||
|
||||
export interface UptimeAppColors {
|
||||
danger: string;
|
||||
|
@ -124,7 +124,7 @@ const Application = (props: UptimeAppProps) => {
|
|||
<UptimeSettingsContextProvider {...props}>
|
||||
<UptimeThemeContextProvider darkMode={darkMode}>
|
||||
<UptimeStartupPluginsContextProvider {...startPlugins}>
|
||||
<UptimeIndexPatternContextProvider data={startPlugins.data}>
|
||||
<UptimeDataViewContextProvider dataViews={startPlugins.dataViews}>
|
||||
<div className={APP_WRAPPER_CLASS} data-test-subj="uptimeApp">
|
||||
<RedirectAppLinks
|
||||
className={APP_WRAPPER_CLASS}
|
||||
|
@ -137,7 +137,7 @@ const Application = (props: UptimeAppProps) => {
|
|||
</InspectorContextProvider>
|
||||
</RedirectAppLinks>
|
||||
</div>
|
||||
</UptimeIndexPatternContextProvider>
|
||||
</UptimeDataViewContextProvider>
|
||||
</UptimeStartupPluginsContextProvider>
|
||||
</UptimeThemeContextProvider>
|
||||
</UptimeSettingsContextProvider>
|
||||
|
|
|
@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n';
|
|||
import { QueryStringInput } from '@kbn/unified-search-plugin/public';
|
||||
import { isValidKuery } from '../../query_bar/query_bar';
|
||||
import * as labels from '../translations';
|
||||
import { useIndexPattern } from '../../../../hooks';
|
||||
import { useUptimeDataView } from '../../../../hooks';
|
||||
|
||||
interface Props {
|
||||
query: string;
|
||||
|
@ -19,7 +19,7 @@ interface Props {
|
|||
}
|
||||
|
||||
export const AlertQueryBar = ({ query = '', onChange }: Props) => {
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
const [inputVal, setInputVal] = useState<string>(query);
|
||||
|
||||
|
@ -31,7 +31,7 @@ export const AlertQueryBar = ({ query = '', onChange }: Props) => {
|
|||
return (
|
||||
<EuiFlexItem grow={1} style={{ flexBasis: 485 }}>
|
||||
<QueryStringInput
|
||||
indexPatterns={indexPattern ? [indexPattern] : []}
|
||||
indexPatterns={dataView ? [dataView] : []}
|
||||
iconType="search"
|
||||
isClearable={true}
|
||||
onChange={(queryN) => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { useFetcher } from '@kbn/observability-plugin/public';
|
||||
import { useIndexPattern, generateUpdatedKueryString } from '../../../../hooks';
|
||||
import { useUptimeDataView, generateUpdatedKueryString } from '../../../../hooks';
|
||||
import { fetchSnapshotCount } from '../../../../state/api';
|
||||
|
||||
export const useSnapShotCount = ({ query, filters }: { query: string; filters: [] | string }) => {
|
||||
|
@ -15,9 +15,9 @@ export const useSnapShotCount = ({ query, filters }: { query: string; filters: [
|
|||
? ''
|
||||
: JSON.stringify(Array.from(Object.entries(filters)));
|
||||
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
const [esKuery, error] = generateUpdatedKueryString(indexPattern, query, parsedFilters);
|
||||
const [esKuery, error] = generateUpdatedKueryString(dataView, query, parsedFilters);
|
||||
|
||||
const { data, loading } = useFetcher(
|
||||
() =>
|
||||
|
|
|
@ -10,7 +10,7 @@ import { EuiButtonIcon, EuiExpression, EuiFlexGroup, EuiFlexItem, EuiSpacer } fr
|
|||
import { FieldValueSuggestions } from '@kbn/observability-plugin/public';
|
||||
import { filterLabels } from '../../filter_group/translations';
|
||||
import { alertFilterLabels, filterAriaLabels } from './translations';
|
||||
import { useIndexPattern } from '../../../../contexts/uptime_index_pattern_context';
|
||||
import { useUptimeDataView } from '../../../../contexts/uptime_data_view_context';
|
||||
import { FILTER_FIELDS } from '../../../../../common/constants';
|
||||
import { useGetUrlParams } from '../../../../hooks';
|
||||
|
||||
|
@ -122,7 +122,7 @@ export const FiltersExpressionsSelect: React.FC<FilterExpressionsSelectProps> =
|
|||
(curr) => curr.selectedItems.length > 0 || newFilters?.includes(curr.fieldName)
|
||||
);
|
||||
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -130,11 +130,11 @@ export const FiltersExpressionsSelect: React.FC<FilterExpressionsSelectProps> =
|
|||
({ description, id, title, value, fieldName, ariaLabel, selectedItems }) => (
|
||||
<EuiFlexGroup key={id}>
|
||||
<EuiFlexItem>
|
||||
{indexPattern && (
|
||||
{dataView && (
|
||||
<FieldValueSuggestions
|
||||
filters={[]}
|
||||
key={fieldName}
|
||||
dataViewTitle={indexPattern.title}
|
||||
dataViewTitle={dataView.title}
|
||||
sourceField={fieldName}
|
||||
label={title}
|
||||
onChange={(vals) => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import React, { useState } from 'react';
|
||||
import { EuiButtonEmpty, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui';
|
||||
import * as labels from '../translations';
|
||||
import { useIndexPattern } from '../../../../contexts/uptime_index_pattern_context';
|
||||
import { useUptimeDataView } from '../../../../contexts/uptime_data_view_context';
|
||||
|
||||
interface Props {
|
||||
newFilters: string[];
|
||||
|
@ -21,7 +21,7 @@ export const AddFilterButton: React.FC<Props> = ({ newFilters, onNewFilter, aler
|
|||
|
||||
const getSelectedItems = (fieldName: string) => alertFilters?.[fieldName] ?? [];
|
||||
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
const onButtonClick = () => {
|
||||
setPopover(!isPopoverOpen);
|
||||
|
@ -65,7 +65,7 @@ export const AddFilterButton: React.FC<Props> = ({ newFilters, onNewFilter, aler
|
|||
onClick={onButtonClick}
|
||||
size="s"
|
||||
flush="left"
|
||||
isLoading={!indexPattern}
|
||||
isLoading={!dataView}
|
||||
>
|
||||
{labels.ADD_FILTER}
|
||||
</EuiButtonEmpty>
|
||||
|
|
|
@ -13,7 +13,7 @@ import { FieldValueSuggestions, useInspectorContext } from '@kbn/observability-p
|
|||
import { useFilterUpdate } from '../../../hooks/use_filter_update';
|
||||
import { useSelectedFilters } from '../../../hooks/use_selected_filters';
|
||||
import { SelectedFilters } from './selected_filters';
|
||||
import { useIndexPattern } from '../../../contexts/uptime_index_pattern_context';
|
||||
import { useUptimeDataView } from '../../../contexts/uptime_data_view_context';
|
||||
import { useGetUrlParams } from '../../../hooks';
|
||||
import { EXCLUDE_RUN_ONCE_FILTER } from '../../../../common/constants/client_defaults';
|
||||
|
||||
|
@ -40,7 +40,7 @@ export const FilterGroup = () => {
|
|||
|
||||
const { filtersList } = useSelectedFilters();
|
||||
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
const onFilterFieldChange = useCallback(
|
||||
(fieldName: string, values: string[], notValues: string[]) => {
|
||||
|
@ -52,12 +52,12 @@ export const FilterGroup = () => {
|
|||
return (
|
||||
<>
|
||||
<Container>
|
||||
{indexPattern &&
|
||||
{dataView &&
|
||||
filtersList.map(({ field, label, selectedItems, excludedItems }) => (
|
||||
<FieldValueSuggestions
|
||||
key={field}
|
||||
compressed={false}
|
||||
dataViewTitle={indexPattern.title}
|
||||
dataViewTitle={dataView.title}
|
||||
sourceField={field}
|
||||
label={label}
|
||||
selectedValue={selectedItems}
|
||||
|
|
|
@ -8,17 +8,17 @@
|
|||
import React from 'react';
|
||||
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
|
||||
import { FilterValueLabel } from '@kbn/observability-plugin/public';
|
||||
import { useIndexPattern } from '../../../contexts/uptime_index_pattern_context';
|
||||
import { useUptimeDataView } from '../../../contexts/uptime_data_view_context';
|
||||
import { useSelectedFilters } from '../../../hooks/use_selected_filters';
|
||||
|
||||
interface Props {
|
||||
onChange: (fieldName: string, values: string[], notValues: string[]) => void;
|
||||
}
|
||||
export const SelectedFilters = ({ onChange }: Props) => {
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
const { filtersList } = useSelectedFilters();
|
||||
|
||||
if (!indexPattern) return null;
|
||||
if (!dataView) return null;
|
||||
|
||||
return (
|
||||
<EuiFlexGroup gutterSize="xs" wrap>
|
||||
|
@ -26,7 +26,7 @@ export const SelectedFilters = ({ onChange }: Props) => {
|
|||
...selectedItems.map((value) => (
|
||||
<EuiFlexItem key={field + value} grow={false}>
|
||||
<FilterValueLabel
|
||||
dataView={indexPattern}
|
||||
dataView={dataView}
|
||||
removeFilter={() => {
|
||||
onChange(
|
||||
field,
|
||||
|
@ -51,7 +51,7 @@ export const SelectedFilters = ({ onChange }: Props) => {
|
|||
...excludedItems.map((value) => (
|
||||
<EuiFlexItem key={field + value} grow={false}>
|
||||
<FilterValueLabel
|
||||
dataView={indexPattern}
|
||||
dataView={dataView}
|
||||
removeFilter={() => {
|
||||
onChange(
|
||||
field,
|
||||
|
|
|
@ -11,7 +11,7 @@ import { EuiFlexItem } from '@elastic/eui';
|
|||
import { QueryStringInput } from '@kbn/unified-search-plugin/public';
|
||||
import { SyntaxType, useQueryBar } from './use_query_bar';
|
||||
import { KQL_PLACE_HOLDER, SIMPLE_SEARCH_PLACEHOLDER } from './translations';
|
||||
import { useGetUrlParams, useIndexPattern } from '../../../hooks';
|
||||
import { useGetUrlParams, useUptimeDataView } from '../../../hooks';
|
||||
|
||||
const SYNTAX_STORAGE = 'uptime:queryBarSyntax';
|
||||
|
||||
|
@ -35,7 +35,7 @@ export const QueryBar = () => {
|
|||
|
||||
const { query, setQuery, submitImmediately } = useQueryBar();
|
||||
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
const [inputVal, setInputVal] = useState<string>(query.query as string);
|
||||
|
||||
|
@ -49,7 +49,7 @@ export const QueryBar = () => {
|
|||
return (
|
||||
<EuiFlexItem grow={1} style={{ flexBasis: 485 }}>
|
||||
<QueryStringInput
|
||||
indexPatterns={indexPattern ? [indexPattern] : []}
|
||||
indexPatterns={dataView ? [dataView] : []}
|
||||
nonKqlMode="text"
|
||||
iconType="search"
|
||||
isClearable={true}
|
||||
|
|
|
@ -12,7 +12,7 @@ import { Query } from '@kbn/data-plugin/common';
|
|||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import {
|
||||
useGetUrlParams,
|
||||
useIndexPattern,
|
||||
useUptimeDataView,
|
||||
generateUpdatedKueryString,
|
||||
useUrlParams,
|
||||
} from '../../../hooks';
|
||||
|
@ -70,12 +70,12 @@ export const useQueryBar = (): UseQueryBarUtils => {
|
|||
}
|
||||
);
|
||||
|
||||
const indexPattern = useIndexPattern();
|
||||
const dataView = useUptimeDataView();
|
||||
|
||||
const [, updateUrlParams] = useUrlParams();
|
||||
|
||||
const [esFilters, error] = generateUpdatedKueryString(
|
||||
indexPattern,
|
||||
dataView,
|
||||
query.language === SyntaxType.kuery ? (query.query as string) : undefined,
|
||||
paramFilters,
|
||||
excludedFilters
|
||||
|
|
|
@ -7,27 +7,26 @@
|
|||
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { useFetcher } from '@kbn/observability-plugin/public';
|
||||
import { DataPublicPluginStart, IndexPattern } from '@kbn/data-plugin/public';
|
||||
import { DataViewsPublicPluginStart, DataView } from '@kbn/data-views-plugin/public';
|
||||
import { useHasData } from '../components/overview/empty_state/use_has_data';
|
||||
|
||||
export const UptimeIndexPatternContext = createContext({} as IndexPattern);
|
||||
export const UptimeDataViewContext = createContext({} as DataView);
|
||||
|
||||
export const UptimeIndexPatternContextProvider: React.FC<{ data: DataPublicPluginStart }> = ({
|
||||
children,
|
||||
data: { indexPatterns },
|
||||
}) => {
|
||||
export const UptimeDataViewContextProvider: React.FC<{
|
||||
dataViews: DataViewsPublicPluginStart;
|
||||
}> = ({ children, dataViews }) => {
|
||||
const { settings, data: indexStatus } = useHasData();
|
||||
|
||||
const heartbeatIndices = settings?.heartbeatIndices || '';
|
||||
|
||||
const { data } = useFetcher<Promise<IndexPattern | undefined>>(async () => {
|
||||
const { data } = useFetcher<Promise<DataView | undefined>>(async () => {
|
||||
if (heartbeatIndices && indexStatus?.indexExists) {
|
||||
// this only creates an index pattern in memory, not as saved object
|
||||
return indexPatterns.create({ title: heartbeatIndices });
|
||||
// this only creates an dateView in memory, not as saved object
|
||||
return dataViews.create({ title: heartbeatIndices });
|
||||
}
|
||||
}, [heartbeatIndices, indexStatus?.indexExists]);
|
||||
|
||||
return <UptimeIndexPatternContext.Provider value={data!} children={children} />;
|
||||
return <UptimeDataViewContext.Provider value={data!} children={children} />;
|
||||
};
|
||||
|
||||
export const useIndexPattern = () => useContext(UptimeIndexPatternContext);
|
||||
export const useUptimeDataView = () => useContext(UptimeDataViewContext);
|
|
@ -13,4 +13,4 @@ export * from './use_cert_status';
|
|||
export * from './use_telemetry';
|
||||
export * from './use_url_params';
|
||||
export * from './use_breakpoints';
|
||||
export { useIndexPattern } from '../contexts/uptime_index_pattern_context';
|
||||
export { useUptimeDataView } from '../contexts/uptime_data_view_context';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import type { IndexPattern } from '@kbn/data-plugin/public';
|
||||
import { DataView } from '@kbn/data-views-plugin/public';
|
||||
import { combineFiltersAndUserSearch, stringifyKueries } from '../../common/lib';
|
||||
|
||||
const getKueryString = (urlFilters: string, excludedFilters?: string): string => {
|
||||
|
@ -42,7 +42,7 @@ const getKueryString = (urlFilters: string, excludedFilters?: string): string =>
|
|||
};
|
||||
|
||||
export const generateUpdatedKueryString = (
|
||||
indexPattern: IndexPattern | null,
|
||||
dataView: DataView | null,
|
||||
filterQueryString = '',
|
||||
urlFilters: string,
|
||||
excludedFilters?: string
|
||||
|
@ -55,10 +55,10 @@ export const generateUpdatedKueryString = (
|
|||
// this try catch is necessary to evaluate user input in kuery bar,
|
||||
// this error will be actually shown in UI for user to see
|
||||
try {
|
||||
if ((filterQueryString || urlFilters || excludedFilters) && indexPattern) {
|
||||
if ((filterQueryString || urlFilters || excludedFilters) && dataView) {
|
||||
const ast = fromKueryExpression(combinedFilterString);
|
||||
|
||||
const elasticsearchQuery = toElasticsearchQuery(ast, indexPattern);
|
||||
const elasticsearchQuery = toElasticsearchQuery(ast, dataView);
|
||||
|
||||
esFilters = JSON.stringify(elasticsearchQuery);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import { store } from '../../../state';
|
|||
import { ClientPluginsStart } from '../../../apps/plugin';
|
||||
import { kibanaService } from '../../../state/kibana_service';
|
||||
import { AlertMonitorStatus } from '../../../components/overview/alerts/alerts_containers/alert_monitor_status';
|
||||
import { UptimeIndexPatternContextProvider } from '../../../contexts/uptime_index_pattern_context';
|
||||
import { UptimeDataViewContextProvider } from '../../../contexts/uptime_data_view_context';
|
||||
|
||||
interface Props {
|
||||
core: CoreStart;
|
||||
|
@ -27,9 +27,9 @@ export default function MonitorStatusAlert({ core, plugins, params }: Props) {
|
|||
return (
|
||||
<ReduxProvider store={store}>
|
||||
<KibanaContextProvider services={{ ...core, ...plugins }}>
|
||||
<UptimeIndexPatternContextProvider data={plugins.data}>
|
||||
<UptimeDataViewContextProvider dataViews={plugins.dataViews}>
|
||||
<AlertMonitorStatus {...params} autocomplete={plugins.unifiedSearch.autocomplete} />
|
||||
</UptimeIndexPatternContextProvider>
|
||||
</UptimeDataViewContextProvider>
|
||||
</KibanaContextProvider>
|
||||
</ReduxProvider>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue