-
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 remote-tracking branch 'upstream/master' into task/olm-956-even…
…t-filter-delete
- Loading branch information
Showing
116 changed files
with
3,903 additions
and
683 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { | ||
IEsSearchRequest, | ||
IEsSearchResponse, | ||
IKibanaSearchRequest, | ||
IKibanaSearchResponse, | ||
} from '../../../src/plugins/data/common'; | ||
|
||
export interface IMyStrategyRequest extends IEsSearchRequest { | ||
get_cool: boolean; | ||
} | ||
export interface IMyStrategyResponse extends IEsSearchResponse { | ||
cool: string; | ||
executed_at: number; | ||
} | ||
|
||
export type FibonacciRequest = IKibanaSearchRequest<{ n: number }>; | ||
|
||
export type FibonacciResponse = IKibanaSearchResponse<{ values: number[] }>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import uuid from 'uuid'; | ||
import { ISearchStrategy } from '../../../src/plugins/data/server'; | ||
import { FibonacciRequest, FibonacciResponse } from '../common/types'; | ||
|
||
export const fibonacciStrategyProvider = (): ISearchStrategy< | ||
FibonacciRequest, | ||
FibonacciResponse | ||
> => { | ||
const responseMap = new Map<string, [number[], number, number]>(); | ||
return ({ | ||
search: (request: FibonacciRequest) => { | ||
const id = request.id ?? uuid(); | ||
const [sequence, total, started] = responseMap.get(id) ?? [ | ||
[], | ||
request.params?.n ?? 0, | ||
Date.now(), | ||
]; | ||
if (sequence.length < 2) { | ||
if (total > 0) sequence.push(sequence.length); | ||
} else { | ||
const [a, b] = sequence.slice(-2); | ||
sequence.push(a + b); | ||
} | ||
const loaded = sequence.length; | ||
responseMap.set(id, [sequence, total, started]); | ||
if (loaded >= total) { | ||
responseMap.delete(id); | ||
} | ||
|
||
const isRunning = loaded < total; | ||
const isPartial = isRunning; | ||
const took = Date.now() - started; | ||
const values = sequence.slice(0, loaded); | ||
|
||
// Usually we'd do something like "of()" but for some reason it breaks in tests with the error | ||
// "You provided an invalid object where a stream was expected." which is why we have to cast | ||
// down below as well | ||
return [{ id, loaded, total, isRunning, isPartial, rawResponse: { took, values } }]; | ||
}, | ||
cancel: async (id: string) => { | ||
responseMap.delete(id); | ||
}, | ||
} as unknown) as ISearchStrategy<FibonacciRequest, FibonacciResponse>; | ||
}; |
Oops, something went wrong.