Skip to content

Commit aff3bf5

Browse files
Merge branch 'master' into Move_Show_Hide_Indices_Outside_List
2 parents 2edaacb + 6e37905 commit aff3bf5

149 files changed

Lines changed: 941 additions & 808 deletions

File tree

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
/x-pack/legacy/plugins/index_lifecycle_management/ @elastic/es-ui
171171
/x-pack/legacy/plugins/index_management/ @elastic/es-ui
172172
/x-pack/legacy/plugins/license_management/ @elastic/es-ui
173-
/x-pack/legacy/plugins/remote_clusters/ @elastic/es-ui
173+
/x-pack/plugins/remote_clusters/ @elastic/es-ui
174174
/x-pack/legacy/plugins/rollup/ @elastic/es-ui
175175
/x-pack/plugins/searchprofiler/ @elastic/es-ui
176176
/x-pack/legacy/plugins/snapshot_restore/ @elastic/es-ui

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@
294294
"@kbn/eslint-import-resolver-kibana": "2.0.0",
295295
"@kbn/eslint-plugin-eslint": "1.0.0",
296296
"@kbn/expect": "1.0.0",
297-
"@kbn/plugin-generator": "1.0.0",
298297
"@kbn/optimizer": "1.0.0",
298+
"@kbn/plugin-generator": "1.0.0",
299299
"@kbn/test": "1.0.0",
300300
"@kbn/utility-types": "1.0.0",
301301
"@microsoft/api-documenter": "7.7.2",
@@ -394,7 +394,7 @@
394394
"chai": "3.5.0",
395395
"chance": "1.0.18",
396396
"cheerio": "0.22.0",
397-
"chromedriver": "79.0.0",
397+
"chromedriver": "^80.0.1",
398398
"classnames": "2.2.6",
399399
"dedent": "^0.7.0",
400400
"delete-empty": "^2.0.0",

packages/kbn-optimizer/src/common/rxjs_helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ type Operator<T1, T2> = (source: Rx.Observable<T1>) => Rx.Observable<T2>;
2424
type MapFn<T1, T2> = (item: T1, index: number) => T2;
2525

2626
/**
27-
* Wrap an operator chain in a closure so that is can have some local
28-
* state. The `fn` is called each time the final observable is
29-
* subscribed so the pipeline/closure is setup for each subscription.
27+
* Wrap an operator chain in a closure so that it can have some local
28+
* state. The `fn` is called each time the returned observable is
29+
* subscribed; the closure is recreated for each subscription.
3030
*/
3131
export const pipeClosure = <T1, T2>(fn: Operator<T1, T2>): Operator<T1, T2> => {
3232
return (source: Rx.Observable<T1>) => {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import * as Rx from 'rxjs';
21+
import { REPO_ROOT } from '@kbn/dev-utils';
22+
23+
import { Update } from '../common';
24+
25+
import { OptimizerState } from './optimizer_reducer';
26+
import { OptimizerConfig } from './optimizer_config';
27+
import { handleOptimizerCompletion } from './handle_optimizer_completion';
28+
import { toArray } from 'rxjs/operators';
29+
30+
const createUpdate$ = (phase: OptimizerState['phase']) =>
31+
Rx.of<Update<any, OptimizerState>>({
32+
state: {
33+
phase,
34+
compilerStates: [],
35+
durSec: 0,
36+
offlineBundles: [],
37+
onlineBundles: [],
38+
startTime: Date.now(),
39+
},
40+
});
41+
42+
const config = (watch?: boolean) =>
43+
OptimizerConfig.create({
44+
repoRoot: REPO_ROOT,
45+
watch,
46+
});
47+
const collect = <T>(stream: Rx.Observable<T>): Promise<T[]> => stream.pipe(toArray()).toPromise();
48+
49+
it('errors if the optimizer completes when in watch mode', async () => {
50+
const update$ = createUpdate$('success');
51+
52+
await expect(
53+
collect(update$.pipe(handleOptimizerCompletion(config(true))))
54+
).rejects.toThrowErrorMatchingInlineSnapshot(
55+
`"optimizer unexpectedly completed when in watch mode"`
56+
);
57+
});
58+
59+
it('errors if the optimizer completes in phase "issue"', async () => {
60+
const update$ = createUpdate$('issue');
61+
62+
await expect(
63+
collect(update$.pipe(handleOptimizerCompletion(config())))
64+
).rejects.toThrowErrorMatchingInlineSnapshot(`"webpack issue"`);
65+
});
66+
67+
it('errors if the optimizer completes in phase "initializing"', async () => {
68+
const update$ = createUpdate$('initializing');
69+
70+
await expect(
71+
collect(update$.pipe(handleOptimizerCompletion(config())))
72+
).rejects.toThrowErrorMatchingInlineSnapshot(
73+
`"optimizer unexpectedly exit in phase \\"initializing\\""`
74+
);
75+
});
76+
77+
it('errors if the optimizer completes in phase "reallocating"', async () => {
78+
const update$ = createUpdate$('reallocating');
79+
80+
await expect(
81+
collect(update$.pipe(handleOptimizerCompletion(config())))
82+
).rejects.toThrowErrorMatchingInlineSnapshot(
83+
`"optimizer unexpectedly exit in phase \\"reallocating\\""`
84+
);
85+
});
86+
87+
it('errors if the optimizer completes in phase "running"', async () => {
88+
const update$ = createUpdate$('running');
89+
90+
await expect(
91+
collect(update$.pipe(handleOptimizerCompletion(config())))
92+
).rejects.toThrowErrorMatchingInlineSnapshot(
93+
`"optimizer unexpectedly exit in phase \\"running\\""`
94+
);
95+
});
96+
97+
it('passes through errors on the source stream', async () => {
98+
const error = new Error('foo');
99+
const update$ = Rx.throwError(error);
100+
101+
await expect(collect(update$.pipe(handleOptimizerCompletion(config())))).rejects.toThrowError(
102+
error
103+
);
104+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import * as Rx from 'rxjs';
21+
import { tap } from 'rxjs/operators';
22+
import { createFailError } from '@kbn/dev-utils';
23+
24+
import { pipeClosure, Update } from '../common';
25+
26+
import { OptimizerState } from './optimizer_reducer';
27+
import { OptimizerConfig } from './optimizer_config';
28+
29+
export function handleOptimizerCompletion(config: OptimizerConfig) {
30+
return pipeClosure((source$: Rx.Observable<Update<any, OptimizerState>>) => {
31+
let prevState: OptimizerState | undefined;
32+
33+
return source$.pipe(
34+
tap({
35+
next: update => {
36+
prevState = update.state;
37+
},
38+
complete: () => {
39+
if (config.watch) {
40+
throw new Error('optimizer unexpectedly completed when in watch mode');
41+
}
42+
43+
if (prevState?.phase === 'success') {
44+
return;
45+
}
46+
47+
if (prevState?.phase === 'issue') {
48+
throw createFailError('webpack issue');
49+
}
50+
51+
throw new Error(`optimizer unexpectedly exit in phase "${prevState?.phase}"`);
52+
},
53+
})
54+
);
55+
});
56+
}

packages/kbn-optimizer/src/optimizer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ export * from './cache_keys';
2424
export * from './watch_bundles_for_changes';
2525
export * from './run_workers';
2626
export * from './bundle_cache';
27+
export * from './handle_optimizer_completion';

packages/kbn-optimizer/src/run_optimizer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
runWorkers,
3333
OptimizerInitializedEvent,
3434
createOptimizerReducer,
35+
handleOptimizerCompletion,
3536
} from './optimizer';
3637

3738
export type OptimizerUpdate = Update<OptimizerEvent, OptimizerState>;
@@ -77,6 +78,7 @@ export function runOptimizer(config: OptimizerConfig) {
7778
},
7879
createOptimizerReducer(config)
7980
);
80-
})
81+
}),
82+
handleOptimizerCompletion(config)
8183
);
8284
}

