Skip to content

Commit 3a5d874

Browse files
Merge branch 'master' into telemetry/always-opted-in
2 parents f7fa39d + c485893 commit 3a5d874

27 files changed

Lines changed: 914 additions & 482 deletions

File tree

packages/kbn-babel-preset/node_preset.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@
1818
*/
1919

2020
module.exports = (_, options = {}) => {
21+
const overrides = [];
22+
if (!process.env.ALLOW_PERFORMANCE_HOOKS_IN_TASK_MANAGER) {
23+
overrides.push(
24+
{
25+
test: [/x-pack[\/\\]legacy[\/\\]plugins[\/\\]task_manager/],
26+
plugins: [
27+
[
28+
'filter-imports',
29+
{
30+
imports: {
31+
perf_hooks: ['performance'],
32+
},
33+
},
34+
],
35+
],
36+
}
37+
);
38+
}
39+
2140
return {
2241
presets: [
2342
[
@@ -39,7 +58,7 @@ module.exports = (_, options = {}) => {
3958
modules: 'cjs',
4059
corejs: 3,
4160

42-
...(options['@babel/preset-env'] || {})
61+
...(options['@babel/preset-env'] || {}),
4362
},
4463
],
4564
require('./common_preset'),
@@ -48,9 +67,10 @@ module.exports = (_, options = {}) => {
4867
[
4968
require.resolve('babel-plugin-transform-define'),
5069
{
51-
'global.__BUILT_WITH_BABEL__': 'true'
52-
}
53-
]
54-
]
70+
'global.__BUILT_WITH_BABEL__': 'true',
71+
},
72+
],
73+
],
74+
overrides,
5575
};
5676
};

packages/kbn-babel-preset/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
99
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
1010
"@babel/preset-env": "^7.5.5",
11-
"@babel/preset-react":"^7.0.0",
11+
"@babel/preset-react": "^7.0.0",
1212
"@babel/preset-typescript": "^7.3.3",
1313
"@kbn/elastic-idx": "1.0.0",
1414
"babel-plugin-add-module-exports": "^1.0.2",
15+
"babel-plugin-filter-imports": "^3.0.0",
1516
"babel-plugin-transform-define": "^1.3.1",
1617
"babel-plugin-typescript-strip-namespaces": "^1.1.1"
1718
}

src/legacy/core_plugins/data/public/search/search_bar/components/saved_query_management/saved_query_management_component.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
EuiPagination,
3030
EuiText,
3131
EuiSpacer,
32+
EuiIcon,
3233
} from '@elastic/eui';
3334

3435
import { i18n } from '@kbn/i18n';
@@ -116,8 +117,6 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
116117

117118
const savedQueryPopoverButton = (
118119
<EuiButtonEmpty
119-
iconType="arrowDown"
120-
iconSide="right"
121120
onClick={() => {
122121
setIsOpen(!isOpen);
123122
}}
@@ -129,7 +128,8 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
129128
})}
130129
data-test-subj="saved-query-management-popover-button"
131130
>
132-
#
131+
<EuiIcon type="save" className="euiQuickSelectPopover__buttonText" />
132+
<EuiIcon type="arrowDown" />
133133
</EuiButtonEmpty>
134134
);
135135

src/legacy/ui/public/vis/editors/default/components/agg_group.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import {
2626
EuiDraggable,
2727
EuiSpacer,
2828
EuiPanel,
29+
EuiFormErrorText,
2930
} from '@elastic/eui';
31+
import { i18n } from '@kbn/i18n';
3032

