diff --git a/NOTICE.txt b/NOTICE.txt
index 4ede43610ca7b..e18cfe6f0a1da 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
Kibana source code with Kibana X-Pack source code
-Copyright 2012-2021 Elasticsearch B.V.
+Copyright 2012-2022 Elasticsearch B.V.
---
Pretty handling of logarithmic axes.
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.handleresponse.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.handleresponse.md
new file mode 100644
index 0000000000000..59cdd63046d85
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.handleresponse.md
@@ -0,0 +1,23 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [handleResponse](./kibana-plugin-plugins-data-public.handleresponse.md)
+
+## handleResponse() function
+
+Signature:
+
+```typescript
+export declare function handleResponse(request: SearchRequest, response: IKibanaSearchResponse): IKibanaSearchResponse;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| request | SearchRequest | |
+| response | IKibanaSearchResponse | |
+
+Returns:
+
+`IKibanaSearchResponse`
+
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md
index bf269ea8c3355..91bf8e0355410 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md
@@ -47,6 +47,7 @@
| [getEsPreference(uiSettings, sessionId)](./kibana-plugin-plugins-data-public.getespreference.md) | |
| [getSearchParamsFromRequest(searchRequest, dependencies)](./kibana-plugin-plugins-data-public.getsearchparamsfromrequest.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-public.gettime.md) | |
+| [handleResponse(request, response)](./kibana-plugin-plugins-data-public.handleresponse.md) | |
| [isEsError(e)](./kibana-plugin-plugins-data-public.iseserror.md) | Checks if a given errors originated from Elasticsearch. Those params are assigned to the attributes property of an error. |
| [plugin(initializerContext)](./kibana-plugin-plugins-data-public.plugin.md) | |
| [waitUntilNextSessionCompletes$(sessionService, { waitForIdle })](./kibana-plugin-plugins-data-public.waituntilnextsessioncompletes_.md) | Creates an observable that emits when next search session completes. This utility is helpful to use in the application to delay some tasks until next session completes. |
diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts
index 0843e4d587503..940f4a25aa9c1 100644
--- a/src/plugins/data/public/index.ts
+++ b/src/plugins/data/public/index.ts
@@ -396,6 +396,7 @@ export {
isEsError,
SearchSessionState,
SortDirection,
+ handleResponse,
} from './search';
export type {
diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md
index 0cc0b9d84151e..1ab6cc5b9f760 100644
--- a/src/plugins/data/public/public.api.md
+++ b/src/plugins/data/public/public.api.md
@@ -47,6 +47,7 @@ import { HttpSetup } from 'kibana/public';
import { IAggConfigs as IAggConfigs_2 } from 'src/plugins/data/public';
import { IconType } from '@elastic/eui';
import { IEsSearchResponse as IEsSearchResponse_2 } from 'src/plugins/data/public';
+import { IKibanaSearchResponse as IKibanaSearchResponse_2 } from 'src/plugins/data/common';
import { IncomingHttpHeaders } from 'http';
import { InjectedIntl } from '@kbn/i18n/react';
import { ISearchOptions as ISearchOptions_2 } from 'src/plugins/data/public';
@@ -1154,6 +1155,12 @@ export function getTime(indexPattern: IIndexPattern | undefined, timeRange: Time
fieldName?: string;
}): import("../..").RangeFilter | undefined;
+// Warning: (ae-incompatible-release-tags) The symbol "handleResponse" is marked as @public, but its signature references "SearchRequest" which is marked as @internal
+// Warning: (ae-missing-release-tag) "handleResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
+//
+// @public (undocumented)
+export function handleResponse(request: SearchRequest, response: IKibanaSearchResponse_2): IKibanaSearchResponse_2;
+
// Warning: (ae-missing-release-tag) "IAggConfig" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
@@ -2805,20 +2812,20 @@ export interface WaitUntilNextSessionCompletesOptions {
// src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:412:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:412:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:412:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:414:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:415:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:424:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:425:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:426:1 - (ae-forgotten-export) The symbol "IpAddress" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:427:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:431:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:432:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:435:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:436:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
-// src/plugins/data/public/index.ts:439:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:413:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:413:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:413:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:415:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:416:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:425:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:426:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:427:1 - (ae-forgotten-export) The symbol "IpAddress" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:428:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:432:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:433:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:436:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:437:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
+// src/plugins/data/public/index.ts:440:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:34:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/search/session/session_service.ts:62:5 - (ae-forgotten-export) The symbol "UrlGeneratorStateMapping" needs to be exported by the entry point index.d.ts
diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts
index 21d607eedb152..cdb16cc7d9f2c 100644
--- a/src/plugins/data/public/search/index.ts
+++ b/src/plugins/data/public/search/index.ts
@@ -51,3 +51,5 @@ export { getEsPreference } from './es_search';
export { SearchInterceptor, SearchInterceptorDeps } from './search_interceptor';
export * from './errors';
+
+export { handleResponse } from './fetch';
diff --git a/src/plugins/vis_type_timeseries/common/types/index.ts b/src/plugins/vis_type_timeseries/common/types/index.ts
index 2236e57e47044..963b108372d70 100644
--- a/src/plugins/vis_type_timeseries/common/types/index.ts
+++ b/src/plugins/vis_type_timeseries/common/types/index.ts
@@ -10,7 +10,15 @@ import { IndexPattern, Query } from '../../../data/common';
import { Panel } from './panel_model';
export { Metric, Series, Panel } from './panel_model';
-export { TimeseriesVisData, PanelData, SeriesData, TableData } from './vis_data';
+export type {
+ TimeseriesVisData,
+ PanelData,
+ SeriesData,
+ TableData,
+ DataResponseMeta,
+ TrackedEsSearches,
+ PanelSeries,
+} from './vis_data';
export interface FetchedIndexPattern {
indexPattern: IndexPattern | undefined | null;
diff --git a/src/plugins/vis_type_timeseries/common/types/vis_data.ts b/src/plugins/vis_type_timeseries/common/types/vis_data.ts
index 70433ccbab7bf..2d33277f8e788 100644
--- a/src/plugins/vis_type_timeseries/common/types/vis_data.ts
+++ b/src/plugins/vis_type_timeseries/common/types/vis_data.ts
@@ -7,27 +7,35 @@
*/
import { PANEL_TYPES } from '../enums';
-import { TimeseriesUIRestrictions } from '../ui_restrictions';
+import type { TimeseriesUIRestrictions } from '../ui_restrictions';
export type TimeseriesVisData = SeriesData | TableData;
-export interface TableData {
- type: PANEL_TYPES.TABLE;
+export type TrackedEsSearches = Record<
+ string,
+ {
+ body: Record;
+ response?: Record;
+ }
+>;
+
+export interface DataResponseMeta {
+ type: PANEL_TYPES;
uiRestrictions: TimeseriesUIRestrictions;
+ trackedEsSearches: TrackedEsSearches;
+}
+
+export interface TableData extends DataResponseMeta {
series?: PanelData[];
pivot_label?: string;
}
// series data is not fully typed yet
-export type SeriesData = {
- type: Exclude;
- uiRestrictions: TimeseriesUIRestrictions;
+export type SeriesData = DataResponseMeta & {
error?: string;
-} & {
- [key: string]: PanelSeries;
-};
+} & Record;
-interface PanelSeries {
+export interface PanelSeries {
annotations: {
[key: string]: unknown[];
};
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
index 86d1758932301..682279d5639e5 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
@@ -37,7 +37,7 @@ export const FieldTextSelect = ({
useDebounce(
() => {
- if (inputValue !== indexPatternString) {
+ if ((inputValue ?? '') !== (indexPatternString ?? '')) {
onIndexChange(inputValue);
}
},
diff --git a/src/plugins/vis_type_timeseries/public/request_handler.ts b/src/plugins/vis_type_timeseries/public/request_handler.ts
index 4cd297a597dfc..0ca5e14046312 100644
--- a/src/plugins/vis_type_timeseries/public/request_handler.ts
+++ b/src/plugins/vis_type_timeseries/public/request_handler.ts
@@ -12,7 +12,7 @@ import { ROUTES } from '../common/constants';
import type { TimeseriesVisParams } from './types';
import type { TimeseriesVisData } from '../common/types';
-import type { KibanaContext } from '../../data/public';
+import { KibanaContext, handleResponse } from '../../data/public';
interface MetricsRequestHandlerParams {
input: KibanaContext | null;
@@ -46,7 +46,7 @@ export const metricsRequestHandler = async ({
try {
const searchSessionOptions = dataSearch.session.getSearchOptions(searchSessionId);
- return await getCoreStart().http.post(ROUTES.VIS_DATA, {
+ const visData: TimeseriesVisData = await getCoreStart().http.post(ROUTES.VIS_DATA, {
body: JSON.stringify({
timerange: {
timezone,
@@ -61,6 +61,14 @@ export const metricsRequestHandler = async ({
}),
}),
});
+
+ Object.entries(visData.trackedEsSearches || {}).forEach(([key, query]) => {
+ if (query.response) {
+ handleResponse({ body: query.body }, { rawResponse: query.response });
+ }
+ });
+
+ return visData;
} finally {
if (untrackSearch && dataSearch.session.isCurrentSession(searchSessionId)) {
// untrack if this search still belongs to current session
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/index.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/index.ts
index 0f72b8907ec76..6f49eca49d51b 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/index.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/index.ts
@@ -8,5 +8,6 @@
export { SearchStrategyRegistry } from './search_strategy_registry';
export { DefaultSearchCapabilities } from './capabilities/default_search_capabilities';
-
export { AbstractSearchStrategy, RollupSearchStrategy, DefaultSearchStrategy } from './strategies';
+
+export type { EsSearchRequest } from './strategies/abstract_search_strategy';
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts
index 7add5cb4a4553..ba0db95ed5885 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts
@@ -9,8 +9,8 @@
import { IndexPatternsService } from '../../../../../data/common';
import { from } from 'rxjs';
-import { AbstractSearchStrategy } from './abstract_search_strategy';
-import type { IFieldType } from '../../../../../data/common';
+import { AbstractSearchStrategy, EsSearchRequest } from './abstract_search_strategy';
+import type { FieldSpec } from '../../../../../data/common';
import type { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
import type {
VisTypeTimeseriesRequestHandlerContext,
@@ -21,7 +21,7 @@ class FooSearchStrategy extends AbstractSearchStrategy {}
describe('AbstractSearchStrategy', () => {
let abstractSearchStrategy: AbstractSearchStrategy;
- let mockedFields: IFieldType[];
+ let mockedFields: FieldSpec[];
let requestContext: VisTypeTimeseriesRequestHandlerContext;
beforeEach(() => {
@@ -64,7 +64,7 @@ describe('AbstractSearchStrategy', () => {
});
test('should return response', async () => {
- const searches = [{ body: 'body', index: 'index' }];
+ const searches: EsSearchRequest[] = [{ body: {}, index: 'index' }];
const responses = await abstractSearchStrategy.search(
requestContext,
@@ -84,7 +84,7 @@ describe('AbstractSearchStrategy', () => {
expect(requestContext.search.search).toHaveBeenCalledWith(
{
params: {
- body: 'body',
+ body: {},
index: 'index',
},
indexType: undefined,
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
index 26c3a6c7c8bf7..cf2fbef746bce 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
@@ -6,40 +6,63 @@
* Side Public License, v 1.
*/
+import { tap } from 'rxjs/operators';
+import { omit } from 'lodash';
import { IndexPatternsService } from '../../../../../data/server';
import { toSanitizedFieldType } from '../../../../common/fields_utils';
-import type { FetchedIndexPattern } from '../../../../common/types';
+import type { FetchedIndexPattern, TrackedEsSearches } from '../../../../common/types';
import type {
VisTypeTimeseriesRequest,
VisTypeTimeseriesRequestHandlerContext,
VisTypeTimeseriesVisDataRequest,
} from '../../../types';
+export interface EsSearchRequest {
+ body: Record;
+ index?: string;
+ trackingEsSearchMeta?: {
+ requestId: string;
+ };
+}
+
export abstract class AbstractSearchStrategy {
async search(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesVisDataRequest,
- bodies: any[],
+ esRequests: EsSearchRequest[],
+ trackedEsSearches?: TrackedEsSearches,
indexType?: string
) {
const requests: any[] = [];
- bodies.forEach((body) => {
+ esRequests.forEach(({ body, index, trackingEsSearchMeta }) => {
requests.push(
requestContext.search
.search(
{
indexType,
params: {
- ...body,
+ body,
+ index,
},
},
req.body.searchSession
)
+ .pipe(
+ tap((data) => {
+ if (trackingEsSearchMeta?.requestId && trackedEsSearches) {
+ trackedEsSearches[trackingEsSearchMeta.requestId] = {
+ body,
+ response: omit(data.rawResponse, 'aggregations'),
+ };
+ }
+ })
+ )
.toPromise()
);
});
+
return Promise.all(requests);
}
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts
index 0ac00863d0a73..6c2219553d9bf 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts
@@ -7,10 +7,10 @@
*/
import { getCapabilitiesForRollupIndices, IndexPatternsService } from '../../../../../data/server';
-import { AbstractSearchStrategy } from './abstract_search_strategy';
+import { AbstractSearchStrategy, EsSearchRequest } from './abstract_search_strategy';
import { RollupSearchCapabilities } from '../capabilities/rollup_search_capabilities';
-import type { FetchedIndexPattern } from '../../../../common/types';
+import type { FetchedIndexPattern, TrackedEsSearches } from '../../../../common/types';
import type { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
import type {
VisTypeTimeseriesRequest,
@@ -26,9 +26,10 @@ export class RollupSearchStrategy extends AbstractSearchStrategy {
async search(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesVisDataRequest,
- bodies: any[]
+ esRequests: EsSearchRequest[],
+ trackedEsSearches?: TrackedEsSearches
) {
- return super.search(requestContext, req, bodies, 'rollup');
+ return super.search(requestContext, req, esRequests, trackedEsSearches, 'rollup');
}
async getRollupData(
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/annotations/get_request_params.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/annotations/get_request_params.ts
index c4abbbd4333f4..79500edb620b4 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/annotations/get_request_params.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/annotations/get_request_params.ts
@@ -13,7 +13,12 @@ import {
VisTypeTimeseriesRequestServices,
VisTypeTimeseriesVisDataRequest,
} from '../../../types';
-import { AbstractSearchStrategy, DefaultSearchCapabilities } from '../../search_strategies';
+
+import {
+ AbstractSearchStrategy,
+ DefaultSearchCapabilities,
+ EsSearchRequest,
+} from '../../search_strategies';
export type AnnotationServices = VisTypeTimeseriesRequestServices & {
capabilities: DefaultSearchCapabilities;
@@ -32,7 +37,7 @@ export async function getAnnotationRequestParams(
uiSettings,
cachedIndexPatternFetcher,
}: AnnotationServices
-) {
+): Promise {
const annotationIndex = await cachedIndexPatternFetcher(annotation.index_pattern);
const request = await buildAnnotationRequest(
@@ -47,6 +52,9 @@ export async function getAnnotationRequestParams(
return {
index: annotationIndex.indexPatternString,
+ trackingEsSearchMeta: {
+ requestId: annotation.id,
+ },
body: {
...request,
runtime_mappings: annotationIndex.indexPattern?.getComputedFields().runtimeFields ?? {},
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_annotations.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_annotations.ts
index 212e1a5254358..2394173194c7d 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_annotations.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_annotations.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import type { Annotation, Panel, Series } from '../../../common/types';
+import type { Annotation, Panel, Series, TrackedEsSearches } from '../../../common/types';
// @ts-expect-error
import { handleAnnotationResponse } from './response_processors/annotations';
import { AnnotationServices, getAnnotationRequestParams } from './annotations/get_request_params';
@@ -23,26 +23,33 @@ interface GetAnnotationsParams {
panel: Panel;
series: Series[];
services: AnnotationServices;
+ trackedEsSearches: TrackedEsSearches;
}
-export async function getAnnotations({ req, panel, series, services }: GetAnnotationsParams) {
+export async function getAnnotations({
+ req,
+ panel,
+ series,
+ services,
+ trackedEsSearches,
+}: GetAnnotationsParams) {
const annotations = panel.annotations!.filter(validAnnotation);
const lastSeriesTimestamp = getLastSeriesTimestamp(series);
const handleAnnotationResponseBy = handleAnnotationResponse(lastSeriesTimestamp);
- const bodiesPromises = annotations.map((annotation) =>
- getAnnotationRequestParams(req, panel, annotation, services)
- );
-
- const searches = (await Promise.all(bodiesPromises)).reduce(
- (acc, items) => acc.concat(items as any),
- []
+ const searches = await Promise.all(
+ annotations.map((annotation) => getAnnotationRequestParams(req, panel, annotation, services))
);
if (!searches.length) return { responses: [] };
try {
- const data = await services.searchStrategy.search(services.requestContext, req, searches);
+ const data = await services.searchStrategy.search(
+ services.requestContext,
+ req,
+ searches,
+ trackedEsSearches
+ );
return annotations.reduce((acc, annotation, index) => {
acc[annotation.id] = handleAnnotationResponseBy(data[index].rawResponse, annotation);
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
index 8d495d68eb625..e0c94941e5975 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
@@ -18,7 +18,7 @@ import type {
VisTypeTimeseriesVisDataRequest,
VisTypeTimeseriesRequestServices,
} from '../../types';
-import type { Panel } from '../../../common/types';
+import type { DataResponseMeta, Panel } from '../../../common/types';
import { PANEL_TYPES } from '../../../common/enums';
export async function getSeriesData(
@@ -44,9 +44,10 @@ export async function getSeriesData(
}
const { searchStrategy, capabilities } = strategy;
- const meta = {
+ const meta: DataResponseMeta = {
type: panel.type,
uiRestrictions: capabilities.uiRestrictions,
+ trackedEsSearches: {},
};
const handleError = handleErrorResponse(panel);
@@ -57,7 +58,7 @@ export async function getSeriesData(
);
const searches = await Promise.all(bodiesPromises);
- const data = await searchStrategy.search(requestContext, req, searches);
+ const data = await searchStrategy.search(requestContext, req, searches, meta.trackedEsSearches);
const handleResponseBodyFn = handleResponseBody(panel, req, {
indexPatternsService: services.indexPatternsService,
@@ -85,6 +86,7 @@ export async function getSeriesData(
searchStrategy,
capabilities,
},
+ trackedEsSearches: meta.trackedEsSearches,
});
}
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
index 3f8d30f0ed833..b95a163fecb1f 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
@@ -24,7 +24,7 @@ import type {
VisTypeTimeseriesRequestServices,
VisTypeTimeseriesVisDataRequest,
} from '../../types';
-import type { Panel } from '../../../common/types';
+import type { DataResponseMeta, Panel } from '../../../common/types';
export async function getTableData(
requestContext: VisTypeTimeseriesRequestHandlerContext,
@@ -66,9 +66,10 @@ export async function getTableData(
return panel.pivot_id;
};
- const meta = {
+ const meta: DataResponseMeta = {
type: panel.type,
uiRestrictions: capabilities.uiRestrictions,
+ trackedEsSearches: {},
};
const handleError = handleErrorResponse(panel);
@@ -84,15 +85,23 @@ export async function getTableData(
() => services.buildSeriesMetaParams(panelIndex, Boolean(panel.use_kibana_indexes))
);
- const [resp] = await searchStrategy.search(requestContext, req, [
- {
- body: {
- ...body,
- runtime_mappings: panelIndex.indexPattern?.getComputedFields().runtimeFields ?? {},
+ const [resp] = await searchStrategy.search(
+ requestContext,
+ req,
+ [
+ {
+ body: {
+ ...body,
+ runtime_mappings: panelIndex.indexPattern?.getComputedFields().runtimeFields ?? {},
+ },
+ index: panelIndex.indexPatternString,
+ trackingEsSearchMeta: {
+ requestId: panel.id,
+ },
},
- index: panelIndex.indexPatternString,
- },
- ]);
+ ],
+ meta.trackedEsSearches
+ );
const buckets = get(
resp.rawResponse ? resp.rawResponse : resp,
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts
index aedc4ee7c8a15..2d7a75a7177f8 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts
@@ -13,7 +13,7 @@ import type {
VisTypeTimeseriesRequestServices,
VisTypeTimeseriesVisDataRequest,
} from '../../../types';
-import type { DefaultSearchCapabilities } from '../../search_strategies';
+import type { DefaultSearchCapabilities, EsSearchRequest } from '../../search_strategies';
export async function getSeriesRequestParams(
req: VisTypeTimeseriesVisDataRequest,
@@ -28,7 +28,7 @@ export async function getSeriesRequestParams(
cachedIndexPatternFetcher,
buildSeriesMetaParams,
}: VisTypeTimeseriesRequestServices
-) {
+): Promise {
let seriesIndex = panelIndex;
if (series.override_index_pattern) {
@@ -53,5 +53,8 @@ export async function getSeriesRequestParams(
runtime_mappings: seriesIndex.indexPattern?.getComputedFields().runtimeFields ?? {},
timeout: esShardTimeout > 0 ? `${esShardTimeout}ms` : undefined,
},
+ trackingEsSearchMeta: {
+ requestId: series.id,
+ },
};
}
diff --git a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts
index 6009652e2d0b0..eb20a81a873ae 100644
--- a/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts
+++ b/x-pack/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts
@@ -62,7 +62,7 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter {
.then((results) => {
return results.filter(isVisSeriesData).map((result) => {
const metricIds = Object.keys(result).filter(
- (k) => !['type', 'uiRestrictions'].includes(k)
+ (k) => !['type', 'uiRestrictions', 'trackedEsSearches'].includes(k)
);
return metricIds.map((id: string) => {