diff --git a/x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts b/x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts index c900123c6cee9..6397c79ce4ffb 100644 --- a/x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts +++ b/x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts @@ -17,8 +17,7 @@ import { argv } from 'yargs'; import { Logger } from 'kibana/server'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { CollectTelemetryParams } from '../../server/lib/apm_telemetry/collect_data_telemetry'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { unwrapEsResponse } from '../../../observability/server/utils/unwrap_es_response'; +import { unwrapEsResponse } from '../../../observability/common/utils/unwrap_es_response'; import { downloadTelemetryTemplate } from '../shared/download-telemetry-template'; import { mergeApmTelemetryMapping } from '../../common/apm_telemetry'; import { generateSampleDocuments } from './generate-sample-documents'; diff --git a/x-pack/plugins/observability/server/utils/get_inspect_response.ts b/x-pack/plugins/observability/common/utils/get_inspect_response.ts similarity index 79% rename from x-pack/plugins/observability/server/utils/get_inspect_response.ts rename to x-pack/plugins/observability/common/utils/get_inspect_response.ts index a6792e0cac5fd..55d84b622dc2c 100644 --- a/x-pack/plugins/observability/server/utils/get_inspect_response.ts +++ b/x-pack/plugins/observability/common/utils/get_inspect_response.ts @@ -8,8 +8,8 @@ import { i18n } from '@kbn/i18n'; import type { KibanaRequest } from 'kibana/server'; import type { RequestStatistics, RequestStatus } from '../../../../../src/plugins/inspector'; -import { WrappedElasticsearchClientError } from '../index'; import { InspectResponse } from '../../typings/common'; +import { WrappedElasticsearchClientError } from './unwrap_es_response'; /** * Get statistics to show on inspector tab. @@ -29,19 +29,26 @@ function getStats({ kibanaRequest: KibanaRequest; }) { const stats: RequestStatistics = { - kibanaApiQueryParameters: { - label: i18n.translate('xpack.observability.inspector.stats.kibanaApiQueryParametersLabel', { - defaultMessage: 'Kibana API query parameters', - }), - description: i18n.translate( - 'xpack.observability.inspector.stats.kibanaApiQueryParametersDescription', - { - defaultMessage: - 'The query parameters used in the Kibana API request that initiated the Elasticsearch request.', + ...(kibanaRequest.query + ? { + kibanaApiQueryParameters: { + label: i18n.translate( + 'xpack.observability.inspector.stats.kibanaApiQueryParametersLabel', + { + defaultMessage: 'Kibana API query parameters', + } + ), + description: i18n.translate( + 'xpack.observability.inspector.stats.kibanaApiQueryParametersDescription', + { + defaultMessage: + 'The query parameters used in the Kibana API request that initiated the Elasticsearch request.', + } + ), + value: JSON.stringify(kibanaRequest.query, null, 2), + }, } - ), - value: JSON.stringify(kibanaRequest.query, null, 2), - }, + : {}), kibanaApiRoute: { label: i18n.translate('xpack.observability.inspector.stats.kibanaApiRouteLabel', { defaultMessage: 'Kibana API route', @@ -93,11 +100,17 @@ function getStats({ } if (esResponse?.hits?.total !== undefined) { - const total = esResponse.hits.total as { - relation: string; - value: number; - }; - const hitsTotalValue = total.relation === 'eq' ? `${total.value}` : `> ${total.value}`; + let hitsTotalValue; + + if (typeof esResponse.hits.total === 'number') { + hitsTotalValue = esResponse.hits.total; + } else { + const total = esResponse.hits.total as { + relation: string; + value: number; + }; + hitsTotalValue = total.relation === 'eq' ? `${total.value}` : `> ${total.value}`; + } stats.hitsTotal = { label: i18n.translate('xpack.observability.inspector.stats.hitsTotalLabel', { diff --git a/x-pack/plugins/observability/server/utils/unwrap_es_response.ts b/x-pack/plugins/observability/common/utils/unwrap_es_response.ts similarity index 100% rename from x-pack/plugins/observability/server/utils/unwrap_es_response.ts rename to x-pack/plugins/observability/common/utils/unwrap_es_response.ts diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/use_filter_values.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/use_filter_values.ts index 8c659db559d68..e84f79f88298c 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/use_filter_values.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/series_editor/use_filter_values.ts @@ -12,7 +12,10 @@ import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern'; import { ESFilter } from '../../../../../../../../src/core/types/elasticsearch'; import { PersistableFilter } from '../../../../../../lens/common'; -export function useFilterValues({ field, series, baseFilters }: FilterProps, query?: string) { +export function useFilterValues( + { field, series, baseFilters, label }: FilterProps, + query?: string +) { const { indexPatterns } = useAppIndexPatternContext(series.dataType); const queryFilters: ESFilter[] = []; @@ -28,6 +31,7 @@ export function useFilterValues({ field, series, baseFilters }: FilterProps, que return useValuesList({ query, + label, sourceField: field, time: series.time, keepHistory: true, diff --git a/x-pack/plugins/observability/public/components/shared/field_value_suggestions/index.tsx b/x-pack/plugins/observability/public/components/shared/field_value_suggestions/index.tsx index 1c5da15dd33df..ccb2ea2932f5d 100644 --- a/x-pack/plugins/observability/public/components/shared/field_value_suggestions/index.tsx +++ b/x-pack/plugins/observability/public/components/shared/field_value_suggestions/index.tsx @@ -33,6 +33,7 @@ export function FieldValueSuggestions({ required, allowExclusions = true, cardinalityField, + inspector, asCombobox = true, onChange: onSelectionChange, }: FieldValueSuggestionsProps) { @@ -44,7 +45,9 @@ export function FieldValueSuggestions({ sourceField, filters, time, + inspector, cardinalityField, + label, keepHistory: true, }); diff --git a/x-pack/plugins/observability/public/components/shared/field_value_suggestions/types.ts b/x-pack/plugins/observability/public/components/shared/field_value_suggestions/types.ts index b6de2bafdd852..6f6d520a83154 100644 --- a/x-pack/plugins/observability/public/components/shared/field_value_suggestions/types.ts +++ b/x-pack/plugins/observability/public/components/shared/field_value_suggestions/types.ts @@ -8,6 +8,7 @@ import { PopoverAnchorPosition } from '@elastic/eui'; import { Dispatch, SetStateAction } from 'react'; import { ESFilter } from 'src/core/types/elasticsearch'; +import { IInspectorInfo } from '../../../../../../../src/plugins/data/common'; interface CommonProps { selectedValue?: string[]; @@ -37,6 +38,7 @@ export type FieldValueSuggestionsProps = CommonProps & { onChange: (val?: string[], excludedValue?: string[]) => void; filters: ESFilter[]; time?: { from: string; to: string }; + inspector?: IInspectorInfo; }; export type FieldValueSelectionProps = CommonProps & { diff --git a/x-pack/plugins/observability/public/context/inspector/inspector_context.tsx b/x-pack/plugins/observability/public/context/inspector/inspector_context.tsx index 1d9bd95fa08fa..56498fcaecd5c 100644 --- a/x-pack/plugins/observability/public/context/inspector/inspector_context.tsx +++ b/x-pack/plugins/observability/public/context/inspector/inspector_context.tsx @@ -23,6 +23,13 @@ const value: InspectorContextValue = { export const InspectorContext = createContext(value); +export type AddInspectorRequest = ( + result: FetcherResult<{ + mainStatisticsData?: { _inspect?: InspectResponse }; + _inspect?: InspectResponse; + }> +) => void; + export function InspectorContextProvider({ children }: { children: ReactNode }) { const history = useHistory(); const { inspectorAdapters } = value; diff --git a/x-pack/plugins/observability/public/hooks/use_es_search.ts b/x-pack/plugins/observability/public/hooks/use_es_search.ts index 70ffdbba22c58..bf96cf2c1f2c5 100644 --- a/x-pack/plugins/observability/public/hooks/use_es_search.ts +++ b/x-pack/plugins/observability/public/hooks/use_es_search.ts @@ -9,27 +9,61 @@ import { estypes } from '@elastic/elasticsearch'; import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; import { ESSearchResponse } from '../../../../../src/core/types/elasticsearch'; import { useKibana } from '../../../../../src/plugins/kibana_react/public'; -import { isCompleteResponse } from '../../../../../src/plugins/data/common'; -import { useFetcher } from './use_fetcher'; +import { IInspectorInfo, isCompleteResponse } from '../../../../../src/plugins/data/common'; +import { FETCH_STATUS, useFetcher } from './use_fetcher'; +import { useInspectorContext } from '../context/inspector/use_inspector_context'; +import { getInspectResponse } from '../../common/utils/get_inspect_response'; export const useEsSearch = ( params: TParams, - fnDeps: any[] + fnDeps: any[], + options: { inspector?: IInspectorInfo; name: string } ) => { const { services: { data }, } = useKibana<{ data: DataPublicPluginStart }>(); + const { name } = options ?? {}; + + const { addInspectorRequest } = useInspectorContext(); + const { data: response = {}, loading } = useFetcher(() => { if (params.index) { + const startTime = Date.now(); return new Promise((resolve) => { const search$ = data.search - .search({ - params, - }) + .search( + { + params, + }, + {} + ) .subscribe({ next: (result) => { if (isCompleteResponse(result)) { + if (addInspectorRequest) { + addInspectorRequest({ + data: { + _inspect: [ + getInspectResponse({ + startTime, + esRequestParams: params, + esResponse: result.rawResponse, + esError: null, + esRequestStatus: 1, + operationName: name, + kibanaRequest: { + route: { + path: '/internal/bsearch', + method: 'POST', + }, + } as any, + }), + ], + }, + status: FETCH_STATUS.SUCCESS, + }); + } // Final result resolve(result); search$.unsubscribe(); diff --git a/x-pack/plugins/observability/public/hooks/use_values_list.ts b/x-pack/plugins/observability/public/hooks/use_values_list.ts index 7f52fff55e706..e2268f7b85244 100644 --- a/x-pack/plugins/observability/public/hooks/use_values_list.ts +++ b/x-pack/plugins/observability/public/hooks/use_values_list.ts @@ -10,16 +10,19 @@ import { useEffect, useState } from 'react'; import useDebounce from 'react-use/lib/useDebounce'; import { ESFilter } from '../../../../../src/core/types/elasticsearch'; import { createEsParams, useEsSearch } from './use_es_search'; +import { IInspectorInfo } from '../../../../../src/plugins/data/common'; import { TRANSACTION_URL } from '../components/shared/exploratory_view/configurations/constants/elasticsearch_fieldnames'; export interface Props { sourceField: string; + label: string; query?: string; indexPatternTitle?: string; filters?: ESFilter[]; time?: { from: string; to: string }; keepHistory?: boolean; cardinalityField?: string; + inspector?: IInspectorInfo; } export interface ListItem { @@ -60,6 +63,7 @@ export const useValuesList = ({ query = '', filters, time, + label, keepHistory, cardinalityField, }: Props): { values: ListItem[]; loading?: boolean } => { @@ -131,7 +135,8 @@ export const useValuesList = ({ }, }, }), - [debouncedQuery, from, to, JSON.stringify(filters), indexPatternTitle, sourceField] + [debouncedQuery, from, to, JSON.stringify(filters), indexPatternTitle, sourceField], + { name: `get${label.replace(/\s/g, '')}ValuesList` } ); useEffect(() => { diff --git a/x-pack/plugins/observability/public/index.ts b/x-pack/plugins/observability/public/index.ts index 22ad95b96f41f..2dd380c3b7683 100644 --- a/x-pack/plugins/observability/public/index.ts +++ b/x-pack/plugins/observability/public/index.ts @@ -83,5 +83,8 @@ export type { export { createObservabilityRuleTypeRegistryMock } from './rules/observability_rule_type_registry_mock'; export type { ExploratoryEmbeddableProps } from './components/shared/exploratory_view/embeddable/embeddable'; -export { InspectorContextProvider } from './context/inspector/inspector_context'; +export { + InspectorContextProvider, + AddInspectorRequest, +} from './context/inspector/inspector_context'; export { useInspectorContext } from './context/inspector/use_inspector_context'; diff --git a/x-pack/plugins/observability/server/index.ts b/x-pack/plugins/observability/server/index.ts index 53c3ecb23546c..57cfbebc3ccff 100644 --- a/x-pack/plugins/observability/server/index.ts +++ b/x-pack/plugins/observability/server/index.ts @@ -13,9 +13,12 @@ import { PluginConfigDescriptor, PluginInitializerContext } from 'src/core/serve import { ObservabilityPlugin, ObservabilityPluginSetup } from './plugin'; import { createOrUpdateIndex, Mappings } from './utils/create_or_update_index'; import { ScopedAnnotationsClient } from './lib/annotations/bootstrap_annotations'; -import { unwrapEsResponse, WrappedElasticsearchClientError } from './utils/unwrap_es_response'; +import { + unwrapEsResponse, + WrappedElasticsearchClientError, +} from '../common/utils/unwrap_es_response'; export { rangeQuery, kqlQuery } from './utils/queries'; -export { getInspectResponse } from './utils/get_inspect_response'; +export { getInspectResponse } from '../common/utils/get_inspect_response'; export * from './types'; diff --git a/x-pack/plugins/observability/server/lib/annotations/create_annotations_client.ts b/x-pack/plugins/observability/server/lib/annotations/create_annotations_client.ts index 39a594dcc86ca..98e8908cd60a5 100644 --- a/x-pack/plugins/observability/server/lib/annotations/create_annotations_client.ts +++ b/x-pack/plugins/observability/server/lib/annotations/create_annotations_client.ts @@ -17,7 +17,7 @@ import { } from '../../../common/annotations'; import { createOrUpdateIndex } from '../../utils/create_or_update_index'; import { mappings } from './mappings'; -import { unwrapEsResponse } from '../../utils/unwrap_es_response'; +import { unwrapEsResponse } from '../../../common/utils/unwrap_es_response'; type CreateParams = t.TypeOf; type DeleteParams = t.TypeOf; diff --git a/x-pack/plugins/uptime/kibana.json b/x-pack/plugins/uptime/kibana.json index 3124324d90389..409436d734011 100644 --- a/x-pack/plugins/uptime/kibana.json +++ b/x-pack/plugins/uptime/kibana.json @@ -14,6 +14,7 @@ "requiredPlugins": [ "alerting", "embeddable", + "inspector", "features", "licensing", "triggersActionsUi", diff --git a/x-pack/plugins/uptime/public/apps/plugin.ts b/x-pack/plugins/uptime/public/apps/plugin.ts index ed936fe164983..124de9a60110c 100644 --- a/x-pack/plugins/uptime/public/apps/plugin.ts +++ b/x-pack/plugins/uptime/public/apps/plugin.ts @@ -42,6 +42,7 @@ import { LazySyntheticsPolicyEditExtension, } from '../components/fleet_package'; import { LazySyntheticsCustomAssetsExtension } from '../components/fleet_package/lazy_synthetics_custom_assets_extension'; +import { Start as InspectorPluginStart } from '../../../../../src/plugins/inspector/public'; export interface ClientPluginsSetup { data: DataPublicPluginSetup; @@ -56,6 +57,7 @@ export interface ClientPluginsStart { triggersActionsUi: TriggersAndActionsUIPublicPluginStart; fleet?: FleetStart; observability: ObservabilityPublicStart; + inspector: InspectorPluginStart; } export interface UptimePluginServices extends Partial { diff --git a/x-pack/plugins/uptime/public/apps/uptime_app.tsx b/x-pack/plugins/uptime/public/apps/uptime_app.tsx index 73f228f621540..991657f258029 100644 --- a/x-pack/plugins/uptime/public/apps/uptime_app.tsx +++ b/x-pack/plugins/uptime/public/apps/uptime_app.tsx @@ -33,6 +33,7 @@ import { ActionMenu } from '../components/common/header/action_menu'; import { EuiThemeProvider } from '../../../../../src/plugins/kibana_react/common'; import { Storage } from '../../../../../src/plugins/kibana_utils/public'; import { UptimeIndexPatternContextProvider } from '../contexts/uptime_index_pattern_context'; +import { InspectorContextProvider } from '../../../observability/public'; export interface UptimeAppColors { danger: string; @@ -110,6 +111,7 @@ const Application = (props: UptimeAppProps) => { ...plugins, storage, data: startPlugins.data, + inspector: startPlugins.inspector, triggersActionsUi: startPlugins.triggersActionsUi, observability: startPlugins.observability, }} @@ -126,9 +128,11 @@ const Application = (props: UptimeAppProps) => { className={APP_WRAPPER_CLASS} application={core.application} > - - - + + + + + diff --git a/x-pack/plugins/uptime/public/apps/uptime_page_template.tsx b/x-pack/plugins/uptime/public/apps/uptime_page_template.tsx index 817bbf9bedcb1..c6eaeb78a7c1e 100644 --- a/x-pack/plugins/uptime/public/apps/uptime_page_template.tsx +++ b/x-pack/plugins/uptime/public/apps/uptime_page_template.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; import styled from 'styled-components'; import { EuiPageHeaderProps } from '@elastic/eui'; import { CERTIFICATES_ROUTE, OVERVIEW_ROUTE } from '../../common/constants'; @@ -15,6 +15,7 @@ import { useNoDataConfig } from './use_no_data_config'; import { EmptyStateLoading } from '../components/overview/empty_state/empty_state_loading'; import { EmptyStateError } from '../components/overview/empty_state/empty_state_error'; import { useHasData } from '../components/overview/empty_state/use_has_data'; +import { useInspectorContext } from '../../../observability/public'; interface Props { path: string; @@ -39,6 +40,11 @@ export const UptimePageTemplateComponent: React.FC = ({ path, pageHeader, const noDataConfig = useNoDataConfig(); const { loading, error, data } = useHasData(); + const { inspectorAdapters } = useInspectorContext(); + + useEffect(() => { + inspectorAdapters.requests.reset(); + }, [inspectorAdapters.requests]); if (error) { return ; diff --git a/x-pack/plugins/uptime/public/components/certificates/use_cert_search.ts b/x-pack/plugins/uptime/public/components/certificates/use_cert_search.ts index 22531faff2da1..c4379e550b47a 100644 --- a/x-pack/plugins/uptime/public/components/certificates/use_cert_search.ts +++ b/x-pack/plugins/uptime/public/components/certificates/use_cert_search.ts @@ -7,7 +7,7 @@ import { useSelector } from 'react-redux'; import { useContext } from 'react'; -import { useEsSearch, createEsParams } from '../../../../observability/public'; +import { createEsParams, useEsSearch } from '../../../../observability/public'; import { CertResult, GetCertsParams, Ping } from '../../../common/runtime_types'; @@ -48,13 +48,13 @@ export const useCertSearch = ({ body: searchBody, }); - const { data: result, loading } = useEsSearch(esParams, [ - settings.settings?.heartbeatIndices, - size, - pageIndex, - lastRefresh, - search, - ]); + const { data: result, loading } = useEsSearch( + esParams, + [settings.settings?.heartbeatIndices, size, pageIndex, lastRefresh, search], + { + name: 'getTLSCertificates', + } + ); return result ? { ...processCertsResult(result), loading } : { certs: [], total: 0, loading }; }; diff --git a/x-pack/plugins/uptime/public/components/common/header/action_menu_content.tsx b/x-pack/plugins/uptime/public/components/common/header/action_menu_content.tsx index c459fe46da975..21ef3428696e9 100644 --- a/x-pack/plugins/uptime/public/components/common/header/action_menu_content.tsx +++ b/x-pack/plugins/uptime/public/components/common/header/action_menu_content.tsx @@ -18,6 +18,7 @@ import { useGetUrlParams } from '../../../hooks'; import { ToggleAlertFlyoutButton } from '../../overview/alerts/alerts_containers'; import { SETTINGS_ROUTE } from '../../../../common/constants'; import { stringifyUrlParams } from '../../../lib/helper/stringify_url_params'; +import { InspectorHeaderLink } from './inspector_header_link'; import { monitorStatusSelector } from '../../../state/selectors'; const ADD_DATA_LABEL = i18n.translate('xpack.uptime.addDataButtonLabel', { @@ -107,6 +108,7 @@ export function ActionMenuContent(): React.ReactElement { > {ADD_DATA_LABEL} + ); } diff --git a/x-pack/plugins/uptime/public/components/common/header/inspector_header_link.tsx b/x-pack/plugins/uptime/public/components/common/header/inspector_header_link.tsx new file mode 100644 index 0000000000000..8f787512aaf9d --- /dev/null +++ b/x-pack/plugins/uptime/public/components/common/header/inspector_header_link.tsx @@ -0,0 +1,39 @@ +/* + * 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 { EuiHeaderLink } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import React from 'react'; +import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'; +import { enableInspectEsQueries, useInspectorContext } from '../../../../../observability/public'; +import { ClientPluginsStart } from '../../../apps/plugin'; + +export function InspectorHeaderLink() { + const { + services: { inspector, uiSettings }, + } = useKibana(); + + const { inspectorAdapters } = useInspectorContext(); + + const isInspectorEnabled = uiSettings?.get(enableInspectEsQueries); + + const inspect = () => { + inspector.open(inspectorAdapters); + }; + + if (!isInspectorEnabled) { + return null; + } + + return ( + + {i18n.translate('xpack.uptime.inspectButtonText', { + defaultMessage: 'Inspect', + })} + + ); +} diff --git a/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout.test.tsx b/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout.test.tsx index d066bf416e083..29c4a852e208b 100644 --- a/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout.test.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/ml/ml_flyout.test.tsx @@ -33,6 +33,7 @@ describe('ML Flyout component', () => { spy1.mockReturnValue(false); const value = { + isDevMode: true, basePath: '', dateRangeStart: DATE_RANGE_START, dateRangeEnd: DATE_RANGE_END, @@ -48,6 +49,7 @@ describe('ML Flyout component', () => { onClose={onClose} canCreateMLJob={true} /> + uptime/public/state/api/utils.ts ); @@ -57,6 +59,7 @@ describe('ML Flyout component', () => { it('able to create job if valid license is available', async () => { const value = { + isDevMode: true, basePath: '', dateRangeStart: DATE_RANGE_START, dateRangeEnd: DATE_RANGE_END, diff --git a/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.test.tsx b/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.test.tsx index 8b23d867572f3..441ede99fd8b4 100644 --- a/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.test.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.test.tsx @@ -87,7 +87,8 @@ describe('useStepWaterfallMetrics', () => { }, index: 'heartbeat-*', }, - ['heartbeat-*', '44D-444FFF-444-FFF-3333', true] + ['heartbeat-*', '44D-444FFF-444-FFF-3333', true], + { name: 'getWaterfallStepMetrics' } ); expect(result.current).toEqual({ loading: false, diff --git a/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.ts b/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.ts index cf60f6d7d5567..ad2762826c91f 100644 --- a/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.ts +++ b/x-pack/plugins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.ts @@ -57,7 +57,10 @@ export const useStepWaterfallMetrics = ({ checkGroup, hasNavigationRequest, step }, }) : {}, - [heartbeatIndices, checkGroup, hasNavigationRequest] + [heartbeatIndices, checkGroup, hasNavigationRequest], + { + name: 'getWaterfallStepMetrics', + } ); if (!hasNavigationRequest) { diff --git a/x-pack/plugins/uptime/public/components/overview/filter_group/filter_group.tsx b/x-pack/plugins/uptime/public/components/overview/filter_group/filter_group.tsx index 3980b4bf9d3da..835cbb8060142 100644 --- a/x-pack/plugins/uptime/public/components/overview/filter_group/filter_group.tsx +++ b/x-pack/plugins/uptime/public/components/overview/filter_group/filter_group.tsx @@ -8,9 +8,10 @@ import React, { useCallback, useState } from 'react'; import { EuiFilterGroup } from '@elastic/eui'; import styled from 'styled-components'; +import { capitalize } from 'lodash'; import { useFilterUpdate } from '../../../hooks/use_filter_update'; import { useSelectedFilters } from '../../../hooks/use_selected_filters'; -import { FieldValueSuggestions } from '../../../../../observability/public'; +import { FieldValueSuggestions, useInspectorContext } from '../../../../../observability/public'; import { SelectedFilters } from './selected_filters'; import { useIndexPattern } from '../../../contexts/uptime_index_pattern_context'; import { useGetUrlParams } from '../../../hooks'; @@ -34,6 +35,8 @@ export const FilterGroup = () => { const { dateRangeStart, dateRangeEnd } = useGetUrlParams(); + const { inspectorAdapters } = useInspectorContext(); + const { filtersList } = useSelectedFilters(); const indexPattern = useIndexPattern(); @@ -67,6 +70,10 @@ export const FilterGroup = () => { filters={[]} cardinalityField="monitor.id" time={{ from: dateRangeStart, to: dateRangeEnd }} + inspector={{ + adapter: inspectorAdapters.requests, + title: 'get' + capitalize(label) + 'FilterValues', + }} /> ))} diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/use_monitor_histogram.ts b/x-pack/plugins/uptime/public/components/overview/monitor_list/use_monitor_histogram.ts index e1ef3d9efee89..a3985fe5ccca5 100644 --- a/x-pack/plugins/uptime/public/components/overview/monitor_list/use_monitor_histogram.ts +++ b/x-pack/plugins/uptime/public/components/overview/monitor_list/use_monitor_histogram.ts @@ -37,10 +37,13 @@ export const useMonitorHistogram = ({ items }: { items: MonitorSummary[] }) => { monitorIds ); - const { data, loading } = useEsSearch(queryParams, [ - JSON.stringify(monitorIds), - lastRefresh, - ]); + const { data, loading } = useEsSearch( + queryParams, + [JSON.stringify(monitorIds), lastRefresh], + { + name: 'getMonitorDownHistory', + } + ); const histogramBuckets = data?.aggregations?.histogram.buckets ?? []; const simplified = histogramBuckets.map((histogramBucket) => { diff --git a/x-pack/plugins/uptime/public/routes.tsx b/x-pack/plugins/uptime/public/routes.tsx index 9f7310b43e556..54f2110c88bc4 100644 --- a/x-pack/plugins/uptime/public/routes.tsx +++ b/x-pack/plugins/uptime/public/routes.tsx @@ -39,6 +39,8 @@ import { StepDetailPageRightSideItem, } from './pages/synthetics/step_detail_page'; import { UptimePageTemplateComponent } from './apps/uptime_page_template'; +import { apiService } from './state/api/utils'; +import { useInspectorContext } from '../../observability/public'; interface RouteProps { path: string; @@ -178,6 +180,10 @@ const RouteInit: React.FC> = }; export const PageRouter: FC = () => { + const { addInspectorRequest } = useInspectorContext(); + + apiService.addInspectorRequest = addInspectorRequest; + return ( {Routes.map( diff --git a/x-pack/plugins/uptime/public/state/api/snapshot.test.ts b/x-pack/plugins/uptime/public/state/api/snapshot.test.ts index 6c10bd0fa3cb7..38be97d74844f 100644 --- a/x-pack/plugins/uptime/public/state/api/snapshot.test.ts +++ b/x-pack/plugins/uptime/public/state/api/snapshot.test.ts @@ -18,6 +18,7 @@ describe('snapshot API', () => { get: jest.fn(), fetch: jest.fn(), } as any; + apiService.addInspectorRequest = jest.fn(); fetchMock = jest.spyOn(apiService.http, 'fetch'); mockResponse = { up: 3, down: 12, total: 15 }; }); diff --git a/x-pack/plugins/uptime/public/state/api/utils.ts b/x-pack/plugins/uptime/public/state/api/utils.ts index 91e017292d00f..d10064f1ff7a1 100644 --- a/x-pack/plugins/uptime/public/state/api/utils.ts +++ b/x-pack/plugins/uptime/public/state/api/utils.ts @@ -9,7 +9,7 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; import { isRight } from 'fp-ts/lib/Either'; import { HttpFetchQuery, HttpSetup } from 'src/core/public'; import * as t from 'io-ts'; -import { startsWith } from 'lodash'; +import { FETCH_STATUS, AddInspectorRequest } from '../../../../observability/public'; function isObject(value: unknown) { const type = typeof value; @@ -43,6 +43,7 @@ export const formatErrors = (errors: t.Errors): string[] => { class ApiService { private static instance: ApiService; private _http!: HttpSetup; + private _addInspectorRequest!: AddInspectorRequest; public get http() { return this._http; @@ -52,6 +53,14 @@ class ApiService { this._http = httpSetup; } + public get addInspectorRequest() { + return this._addInspectorRequest; + } + + public set addInspectorRequest(addInspectorRequest: AddInspectorRequest) { + this._addInspectorRequest = addInspectorRequest; + } + private constructor() {} static getInstance(): ApiService { @@ -63,15 +72,14 @@ class ApiService { } public async get(apiUrl: string, params?: HttpFetchQuery, decodeType?: any, asResponse = false) { - const debugEnabled = - sessionStorage.getItem('uptime_debug') === 'true' && startsWith(apiUrl, '/api/uptime'); - const response = await this._http!.fetch({ path: apiUrl, - query: { ...params, ...(debugEnabled ? { _inspect: true } : {}) }, + query: params, asResponse, }); + this.addInspectorRequest?.({ data: response, status: FETCH_STATUS.SUCCESS, loading: false }); + if (decodeType) { const decoded = decodeType.decode(response); if (isRight(decoded)) { diff --git a/x-pack/plugins/uptime/server/lib/lib.ts b/x-pack/plugins/uptime/server/lib/lib.ts index 9b8ea6b98c8be..eb2ad9ce21b9e 100644 --- a/x-pack/plugins/uptime/server/lib/lib.ts +++ b/x-pack/plugins/uptime/server/lib/lib.ts @@ -18,6 +18,9 @@ import { UMLicenseCheck } from './domains'; import { UptimeRequests } from './requests'; import { savedObjectsAdapter } from './saved_objects'; import { ESSearchResponse } from '../../../../../src/core/types/elasticsearch'; +import { RequestStatus } from '../../../../../src/plugins/inspector'; +import { getInspectResponse } from '../../../observability/server'; +import { InspectResponse } from '../../../observability/typings/common'; export interface UMDomainLibs { requests: UptimeRequests; @@ -45,6 +48,8 @@ export interface CountResponse { export type UptimeESClient = ReturnType; +export const inspectableEsQueriesMap = new WeakMap(); + export function createUptimeESClient({ esClient, request, @@ -59,7 +64,8 @@ export function createUptimeESClient({ return { baseESClient: esClient, async search( - params: TParams + params: TParams, + operationName?: string ): Promise<{ body: ESSearchResponse }> { let res: any; let esError: any; @@ -70,11 +76,33 @@ export function createUptimeESClient({ const esParams = { index: dynamicSettings!.heartbeatIndices, ...params }; const startTime = process.hrtime(); + const startTimeNow = Date.now(); + + let esRequestStatus: RequestStatus = RequestStatus.PENDING; + try { res = await esClient.search(esParams); + esRequestStatus = RequestStatus.OK; } catch (e) { esError = e; + esRequestStatus = RequestStatus.ERROR; } + + const inspectableEsQueries = inspectableEsQueriesMap.get(request!); + if (inspectableEsQueries) { + inspectableEsQueries.push( + getInspectResponse({ + esError, + esRequestParams: esParams, + esRequestStatus, + esResponse: res.body, + kibanaRequest: request!, + operationName: operationName ?? '', + startTime: startTimeNow, + }) + ); + } + if (_inspect && request) { debugESCall({ startTime, request, esError, operationName: 'search', params: esParams }); } diff --git a/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts b/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts index 107a0f29e55fa..600a335effe2c 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts @@ -87,7 +87,7 @@ export const getPingHistogram: UMElasticsearchQueryFn { diff --git a/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts b/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts index aef01f29f4d57..ee4e3eb96eb5a 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts @@ -43,9 +43,12 @@ export const getSnapshotCount: UMElasticsearchQueryFn => { - const { body: res } = await context.search({ - body: statusCountBody(await context.dateAndCustomFilters(), context), - }); + const { body: res } = await context.search( + { + body: statusCountBody(await context.dateAndCustomFilters(), context), + }, + 'geSnapshotCount' + ); return ( (res.aggregations?.counts?.value as Snapshot) ?? { diff --git a/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts b/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts index 179e9e809e59b..d0d8e61d02181 100644 --- a/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts +++ b/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts @@ -40,7 +40,7 @@ const query = async (queryContext: QueryContext, searchAfter: any, size: number) body, }; - const response = await queryContext.search(params); + const response = await queryContext.search(params, 'getMonitorList-potentialMatches'); return response; }; diff --git a/x-pack/plugins/uptime/server/lib/requests/search/query_context.ts b/x-pack/plugins/uptime/server/lib/requests/search/query_context.ts index 0bc503093f131..84c170363b1ee 100644 --- a/x-pack/plugins/uptime/server/lib/requests/search/query_context.ts +++ b/x-pack/plugins/uptime/server/lib/requests/search/query_context.ts @@ -43,8 +43,8 @@ export class QueryContext { this.query = query; } - async search(params: TParams) { - return this.callES.search(params); + async search(params: TParams, operationName?: string) { + return this.callES.search(params, operationName); } async count(params: any): Promise { diff --git a/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts b/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts index 3ba2a90d07635..f8357e8066573 100644 --- a/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts +++ b/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts @@ -165,5 +165,5 @@ export const query = async ( }, }; - return await queryContext.search(params); + return await queryContext.search(params, 'getMonitorList-refinePotentialMatches'); }; diff --git a/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts b/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts index 29a7a06f1530a..66f6d597344b6 100644 --- a/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts +++ b/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts @@ -5,7 +5,6 @@ * 2.0. */ -import { schema } from '@kbn/config-schema'; import { UMServerLibs } from '../../lib/lib'; import { UMRestApiRouteFactory } from '../types'; import { API_URLS } from '../../../common/constants'; @@ -13,11 +12,7 @@ import { API_URLS } from '../../../common/constants'; export const createGetIndexStatusRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({ method: 'GET', path: API_URLS.INDEX_STATUS, - validate: { - query: schema.object({ - _inspect: schema.maybe(schema.boolean()), - }), - }, + validate: {}, handler: async ({ uptimeEsClient }): Promise => { return await libs.requests.getIndexStatus({ uptimeEsClient }); }, diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts index 36bc5a80ef47a..df8463786449b 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts @@ -21,7 +21,6 @@ export const createMonitorListRoute: UMRestApiRouteFactory = (libs) => ({ statusFilter: schema.maybe(schema.string()), query: schema.maybe(schema.string()), pageSize: schema.number(), - _inspect: schema.maybe(schema.boolean()), }), }, options: { diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts index 77f265d0b81e8..de102f153d650 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts @@ -18,7 +18,6 @@ export const createGetMonitorLocationsRoute: UMRestApiRouteFactory = (libs: UMSe monitorId: schema.string(), dateStart: schema.string(), dateEnd: schema.string(), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts index 94b50386ac216..ac5133fbb7b4e 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts @@ -18,7 +18,6 @@ export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLib monitorId: schema.string(), dateStart: schema.string(), dateEnd: schema.string(), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts index 50712153a5fea..64e9ed504e7cd 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts @@ -18,7 +18,6 @@ export const createGetMonitorDetailsRoute: UMRestApiRouteFactory = (libs: UMServ monitorId: schema.string(), dateStart: schema.maybe(schema.string()), dateEnd: schema.maybe(schema.string()), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, context, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts index e94198ee4e063..8dd9fbb7adb00 100644 --- a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts +++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts @@ -19,7 +19,6 @@ export const createGetMonitorDurationRoute: UMRestApiRouteFactory = (libs: UMSer monitorId: schema.string(), dateStart: schema.string(), dateEnd: schema.string(), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts b/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts index db111390cfaf7..439975a0f5215 100644 --- a/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts +++ b/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts @@ -21,7 +21,6 @@ export const createGetPingHistogramRoute: UMRestApiRouteFactory = (libs: UMServe filters: schema.maybe(schema.string()), bucketSize: schema.maybe(schema.string()), query: schema.maybe(schema.string()), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts b/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts index abb2c85f9ea0c..2be838c5e8658 100644 --- a/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts +++ b/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts @@ -24,7 +24,6 @@ export const createGetPingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) = size: schema.maybe(schema.number()), sort: schema.maybe(schema.string()), status: schema.maybe(schema.string()), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request, response }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshot_blocks.ts b/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshot_blocks.ts index 3127c34590ef5..4b06a13d29f4e 100644 --- a/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshot_blocks.ts +++ b/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshot_blocks.ts @@ -22,9 +22,6 @@ export const createJourneyScreenshotBlocksRoute: UMRestApiRouteFactory = (libs: body: schema.object({ hashes: schema.arrayOf(schema.string()), }), - query: schema.object({ - _inspect: schema.maybe(schema.boolean()), - }), }, handler: async ({ request, response, uptimeEsClient }) => { const { hashes: blockIds } = request.body; diff --git a/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshots.ts b/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshots.ts index 5f0825279ecfa..3e71051816d30 100644 --- a/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshots.ts +++ b/x-pack/plugins/uptime/server/rest_api/pings/journey_screenshots.ts @@ -26,10 +26,6 @@ export const createJourneyScreenshotRoute: UMRestApiRouteFactory = (libs: UMServ params: schema.object({ checkGroup: schema.string(), stepIndex: schema.number(), - _inspect: schema.maybe(schema.boolean()), - }), - query: schema.object({ - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request, response }) => { diff --git a/x-pack/plugins/uptime/server/rest_api/pings/journeys.ts b/x-pack/plugins/uptime/server/rest_api/pings/journeys.ts index 284feda2c662b..7c3dcdfbe845c 100644 --- a/x-pack/plugins/uptime/server/rest_api/pings/journeys.ts +++ b/x-pack/plugins/uptime/server/rest_api/pings/journeys.ts @@ -22,7 +22,6 @@ export const createJourneyRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => syntheticEventTypes: schema.maybe( schema.oneOf([schema.arrayOf(schema.string()), schema.string()]) ), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request, response }): Promise => { @@ -59,7 +58,6 @@ export const createJourneyFailedStepsRoute: UMRestApiRouteFactory = (libs: UMSer validate: { query: schema.object({ checkGroups: schema.arrayOf(schema.string()), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request, response }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts b/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts index 67b106fdf6814..2fae13db7fa0d 100644 --- a/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts +++ b/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts @@ -19,7 +19,6 @@ export const createGetSnapshotCount: UMRestApiRouteFactory = (libs: UMServerLibs dateRangeEnd: schema.string(), filters: schema.maybe(schema.string()), query: schema.maybe(schema.string()), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/synthetics/last_successful_step.ts b/x-pack/plugins/uptime/server/rest_api/synthetics/last_successful_step.ts index cb90de50e2510..5d1407a8679c8 100644 --- a/x-pack/plugins/uptime/server/rest_api/synthetics/last_successful_step.ts +++ b/x-pack/plugins/uptime/server/rest_api/synthetics/last_successful_step.ts @@ -22,7 +22,6 @@ export const createLastSuccessfulStepRoute: UMRestApiRouteFactory = (libs: UMSer monitorId: schema.string(), stepIndex: schema.number(), timestamp: schema.string(), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ uptimeEsClient, request, response }) => { diff --git a/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts b/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts index 088cf494efbf7..ec7de05dd2cf1 100644 --- a/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts +++ b/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts @@ -22,7 +22,6 @@ export const createLogPageViewRoute: UMRestApiRouteFactory = () => ({ autoRefreshEnabled: schema.boolean(), autorefreshInterval: schema.number(), refreshTelemetryHistory: schema.maybe(schema.boolean()), - _inspect: schema.maybe(schema.boolean()), }), }, handler: async ({ savedObjectsClient, uptimeEsClient, request }): Promise => { diff --git a/x-pack/plugins/uptime/server/rest_api/uptime_route_wrapper.ts b/x-pack/plugins/uptime/server/rest_api/uptime_route_wrapper.ts index 24e501a1bddb8..ddde993cc9c70 100644 --- a/x-pack/plugins/uptime/server/rest_api/uptime_route_wrapper.ts +++ b/x-pack/plugins/uptime/server/rest_api/uptime_route_wrapper.ts @@ -6,10 +6,11 @@ */ import { UMKibanaRouteWrapper } from './types'; -import { createUptimeESClient } from '../lib/lib'; +import { createUptimeESClient, inspectableEsQueriesMap } from '../lib/lib'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { KibanaResponse } from '../../../../../src/core/server/http/router'; +import { enableInspectEsQueries } from '../../../observability/common'; export const uptimeRouteWrapper: UMKibanaRouteWrapper = (uptimeRoute) => ({ ...uptimeRoute, @@ -20,11 +21,18 @@ export const uptimeRouteWrapper: UMKibanaRouteWrapper = (uptimeRoute) => ({ const { client: esClient } = context.core.elasticsearch; const { client: savedObjectsClient } = context.core.savedObjects; + const isInspectorEnabled = await context.core.uiSettings.client.get( + enableInspectEsQueries + ); + const uptimeEsClient = createUptimeESClient({ request, savedObjectsClient, esClient: esClient.asCurrentUser, }); + if (isInspectorEnabled) { + inspectableEsQueriesMap.set(request, []); + } const res = await uptimeRoute.handler({ uptimeEsClient, @@ -41,6 +49,7 @@ export const uptimeRouteWrapper: UMKibanaRouteWrapper = (uptimeRoute) => ({ return response.ok({ body: { ...res, + ...(isInspectorEnabled ? { _inspect: inspectableEsQueriesMap.get(request) } : {}), }, }); },