Skip to content

Commit

Permalink
Merge branch 'master' into Move_Show_Hide_Indices_Outside_List
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Feb 15, 2020
2 parents 2edaacb + 6e37905 commit aff3bf5
Show file tree
Hide file tree
Showing 149 changed files with 941 additions and 808 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
/x-pack/legacy/plugins/index_lifecycle_management/ @elastic/es-ui
/x-pack/legacy/plugins/index_management/ @elastic/es-ui
/x-pack/legacy/plugins/license_management/ @elastic/es-ui
/x-pack/legacy/plugins/remote_clusters/ @elastic/es-ui
/x-pack/plugins/remote_clusters/ @elastic/es-ui
/x-pack/legacy/plugins/rollup/ @elastic/es-ui
/x-pack/plugins/searchprofiler/ @elastic/es-ui
/x-pack/legacy/plugins/snapshot_restore/ @elastic/es-ui
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@
"@kbn/eslint-import-resolver-kibana": "2.0.0",
"@kbn/eslint-plugin-eslint": "1.0.0",
"@kbn/expect": "1.0.0",
"@kbn/plugin-generator": "1.0.0",
"@kbn/optimizer": "1.0.0",
"@kbn/plugin-generator": "1.0.0",
"@kbn/test": "1.0.0",
"@kbn/utility-types": "1.0.0",
"@microsoft/api-documenter": "7.7.2",
Expand Down Expand Up @@ -394,7 +394,7 @@
"chai": "3.5.0",
"chance": "1.0.18",
"cheerio": "0.22.0",
"chromedriver": "79.0.0",
"chromedriver": "^80.0.1",
"classnames": "2.2.6",
"dedent": "^0.7.0",
"delete-empty": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-optimizer/src/common/rxjs_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type Operator<T1, T2> = (source: Rx.Observable<T1>) => Rx.Observable<T2>;
type MapFn<T1, T2> = (item: T1, index: number) => T2;

/**
* Wrap an operator chain in a closure so that is can have some local
* state. The `fn` is called each time the final observable is
* subscribed so the pipeline/closure is setup for each subscription.
* Wrap an operator chain in a closure so that it can have some local
* state. The `fn` is called each time the returned observable is
* subscribed; the closure is recreated for each subscription.
*/
export const pipeClosure = <T1, T2>(fn: Operator<T1, T2>): Operator<T1, T2> => {
return (source: Rx.Observable<T1>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as Rx from 'rxjs';
import { REPO_ROOT } from '@kbn/dev-utils';

import { Update } from '../common';

import { OptimizerState } from './optimizer_reducer';
import { OptimizerConfig } from './optimizer_config';
import { handleOptimizerCompletion } from './handle_optimizer_completion';
import { toArray } from 'rxjs/operators';

const createUpdate$ = (phase: OptimizerState['phase']) =>
Rx.of<Update<any, OptimizerState>>({
state: {
phase,
compilerStates: [],
durSec: 0,
offlineBundles: [],
onlineBundles: [],
startTime: Date.now(),
},
});

const config = (watch?: boolean) =>
OptimizerConfig.create({
repoRoot: REPO_ROOT,
watch,
});
const collect = <T>(stream: Rx.Observable<T>): Promise<T[]> => stream.pipe(toArray()).toPromise();

it('errors if the optimizer completes when in watch mode', async () => {
const update$ = createUpdate$('success');

await expect(
collect(update$.pipe(handleOptimizerCompletion(config(true))))
).rejects.toThrowErrorMatchingInlineSnapshot(
`"optimizer unexpectedly completed when in watch mode"`
);
});

it('errors if the optimizer completes in phase "issue"', async () => {
const update$ = createUpdate$('issue');

await expect(
collect(update$.pipe(handleOptimizerCompletion(config())))
).rejects.toThrowErrorMatchingInlineSnapshot(`"webpack issue"`);
});

it('errors if the optimizer completes in phase "initializing"', async () => {
const update$ = createUpdate$('initializing');

await expect(
collect(update$.pipe(handleOptimizerCompletion(config())))
).rejects.toThrowErrorMatchingInlineSnapshot(
`"optimizer unexpectedly exit in phase \\"initializing\\""`
);
});

it('errors if the optimizer completes in phase "reallocating"', async () => {
const update$ = createUpdate$('reallocating');

await expect(
collect(update$.pipe(handleOptimizerCompletion(config())))
).rejects.toThrowErrorMatchingInlineSnapshot(
`"optimizer unexpectedly exit in phase \\"reallocating\\""`
);
});

it('errors if the optimizer completes in phase "running"', async () => {
const update$ = createUpdate$('running');

await expect(
collect(update$.pipe(handleOptimizerCompletion(config())))
).rejects.toThrowErrorMatchingInlineSnapshot(
`"optimizer unexpectedly exit in phase \\"running\\""`
);
});

it('passes through errors on the source stream', async () => {
const error = new Error('foo');
const update$ = Rx.throwError(error);

await expect(collect(update$.pipe(handleOptimizerCompletion(config())))).rejects.toThrowError(
error
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as Rx from 'rxjs';
import { tap } from 'rxjs/operators';
import { createFailError } from '@kbn/dev-utils';

import { pipeClosure, Update } from '../common';

import { OptimizerState } from './optimizer_reducer';
import { OptimizerConfig } from './optimizer_config';

export function handleOptimizerCompletion(config: OptimizerConfig) {
return pipeClosure((source$: Rx.Observable<Update<any, OptimizerState>>) => {
let prevState: OptimizerState | undefined;

return source$.pipe(
tap({
next: update => {
prevState = update.state;
},
complete: () => {
if (config.watch) {
throw new Error('optimizer unexpectedly completed when in watch mode');
}

if (prevState?.phase === 'success') {
return;
}

if (prevState?.phase === 'issue') {
throw createFailError('webpack issue');
}

throw new Error(`optimizer unexpectedly exit in phase "${prevState?.phase}"`);
},
})
);
});
}
1 change: 1 addition & 0 deletions packages/kbn-optimizer/src/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './cache_keys';
export * from './watch_bundles_for_changes';
export * from './run_workers';
export * from './bundle_cache';
export * from './handle_optimizer_completion';
4 changes: 3 additions & 1 deletion packages/kbn-optimizer/src/run_optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
runWorkers,
OptimizerInitializedEvent,
createOptimizerReducer,
handleOptimizerCompletion,
} from './optimizer';

export type OptimizerUpdate = Update<OptimizerEvent, OptimizerState>;
Expand Down Expand Up @@ -77,6 +78,7 @@ export function runOptimizer(config: OptimizerConfig) {
},
createOptimizerReducer(config)
);
})
}),
handleOptimizerCompletion(config)
);
}
2 changes: 1 addition & 1 deletion packages/kbn-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts,.js,.tsx --ignore *.test.js,**/__tests__/**",
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts,.js,.tsx --ignore *.test.js,**/__tests__/** --source-maps=inline",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-test/src/failed_tests_reporter/test_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface TestSuite {
/* number of skipped tests as a string */
skipped: string;
};
testcase: TestCase[];
testcase?: TestCase[];
}

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

