Skip to content

Commit 2d13d59

Browse files
committed
Merge branch 'task/hide-KQL-bar-when-not-compatible' of github.com:kevinlog/kibana into task/hide-KQL-bar-when-not-compatible
2 parents a73ede9 + 1cf12ea commit 2d13d59

File tree

120 files changed

+3413
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+3413
-528
lines changed

src/plugins/data/public/search/expressions/esaggs.ts

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import { get, hasIn } from 'lodash';
2121
import { i18n } from '@kbn/i18n';
2222
import { KibanaDatatable, KibanaDatatableColumn } from 'src/plugins/expressions/public';
23-
import { calculateObjectHash } from '../../../../../plugins/kibana_utils/public';
2423
import { PersistedState } from '../../../../../plugins/visualizations/public';
2524
import { Adapters } from '../../../../../plugins/inspector/public';
2625

@@ -60,7 +59,6 @@ export interface RequestHandlerParams {
6059
indexPattern?: IIndexPattern;
6160
query?: Query;
6261
filters?: Filter[];
63-
forceFetch: boolean;
6462
filterManager: FilterManager;
6563
uiState?: PersistedState;
6664
partialRows?: boolean;
@@ -80,7 +78,6 @@ const handleCourierRequest = async ({
8078
indexPattern,
8179
query,
8280
filters,
83-
forceFetch,
8481
partialRows,
8582
metricsAtAllLevels,
8683
inspectorAdapters,
@@ -137,46 +134,35 @@ const handleCourierRequest = async ({
137134
requestSearchSource.setField('filter', filters);
138135
requestSearchSource.setField('query', query);
139136

140-
const reqBody = await requestSearchSource.getSearchRequestBody();
141-
142-
const queryHash = calculateObjectHash(reqBody);
143-
// We only need to reexecute the query, if forceFetch was true or the hash of the request body has changed
144-
// since the last request
145-
const shouldQuery = forceFetch || (searchSource as any).lastQuery !== queryHash;
146-
147-
if (shouldQuery) {
148-
inspectorAdapters.requests.reset();
149-
const request = inspectorAdapters.requests.start(
150-
i18n.translate('data.functions.esaggs.inspector.dataRequest.title', {
151-
defaultMessage: 'Data',
137+
inspectorAdapters.requests.reset();
138+
const request = inspectorAdapters.requests.start(
139+
i18n.translate('data.functions.esaggs.inspector.dataRequest.title', {
140+
defaultMessage: 'Data',
141+
}),
142+
{
143+
description: i18n.translate('data.functions.esaggs.inspector.dataRequest.description', {
144+
defaultMessage:
145+
'This request queries Elasticsearch to fetch the data for the visualization.',
152146
}),
153-
{
154-
description: i18n.translate('data.functions.esaggs.inspector.dataRequest.description', {
155-
defaultMessage:
156-
'This request queries Elasticsearch to fetch the data for the visualization.',
157-
}),
158-
}
159-
);
160-
request.stats(getRequestInspectorStats(requestSearchSource));
161-
162-
try {
163-
const response = await requestSearchSource.fetch({ abortSignal });
164-
165-
(searchSource as any).lastQuery = queryHash;
166-
167-
request.stats(getResponseInspectorStats(response, searchSource)).ok({ json: response });
168-
169-
(searchSource as any).rawResponse = response;
170-
} catch (e) {
171-
// Log any error during request to the inspector
172-
request.error({ json: e });
173-
throw e;
174-
} finally {
175-
// Add the request body no matter if things went fine or not
176-
requestSearchSource.getSearchRequestBody().then((req: unknown) => {
177-
request.json(req);
178-
});
179147
}
148+
);
149+
request.stats(getRequestInspectorStats(requestSearchSource));
150+
151+
try {
152+
const response = await requestSearchSource.fetch({ abortSignal });
153+
154+
request.stats(getResponseInspectorStats(response, searchSource)).ok({ json: response });
155+
156+
(searchSource as any).rawResponse = response;
157+
} catch (e) {
158+
// Log any error during request to the inspector
159+
request.error({ json: e });
160+
throw e;
161+
} finally {
162+
// Add the request body no matter if things went fine or not
163+
requestSearchSource.getSearchRequestBody().then((req: unknown) => {
164+
request.json(req);
165+
});
180166
}
181167

182168
// Note that rawResponse is not deeply cloned here, so downstream applications using courier
@@ -207,19 +193,11 @@ const handleCourierRequest = async ({
207193
: undefined,
208194
};
209195

210-
const tabifyCacheHash = calculateObjectHash({ tabifyAggs: aggs, ...tabifyParams });
211-
// We only need to reexecute tabify, if either we did a new request or some input params to tabify changed
212-
const shouldCalculateNewTabify =
213-
shouldQuery || (searchSource as any).lastTabifyHash !== tabifyCacheHash;
214-
215-
if (shouldCalculateNewTabify) {
216-
(searchSource as any).lastTabifyHash = tabifyCacheHash;
217-
(searchSource as any).tabifiedResponse = tabifyAggResponse(
218-
aggs,
219-
(searchSource as any).finalResponse,
220-
tabifyParams
221-
);
222-
}
196+
(searchSource as any).tabifiedResponse = tabifyAggResponse(
197+
aggs,
198+
(searchSource as any).finalResponse,
199+
tabifyParams
200+
);
223201

224202
inspectorAdapters.data.setTabularLoader(
225203
() =>
@@ -294,7 +272,6 @@ export const esaggs = (): EsaggsExpressionFunctionDefinition => ({
294272
query: get(input, 'query', undefined) as any,
295273
filters: get(input, 'filters', undefined),
296274
timeFields: args.timeFields,
297-
forceFetch: true,
298275
metricsAtAllLevels: args.metricsAtAllLevels,
299276
partialRows: args.partialRows,
300277
inspectorAdapters: inspectorAdapters as Adapters,

src/plugins/vis_type_timelion/public/helpers/timelion_request_handler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export function getTimelionRequestHandler({
7878
filters: Filter[];
7979
query: Query;
8080
visParams: VisParams;
81-
forceFetch?: boolean;
8281
}): Promise<TimelionSuccessResponse> {
8382
const expression = visParams.expression;
8483

src/plugins/vis_type_timelion/public/timelion_vis_fn.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export const getTimelionVisualizationConfig = (
7676
query: get(input, 'query') as Query,
7777
filters: get(input, 'filters') as Filter[],
7878
visParams,
79-
forceFetch: true,
8079
});
8180

8281
response.visType = TIMELION_VIS_NAME;

src/plugins/visualizations/public/expressions/visualization_function.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export const visualization = (): ExpressionFunctionVisualization => ({
117117
uiState,
118118
inspectorAdapters,
119119
queryFilter: getFilterManager(),
120-
forceFetch: true,
121120
aggs,
122121
});
123122
}

x-pack/plugins/infra/common/alerting/metrics/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const baseAlertRequestParamsRT = rt.intersection([
5252
]),
5353
criteria: rt.array(rt.any),
5454
alertInterval: rt.string,
55+
alertThrottle: rt.string,
56+
alertOnNoData: rt.boolean,
5557
}),
5658
]);
5759

@@ -91,6 +93,7 @@ export const alertPreviewSuccessResponsePayloadRT = rt.type({
9193
fired: rt.number,
9294
noData: rt.number,
9395
error: rt.number,
96+
notifications: rt.number,
9497
}),
9598
});
9699
export type AlertPreviewSuccessResponsePayload = rt.TypeOf<

x-pack/plugins/infra/public/alerting/common/components/alert_preview.tsx

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { getAlertPreview, PreviewableAlertTypes } from './get_alert_preview';
3333

3434
interface Props {
3535
alertInterval: string;
36+
alertThrottle: string;
3637
alertType: PreviewableAlertTypes;
3738
fetch: HttpSetup['fetch'];
3839
alertParams: { criteria: any[]; sourceId: string } & Record<string, any>;
@@ -45,6 +46,7 @@ export const AlertPreview: React.FC<Props> = (props) => {
4546
const {
4647
alertParams,
4748
alertInterval,
49+
alertThrottle,
4850
fetch,
4951
alertType,
5052
validate,
@@ -73,16 +75,27 @@ export const AlertPreview: React.FC<Props> = (props) => {
7375
...alertParams,
7476
lookback: previewLookbackInterval as 'h' | 'd' | 'w' | 'M',
7577
alertInterval,
78+
alertThrottle,
79+
alertOnNoData: showNoDataResults ?? false,
7680
} as AlertPreviewRequestParams,
7781
alertType,
7882
});
79-
setPreviewResult({ ...result, groupByDisplayName, previewLookbackInterval });
83+
setPreviewResult({ ...result, groupByDisplayName, previewLookbackInterval, alertThrottle });
8084
} catch (e) {
8185
setPreviewError(e);
8286
} finally {
8387
setIsPreviewLoading(false);
8488
}
85-
}, [alertParams, alertInterval, fetch, alertType, groupByDisplayName, previewLookbackInterval]);
89+
}, [
90+
alertParams,
91+
alertInterval,
92+
fetch,
93+
alertType,
94+
groupByDisplayName,
95+
previewLookbackInterval,
96+
alertThrottle,
97+
showNoDataResults,
98+
]);
8699

87100
const previewIntervalError = useMemo(() => {
88101
const intervalInSeconds = getIntervalInSeconds(alertInterval);
@@ -101,6 +114,13 @@ export const AlertPreview: React.FC<Props> = (props) => {
101114
return hasValidationErrors || previewIntervalError;
102115
}, [alertParams.criteria, previewIntervalError, validate]);
103116

117+
const showNumberOfNotifications = useMemo(() => {
118+
if (!previewResult) return false;
119+
const { notifications, fired, noData, error } = previewResult.resultTotals;
120+
const unthrottledNotifications = fired + (showNoDataResults ? noData + error : 0);
121+
return unthrottledNotifications > notifications;
122+
}, [previewResult, showNoDataResults]);
123+
104124
return (
105125
<EuiFormRow
106126
label={i18n.translate('xpack.infra.metrics.alertFlyout.previewLabel', {
@@ -136,19 +156,22 @@ export const AlertPreview: React.FC<Props> = (props) => {
136156
<>
137157
<EuiSpacer size={'s'} />
138158
<EuiCallOut
139-
iconType="iInCircle"
159+
size="s"
140160
title={
141161
<>
142162
<FormattedMessage
143163
id="xpack.infra.metrics.alertFlyout.alertPreviewResult"
144-
defaultMessage="This alert would have occurred {firedTimes}"
164+
defaultMessage="There were {firedTimes}"
145165
values={{
146166
firedTimes: (
147167
<strong>
148-
{previewResult.resultTotals.fired}{' '}
149-
{previewResult.resultTotals.fired === 1
150-
? firedTimeLabel
151-
: firedTimesLabel}
168+
<FormattedMessage
169+
id="xpack.infra.metrics.alertFlyout.firedTimes"
170+
defaultMessage="{fired, plural, one {# instance} other {# instances}}"
171+
values={{
172+
fired: previewResult.resultTotals.fired,
173+
}}
174+
/>
152175
</strong>
153176
),
154177
}}
@@ -173,7 +196,7 @@ export const AlertPreview: React.FC<Props> = (props) => {
173196
) : null}
174197
<FormattedMessage
175198
id="xpack.infra.metrics.alertFlyout.alertPreviewResultLookback"
176-
defaultMessage="in the last {lookback}."
199+
defaultMessage="that satisfied the conditions of this alert in the last {lookback}."
177200
values={{
178201
lookback: previewOptions.find(
179202
(e) => e.value === previewResult.previewLookbackInterval
@@ -211,13 +234,40 @@ export const AlertPreview: React.FC<Props> = (props) => {
211234
defaultMessage="An error occurred when trying to evaluate some of the data."
212235
/>
213236
) : null}
237+
{showNumberOfNotifications ? (
238+
<>
239+
<EuiSpacer size={'s'} />
240+
<FormattedMessage
241+
id="xpack.infra.metrics.alertFlyout.alertPreviewTotalNotifications"
242+
defaultMessage='As a result, this alert would have sent {notifications} based on the selected "notify every" setting of "{alertThrottle}."'
243+
values={{
244+
alertThrottle: previewResult.alertThrottle,
245+
notifications: (
246+
<strong>
247+
{i18n.translate(
248+
'xpack.infra.metrics.alertFlyout.alertPreviewTotalNotificationsNumber',
249+
{
250+
defaultMessage:
251+
'{notifs, plural, one {# notification} other {# notifications}}',
252+
values: {
253+
notifs: previewResult.resultTotals.notifications,
254+
},
255+
}
256+
)}
257+
</strong>
258+
),
259+
}}
260+
/>
261+
</>
262+
) : null}{' '}
214263
</EuiCallOut>
215264
</>
216265
)}
217266
{previewIntervalError && (
218267
<>
219268
<EuiSpacer size={'s'} />
220269
<EuiCallOut
270+
size="s"
221271
title={
222272
<FormattedMessage
223273
id="xpack.infra.metrics.alertFlyout.previewIntervalTooShortTitle"
@@ -242,6 +292,7 @@ export const AlertPreview: React.FC<Props> = (props) => {
242292
<EuiSpacer size={'s'} />
243293
{previewError.body?.statusCode === 508 ? (
244294
<EuiCallOut
295+
size="s"
245296
title={
246297
<FormattedMessage
247298
id="xpack.infra.metrics.alertFlyout.tooManyBucketsErrorTitle"
@@ -264,6 +315,7 @@ export const AlertPreview: React.FC<Props> = (props) => {
264315
</EuiCallOut>
265316
) : (
266317
<EuiCallOut
318+
size="s"
267319
title={
268320
<FormattedMessage
269321
id="xpack.infra.metrics.alertFlyout.alertPreviewError"
@@ -349,10 +401,3 @@ const previewOptions = [
349401
const previewDOMOptions: Array<{ text: string; value: string }> = previewOptions.map((o) =>
350402
omit(o, 'shortText')
351403
);
352-
353-
const firedTimeLabel = i18n.translate('xpack.infra.metrics.alertFlyout.firedTime', {
354-
defaultMessage: 'time',
355-
});
356-
const firedTimesLabel = i18n.translate('xpack.infra.metrics.alertFlyout.firedTimes', {
357-
defaultMessage: 'times',
358-
});

x-pack/plugins/infra/public/alerting/common/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,3 @@ export const previewOptions = [
4545
}),
4646
},
4747
];
48-
49-
export const firedTimeLabel = i18n.translate('xpack.infra.metrics.alertFlyout.firedTime', {
50-
defaultMessage: 'time',
51-
});
52-
export const firedTimesLabel = i18n.translate('xpack.infra.metrics.alertFlyout.firedTimes', {
53-
defaultMessage: 'times',
54-
});

x-pack/plugins/infra/public/alerting/inventory/components/expression.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('Expression', () => {
6969
<Expressions
7070
alertsContext={context}
7171
alertInterval="1m"
72+
alertThrottle="1m"
7273
alertParams={alertParams as any}
7374
errors={[]}
7475
setAlertParams={(key, value) => Reflect.set(alertParams, key, value)}

x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ interface Props {
8989
alertOnNoData?: boolean;
9090
};
9191
alertInterval: string;
92+
alertThrottle: string;
9293
alertsContext: AlertsContextValue<AlertContextMeta>;
9394
setAlertParams(key: string, value: any): void;
9495
setAlertProperty(key: string, value: any): void;
@@ -104,7 +105,14 @@ const defaultExpression = {
104105
} as InventoryMetricConditions;
105106

106107
export const Expressions: React.FC<Props> = (props) => {
107-
const { setAlertParams, alertParams, errors, alertsContext, alertInterval } = props;
108+
const {
109+
setAlertParams,
110+
alertParams,
111+
errors,
112+
alertsContext,
113+
alertInterval,
114+
alertThrottle,
115+
} = props;
108116
const { source, createDerivedIndexPattern } = useSourceViaHttp({
109117
sourceId: 'default',
110118
type: 'metrics',
@@ -378,6 +386,7 @@ export const Expressions: React.FC<Props> = (props) => {
378386
<EuiSpacer size={'m'} />
379387
<AlertPreview
380388
alertInterval={alertInterval}
389+
alertThrottle={alertThrottle}
381390
alertType={METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID}
382391
alertParams={pick(alertParams, 'criteria', 'nodeType', 'sourceId', 'filterQuery')}
383392
validate={validateMetricThreshold}

x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('Expression', () => {
6868
<Expressions
6969
alertsContext={context}
7070
alertInterval="1m"
71+
alertThrottle="1m"
7172
alertParams={alertParams}
7273
errors={[]}
7374
setAlertParams={(key, value) => Reflect.set(alertParams, key, value)}

0 commit comments

Comments
 (0)