3133
import { AggConfig } from '../../../../agg_types/agg_config';
3234
import { aggGroupNamesMap, AggGroupNames } from '../agg_groups';
@@ -80,7 +82,15 @@ function DefaultEditorAggGroup({
8082

8183
const [aggsState, setAggsState] = useReducer(aggGroupReducer, group, initAggsState);
8284

83-
const isGroupValid = Object.values(aggsState).every(item => item.valid);
85+
const bucketsError =
86+
lastParentPipelineAggTitle && groupName === AggGroupNames.Buckets && !group.length
87+
? i18n.translate('common.ui.aggTypes.buckets.mustHaveBucketErrorMessage', {
88+
defaultMessage: 'Add a bucket with "Date Histogram" or "Histogram" aggregation.',
89+
description: 'Date Histogram and Histogram should not be translated',
90+
})
91+
: undefined;
92+
93+
const isGroupValid = !bucketsError && Object.values(aggsState).every(item => item.valid);
8494
const isAllAggsTouched = isInvalidAggsTouched(aggsState);
8595
const isMetricAggregationDisabled = useMemo(
8696
() => groupName === AggGroupNames.Metrics && getEnabledMetricAggsCount(group) === 1,
@@ -144,6 +154,12 @@ function DefaultEditorAggGroup({
144154
<h3>{groupNameLabel}</h3>
145155
</EuiTitle>
146156
<EuiSpacer size="s" />
157+
{bucketsError && (
158+
<>
159+
<EuiFormErrorText>{bucketsError}</EuiFormErrorText>
160+
<EuiSpacer size="s" />
161+
</>
162+
)}
147163
<EuiDroppable droppableId={`agg_group_dnd_${groupName}`}>
148164
<>
149165
{group.map((agg: AggConfig, index: number) => (

x-pack/.i18nrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"xpack.server": "legacy/server",
3535
"xpack.snapshotRestore": "legacy/plugins/snapshot_restore",
3636
"xpack.spaces": ["legacy/plugins/spaces", "plugins/spaces"],
37+
"xpack.taskManager": "legacy/plugins/task_manager",
3738
"xpack.transform": "legacy/plugins/transform",
3839
"xpack.upgradeAssistant": "legacy/plugins/upgrade_assistant",
3940
"xpack.uptime": "legacy/plugins/uptime",

x-pack/legacy/plugins/actions/server/builtin_action_types/lib/result_type.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
// Which is basically the Haskel equivalent of Rust/ML/Scala's Result
99
// I'll reach out to other's in Kibana to see if we can merge these into one type
1010

11-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
12-
export type Ok<T> = {
11+
export interface Ok<T> {
1312
tag: 'ok';
1413
value: T;
15-
};
16-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
17-
export type Err<E> = {
14+
}
15+
16+
export interface Err<E> {
1817
tag: 'err';
1918
error: E;
20-
};
19+
}
2120
export type Result<T, E> = Ok<T> | Err<E>;
2221

2322
export function asOk<T>(value: T): Ok<T> {

x-pack/legacy/plugins/task_manager/lib/fill_pool.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import _ from 'lodash';
88
import sinon from 'sinon';
99
import { fillPool } from './fill_pool';
10+
import { TaskPoolRunResult } from '../task_pool';
1011

1112
describe('fillPool', () => {
1213
test('stops filling when there are no more tasks in the store', async () => {
1314
const tasks = [[1, 2, 3], [4, 5]];
1415
let index = 0;
1516
const fetchAvailableTasks = async () => tasks[index++] || [];
16-
const run = sinon.spy(async () => true);
17+
const run = sinon.spy(async () => TaskPoolRunResult.RunningAllClaimedTasks);
1718
const converter = _.identity;
1819

1920
await fillPool(run, fetchAvailableTasks, converter);
@@ -25,7 +26,7 @@ describe('fillPool', () => {
2526
const tasks = [[1, 2, 3], [4, 5]];
2627
let index = 0;
2728
const fetchAvailableTasks = async () => tasks[index++] || [];
28-
const run = sinon.spy(async () => false);
29+
const run = sinon.spy(async () => TaskPoolRunResult.RanOutOfCapacity);
2930
const converter = _.identity;
3031

3132
await fillPool(run, fetchAvailableTasks, converter);
@@ -37,7 +38,7 @@ describe('fillPool', () => {
3738
const tasks = [[1, 2, 3], [4, 5]];
3839
let index = 0;
3940
const fetchAvailableTasks = async () => tasks[index++] || [];
40-
const run = sinon.spy(async () => false);
41+
const run = sinon.spy(async () => TaskPoolRunResult.RanOutOfCapacity);
4142
const converter = (x: number) => x.toString();
4243

4344
await fillPool(run, fetchAvailableTasks, converter);
@@ -47,7 +48,7 @@ describe('fillPool', () => {
4748

4849
describe('error handling', () => {
4950
test('throws exception from fetchAvailableTasks', async () => {
50-
const run = sinon.spy(async () => false);
51+
const run = sinon.spy(async () => TaskPoolRunResult.RanOutOfCapacity);
5152
const converter = (x: number) => x.toString();
5253

5354
try {
@@ -80,7 +81,7 @@ describe('fillPool', () => {
8081
const tasks = [[1, 2, 3], [4, 5]];
8182
let index = 0;
8283
const fetchAvailableTasks = async () => tasks[index++] || [];
83-
const run = sinon.spy(async () => false);
84+
const run = sinon.spy(async () => TaskPoolRunResult.RanOutOfCapacity);
8485
const converter = (x: number) => {
8586
throw new Error(`can not convert ${x}`);
8687
};

x-pack/legacy/plugins/task_manager/lib/fill_pool.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
type BatchRun<T> = (tasks: T[]) => Promise<boolean>;
7+
import { performance } from 'perf_hooks';
8+
import { TaskPoolRunResult } from '../task_pool';
9+
10+
export enum FillPoolResult {
11+
NoTasksClaimed = 'NoTasksClaimed',
12+
RanOutOfCapacity = 'RanOutOfCapacity',
13+
}
14+
15+
type BatchRun<T> = (tasks: T[]) => Promise<TaskPoolRunResult>;
816
type Fetcher<T> = () => Promise<T[]>;
917
type Converter<T1, T2> = (t: T1) => T2;
1018

@@ -24,18 +32,32 @@ export async function fillPool<TRecord, TRunner>(
2432
run: BatchRun<TRunner>,
2533
fetchAvailableTasks: Fetcher<TRecord>,
2634
converter: Converter<TRecord, TRunner>
27-
): Promise<void> {
35+
): Promise<FillPoolResult> {
36+
performance.mark('fillPool.start');
2837
while (true) {
2938
const instances = await fetchAvailableTasks();
3039

3140
if (!instances.length) {
32-
return;
41+
performance.mark('fillPool.bailNoTasks');
42+
performance.measure(
43+
'fillPool.activityDurationUntilNoTasks',
44+
'fillPool.start',
45+
'fillPool.bailNoTasks'
46+
);
47+
return FillPoolResult.NoTasksClaimed;
3348
}
3449

3550
const tasks = instances.map(converter);
3651

37-
if (!(await run(tasks))) {
38-
return;
52+
if ((await run(tasks)) === TaskPoolRunResult.RanOutOfCapacity) {
53+
performance.mark('fillPool.bailExhaustedCapacity');
54+
performance.measure(
55+
'fillPool.activityDurationUntilExhaustedCapacity',
56+
'fillPool.start',
57+
'fillPool.bailExhaustedCapacity'
58+
);
59+
return FillPoolResult.RanOutOfCapacity;
3960
}
61+
performance.mark('fillPool.cycle');
4062
}
4163
}

x-pack/legacy/plugins/task_manager/lib/middleware.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,23 @@ describe('addMiddlewareToChain', () => {
7070
return opts;
7171
},
7272
beforeRun: defaultBeforeRun,
73+
beforeMarkRunning: defaultBeforeRun,
7374
};
7475
const m2 = {
7576
beforeSave: async (opts: BeforeSaveOpts) => {
7677
Object.assign(opts.taskInstance.params, { m2: true });
7778
return opts;
7879
},
7980
beforeRun: defaultBeforeRun,
81+
beforeMarkRunning: defaultBeforeRun,
8082
};
8183
const m3 = {
8284
beforeSave: async (opts: BeforeSaveOpts) => {
8385
Object.assign(opts.taskInstance.params, { m3: true });
8486
return opts;
8587
},
8688
beforeRun: defaultBeforeRun,
89+
beforeMarkRunning: defaultBeforeRun,
8790
};
8891

8992
let middlewareChain;
@@ -119,6 +122,7 @@ describe('addMiddlewareToChain', () => {
119122
m1: true,
120123
};
121124
},
125+
beforeMarkRunning: defaultBeforeRun,
122126
};
123127
const m2 = {
124128
beforeSave: defaultBeforeSave,
@@ -128,6 +132,7 @@ describe('addMiddlewareToChain', () => {
128132
m2: true,
129133
};
130134
},
135+
beforeMarkRunning: defaultBeforeRun,
131136
};
132137
const m3 = {
133138
beforeSave: defaultBeforeSave,
@@ -137,6 +142,7 @@ describe('addMiddlewareToChain', () => {
137142
m3: true,
138143
};
139144
},
145+
beforeMarkRunning: defaultBeforeRun,
140146
};
141147

142148
let middlewareChain;

x-pack/legacy/plugins/task_manager/lib/middleware.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ export type BeforeSaveFunction = (
2323
) => Promise<BeforeSaveMiddlewareParams>;
2424

2525
export type BeforeRunFunction = (params: RunContext) => Promise<RunContext>;
26+
export type BeforeMarkRunningFunction = (params: RunContext) => Promise<RunContext>;
2627

2728
export interface Middleware {
2829
beforeSave: BeforeSaveFunction;
2930
beforeRun: BeforeRunFunction;
31+
beforeMarkRunning: BeforeMarkRunningFunction;
3032
}
3133

3234
export function addMiddlewareToChain(prevMiddleware: Middleware, middleware: Middleware) {
@@ -39,8 +41,14 @@ export function addMiddlewareToChain(prevMiddleware: Middleware, middleware: Mid
3941
? (params: RunContext) => middleware.beforeRun(params).then(prevMiddleware.beforeRun)
4042
: prevMiddleware.beforeRun;
4143

44+
const beforeMarkRunning = middleware.beforeMarkRunning
45+
? (params: RunContext) =>
46+
middleware.beforeMarkRunning(params).then(prevMiddleware.beforeMarkRunning)
47+
: prevMiddleware.beforeMarkRunning;
48+
4249
return {
4350
beforeSave,
4451
beforeRun,
52+
beforeMarkRunning,
4553
};
4654
}

0 commit comments

Comments
 (0)