for (const testSuite of testSuites) {
for (const testCase of testSuite.testcase) {
for (const testCase of testSuite.testcase || []) {
yield testCase;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ import { get } from 'lodash';
import moment from 'moment-timezone';
import { i18n } from '@kbn/i18n';
import { npStart } from 'ui/new_platform';
import { convertDateRangeToString, DateRangeKey } from './lib/date_range';
import { BUCKET_TYPES } from './bucket_agg_types';
import { BucketAggType, IBucketAggConfig } from './_bucket_agg_type';
import { createFilterDateRange } from './create_filter/date_range';

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

export { convertDateRangeToString, DateRangeKey };

const dateRangeTitle = i18n.translate('data.search.aggs.buckets.dateRangeTitle', {
defaultMessage: 'Date Range',
});

export interface DateRangeKey {
from: number;
to: number;
}

export const dateRangeBucketAgg = new BucketAggType({
name: BUCKET_TYPES.DATE_RANGE,
title: dateRangeTitle,
Expand Down Expand Up @@ -106,16 +104,3 @@ export const dateRangeBucketAgg = new BucketAggType({
},
],
});

export const convertDateRangeToString = (
{ from, to }: DateRangeKey,
format: (val: any) => string
) => {
if (!from) {
return 'Before ' + format(to);
} else if (!to) {
return 'After ' + format(from);
} else {
return format(from) + ' to ' + format(to);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@
import { noop, map, omit, isNull } from 'lodash';
import { i18n } from '@kbn/i18n';
import { npStart } from 'ui/new_platform';
import { IpRangeKey, convertIPRangeToString } from './lib/ip_range';
import { BucketAggType } from './_bucket_agg_type';
import { BUCKET_TYPES } from './bucket_agg_types';

// @ts-ignore
import { createFilterIpRange } from './create_filter/ip_range';
import { KBN_FIELD_TYPES, fieldFormats } from '../../../../../../../plugins/data/public';
export { IpRangeKey, convertIPRangeToString };

const ipRangeTitle = i18n.translate('data.search.aggs.buckets.ipRangeTitle', {
defaultMessage: 'IPv4 Range',
});

export type IpRangeKey =
| { type: 'mask'; mask: string }
| { type: 'range'; from: string; to: string };

export const ipRangeBucketAgg = new BucketAggType({
name: BUCKET_TYPES.IP_RANGE,
title: ipRangeTitle,
Expand Down Expand Up @@ -97,13 +95,3 @@ export const ipRangeBucketAgg = new BucketAggType({
},
],
});

export const convertIPRangeToString = (range: IpRangeKey, format: (val: any) => string) => {
if (range.type === 'mask') {
return format(range.mask);
}
const from = range.from ? format(range.from) : '-Infinity';
const to = range.to ? format(range.to) : 'Infinity';

return `${from} to ${to}`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export interface DateRangeKey {
from: number;
to: number;
}

export const convertDateRangeToString = (
{ from, to }: DateRangeKey,
format: (val: any) => string
) => {
if (!from) {
return 'Before ' + format(to);
} else if (!to) {
return 'After ' + format(from);
} else {
return format(from) + ' to ' + format(to);
}
};
Loading

0 comments on commit aff3bf5

Please sign in to comment.