-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Move_Show_Hide_Indices_Outside_List
- Loading branch information
Showing
149 changed files
with
941 additions
and
808 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/kbn-optimizer/src/optimizer/handle_optimizer_completion.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/kbn-optimizer/src/optimizer/handle_optimizer_completion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"`); | ||
}, | ||
}) | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/legacy/core_plugins/data/public/search/aggs/buckets/lib/date_range.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
Oops, something went wrong.