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

export type {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {
waitUntilNextSessionCompletes$,
} from './session';
export { getEsPreference } from './es_search';
export { handleResponse } from './fetch';

export type { SearchInterceptorDeps } from './search_interceptor';
export { SearchInterceptor } from './search_interceptor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class RequestResponder {
}

public finish(status: RequestStatus, response: Response): void {
this.request.time = Date.now() - this.request.startTime;
this.request.time = response.time ?? Date.now() - this.request.startTime;
this.request.status = status;
this.request.response = response;
this.onChange();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/inspector/common/adapters/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export interface RequestStatistic {

export interface Response {
json?: object;
time?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
type: 'long',
_meta: { description: 'Non-default value of setting.' },
},
'metrics:allowCheckingForFailedShards': {
type: 'boolean',
_meta: { description: 'Non-default value of setting.' },
},
'query:allowLeadingWildcards': {
type: 'boolean',
_meta: { description: 'Non-default value of setting.' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface UsageStats {
'savedObjects:listingLimit': number;
'query:queryString:options': string;
'metrics:max_buckets': number;
'metrics:allowCheckingForFailedShards': boolean;
'query:allowLeadingWildcards': boolean;
metaFields: string[];
'indexPattern:placeholder': string;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7577,6 +7577,12 @@
"description": "Non-default value of setting."
}
},
"metrics:allowCheckingForFailedShards": {
"type": "boolean",
"_meta": {
"description": "Non-default value of setting."
}
},
"query:allowLeadingWildcards": {
"type": "boolean",
"_meta": {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_types/timeseries/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

export const MAX_BUCKETS_SETTING = 'metrics:max_buckets';
export const ALLOW_CHECKING_FOR_FAILED_SHARDS = 'metrics:allowCheckingForFailedShards';
export const INDEXES_SEPARATOR = ',';
export const AUTO_INTERVAL = 'auto';
export const ROUTES = {
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/vis_types/timeseries/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import { Filter, IndexPattern, Query } from '../../../../data/common';
import { Panel } from './panel_model';

export type { Metric, Series, Panel, MetricType } from './panel_model';
export type { 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
32 changes: 20 additions & 12 deletions src/plugins/vis_types/timeseries/common/types/vis_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,38 @@
*/

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>;
label?: string;
time: number;
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>;

export interface PanelSeries {
annotations: {
[key: string]: Annotation[];
};
annotations: Record<string, Annotation[]>;
id: string;
series: PanelData[];
error?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/timeseries/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["charts", "data", "expressions", "visualizations", "visualize"],
"requiredPlugins": ["charts", "data", "expressions", "visualizations", "visualize", "inspector"],
"optionalPlugins": ["usageCollection"],
"requiredBundles": ["kibanaUtils", "kibanaReact", "fieldFormats"],
"owner": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export const AnnotationRow = ({

try {
fetchedIndexPattern = index
? await fetchIndexPattern(index, indexPatterns)
? await fetchIndexPattern(index, indexPatterns, {
fetchKibanaIndexForStringIndexes: true,
})
: {
...fetchedIndexPattern,
defaultIndex: await indexPatterns.getDefault(),
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const IndexPatternSelect = ({
defaultIndexPatternHelpText + (!useKibanaIndices ? queryAllIndexesHelpText : '')
}
labelAppend={
fetchedIndex.indexPatternString && !fetchedIndex.indexPattern ? (
!useKibanaIndices && fetchedIndex.indexPatternString && !fetchedIndex.indexPattern ? (
<EuiLink onClick={navigateToCreateIndexPatternPage}>
<EuiText size="xs">
<FormattedMessage
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/vis_types/timeseries/public/metrics_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const createMetricsFn = (): TimeseriesExpressionFunctionDefinition => ({
help: '',
},
},
async fn(input, args, { getSearchSessionId, isSyncColorsEnabled, getExecutionContext }) {
async fn(
input,
args,
{ getSearchSessionId, isSyncColorsEnabled, getExecutionContext, inspectorAdapters }
) {
const visParams: TimeseriesVisParams = JSON.parse(args.params);
const uiState = JSON.parse(args.uiState);
const syncColors = isSyncColorsEnabled?.() ?? false;
Expand All @@ -65,6 +69,7 @@ export const createMetricsFn = (): TimeseriesExpressionFunctionDefinition => ({
uiState,
searchSessionId: getSearchSessionId(),
executionContext: getExecutionContext(),
inspectorAdapters,
});

return {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/vis_types/timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../../../visualizations/public';
import { getDataStart } from './services';
import type { TimeseriesVisDefaultParams, TimeseriesVisParams } from './types';
import { RequestAdapter } from '../../../inspector/public';

export const withReplacedIds = (
vis: Vis<TimeseriesVisParams | TimeseriesVisDefaultParams>
Expand Down Expand Up @@ -118,7 +119,9 @@ export const metricsVisDefinition: VisTypeDefinition<
}
return [];
},
inspectorAdapters: {},
inspectorAdapters: () => ({
requests: new RequestAdapter(),
}),
requiresSearch: true,
getUsedIndexPattern: async (params: VisParams) => {
const { indexPatterns } = getDataStart();
Expand Down
25 changes: 22 additions & 3 deletions src/plugins/vis_types/timeseries/public/request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
* Side Public License, v 1.
*/
import type { KibanaExecutionContext } from 'src/core/public';
import type { Adapters } from 'src/plugins/inspector';
import { getTimezone } from './application/lib/get_timezone';
import { getUISettings, getDataStart, getCoreStart } from './services';
import { ROUTES } from '../common/constants';
import { ROUTES, ALLOW_CHECKING_FOR_FAILED_SHARDS } from '../common/constants';
import { KibanaContext, handleResponse } from '../../../data/public';

import type { TimeseriesVisParams } from './types';
import type { TimeseriesVisData } from '../common/types';
import type { KibanaContext } from '../../../data/public';

interface MetricsRequestHandlerParams {
input: KibanaContext | null;
uiState: Record<string, any>;
visParams: TimeseriesVisParams;
searchSessionId?: string;
executionContext?: KibanaExecutionContext;
inspectorAdapters?: Adapters;
}

export const metricsRequestHandler = async ({
Expand All @@ -28,6 +30,7 @@ export const metricsRequestHandler = async ({
visParams,
searchSessionId,
executionContext,
inspectorAdapters,
}: MetricsRequestHandlerParams): Promise<TimeseriesVisData | {}> => {
const config = getUISettings();
const data = getDataStart();
Expand All @@ -48,7 +51,8 @@ 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 @@ -64,6 +68,21 @@ export const metricsRequestHandler = async ({
}),
context: executionContext,
});

inspectorAdapters?.requests?.reset();

Object.entries(visData.trackedEsSearches || {}).forEach(([key, query]) => {
inspectorAdapters?.requests
?.start(query.label ?? key, { searchSessionId })
.json(query.body)
.ok({ time: query.time });

if (query.response && config.get(ALLOW_CHECKING_FOR_FAILED_SHARDS)) {
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 @@ -11,6 +11,7 @@ import { AbstractSearchStrategy } from './strategies';

export { SearchStrategyRegistry } from './search_strategy_registry';
export { AbstractSearchStrategy, RollupSearchStrategy, DefaultSearchStrategy } from './strategies';
export type { EsSearchRequest } from './strategies/abstract_search_strategy';

export type SearchCapabilities = DefaultSearchCapabilities;
export type SearchStrategy = AbstractSearchStrategy;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { IndexPatternsService } from '../../../../../../data/common';

import { from } from 'rxjs';
import { AbstractSearchStrategy } from './abstract_search_strategy';
import { AbstractSearchStrategy, EsSearchRequest } from './abstract_search_strategy';
import type { FieldSpec } from '../../../../../../data/common';
import type { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
import type {
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,67 @@
* 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;
requestLabel?: 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 }) => {
const startTime = Date.now();
requests.push(
requestContext.search
.search(
{
indexType,
params: {
...body,
body,
index,
},
},
req.body.searchSession
)
.pipe(
tap((data) => {
if (trackingEsSearchMeta?.requestId && trackedEsSearches) {
trackedEsSearches[trackingEsSearchMeta.requestId] = {
body,
time: Date.now() - startTime,
label: trackingEsSearchMeta.requestLabel,
response: omit(data.rawResponse, 'aggregations'),
};
}
})
)
.toPromise()
);
});

return Promise.all(requests);
}

Expand Down
Loading