packages/kbn-test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "Apache-2.0",
66
"private": true,
77
"scripts": {
8-
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts,.js,.tsx --ignore *.test.js,**/__tests__/**",
8+
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts,.js,.tsx --ignore *.test.js,**/__tests__/** --source-maps=inline",
99
"kbn:bootstrap": "yarn build",
1010
"kbn:watch": "yarn build --watch"
1111
},

packages/kbn-test/src/failed_tests_reporter/test_report.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface TestSuite {
4747
/* number of skipped tests as a string */
4848
skipped: string;
4949
};
50-
testcase: TestCase[];
50+
testcase?: TestCase[];
5151
}
5252

5353
export interface TestCase {
@@ -89,7 +89,7 @@ export function* makeTestCaseIter(report: TestReport) {
8989
const testSuites = 'testsuites' in report ? report.testsuites.testsuite : [report.testsuite];
9090

9191
for (const testSuite of testSuites) {
92-
for (const testCase of testSuite.testcase) {
92+
for (const testCase of testSuite.testcase || []) {
9393
yield testCase;
9494
}
9595
}

src/legacy/core_plugins/data/public/search/aggs/buckets/date_range.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ import { get } from 'lodash';
2020
import moment from 'moment-timezone';
2121
import { i18n } from '@kbn/i18n';
2222
import { npStart } from 'ui/new_platform';
23+
import { convertDateRangeToString, DateRangeKey } from './lib/date_range';
2324
import { BUCKET_TYPES } from './bucket_agg_types';
2425
import { BucketAggType, IBucketAggConfig } from './_bucket_agg_type';
2526
import { createFilterDateRange } from './create_filter/date_range';
2627

2728
import { KBN_FIELD_TYPES, fieldFormats } from '../../../../../../../plugins/data/public';
2829

30+
export { convertDateRangeToString, DateRangeKey };
31+
2932
const dateRangeTitle = i18n.translate('data.search.aggs.buckets.dateRangeTitle', {
3033
defaultMessage: 'Date Range',
3134
});
3235

33-
export interface DateRangeKey {
34-
from: number;
35-
to: number;
36-
}
37-
3836
export const dateRangeBucketAgg = new BucketAggType({
3937
name: BUCKET_TYPES.DATE_RANGE,
4038
title: dateRangeTitle,
@@ -106,16 +104,3 @@ export const dateRangeBucketAgg = new BucketAggType({
106104
},
107105
],
108106
});
109-
110-
export const convertDateRangeToString = (
111-
{ from, to }: DateRangeKey,
112-
format: (val: any) => string
113-
) => {
114-
if (!from) {
115-
return 'Before ' + format(to);
116-
} else if (!to) {
117-
return 'After ' + format(from);
118-
} else {
119-
return format(from) + ' to ' + format(to);
120-
}
121-
};

0 commit comments

Comments
 (0)