Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [handleResponse](./kibana-plugin-plugins-data-public.handleresponse.md)

## handleResponse() function

<b>Signature:</b>

```typescript
export declare function handleResponse(request: SearchRequest, response: IKibanaSearchResponse): IKibanaSearchResponse<any>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | <code>SearchRequest</code> | |
| response | <code>IKibanaSearchResponse</code> | |

<b>Returns:</b>

`IKibanaSearchResponse<any>`

Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ export {
isEsError,
SearchSessionState,
SortDirection,
handleResponse,
} from './search';

export type {
Expand Down
35 changes: 21 additions & 14 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any>;

// Warning: (ae-missing-release-tag) "IAggConfig" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ export { getEsPreference } from './es_search';

export { SearchInterceptor, SearchInterceptorDeps } from './search_interceptor';
export * from './errors';

export { handleResponse } from './fetch';
10 changes: 9 additions & 1 deletion src/plugins/vis_type_timeseries/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 18 additions & 10 deletions src/plugins/vis_type_timeseries/common/types/vis_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
response?: Record<string, any>;
}
>;

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<PANEL_TYPES, PANEL_TYPES.TABLE>;
uiRestrictions: TimeseriesUIRestrictions;
export type SeriesData = DataResponseMeta & {
error?: string;
} & {
[key: string]: PanelSeries;
};
} & Record<string, PanelSeries>;

interface PanelSeries {
export interface PanelSeries {
annotations: {
[key: string]: unknown[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const FieldTextSelect = ({

useDebounce(
() => {
if (inputValue !== indexPatternString) {
if ((inputValue ?? '') !== (indexPatternString ?? '')) {
onIndexChange(inputValue);
}
},
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/vis_type_timeseries/public/request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +21,7 @@ class FooSearchStrategy extends AbstractSearchStrategy {}

describe('AbstractSearchStrategy', () => {
let abstractSearchStrategy: AbstractSearchStrategy;
let mockedFields: IFieldType[];
let mockedFields: FieldSpec[];
let requestContext: VisTypeTimeseriesRequestHandlerContext;

beforeEach(() => {
Expand Down Expand Up @@ -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,
Expand All @@ -84,7 +84,7 @@ describe('AbstractSearchStrategy', () => {
expect(requestContext.search.search).toHaveBeenCalledWith(
{
params: {
body: 'body',
body: {},
index: 'index',
},
indexType: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +37,7 @@ export async function getAnnotationRequestParams(
uiSettings,
cachedIndexPatternFetcher,
}: AnnotationServices
) {
): Promise<EsSearchRequest> {
const annotationIndex = await cachedIndexPatternFetcher(annotation.index_pattern);

const request = await buildAnnotationRequest(
Expand All @@ -47,6 +52,9 @@ export async function getAnnotationRequestParams(

return {
index: annotationIndex.indexPatternString,
trackingEsSearchMeta: {
requestId: annotation.id,
},
body: {
...request,
runtime_mappings: annotationIndex.indexPattern?.getComputedFields().runtimeFields ?? {},
Expand Down
Loading