-
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 'main' into fix-typecheck-foundations
- Loading branch information
Showing
45 changed files
with
653 additions
and
1,422 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
2 changes: 1 addition & 1 deletion
2
packages/shared-ux/page/kibana_template/impl/src/__snapshots__/page_template.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
...s/shared-ux/page/kibana_template/impl/src/__snapshots__/page_template_inner.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
81 changes: 81 additions & 0 deletions
81
src/core/server/integration_tests/saved_objects/migrations/elasticsearch_client_wrapper.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,81 @@ | ||
/* | ||
* 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 type { Client } from '@elastic/elasticsearch'; | ||
|
||
export type ElasticsearchClientWrapperFactory = (client: Client) => Client; | ||
|
||
interface GetElasticsearchClientWrapperFactoryParams { | ||
failOn: (methodName: string, methodArguments: any[]) => boolean; | ||
errorDelaySeconds?: number; | ||
} | ||
|
||
export const getElasticsearchClientWrapperFactory = ({ | ||
failOn, | ||
errorDelaySeconds, | ||
}: GetElasticsearchClientWrapperFactoryParams): ElasticsearchClientWrapperFactory => { | ||
const interceptClientMethod = (methodName: string, method: any): any => { | ||
return new Proxy(method, { | ||
apply: (applyTarget, thisArg, methodArguments) => { | ||
if (failOn(methodName, methodArguments)) { | ||
return new Promise((_, reject) => | ||
setTimeout( | ||
() => reject(`Error: esClient.${methodName}() failed unexpectedly`), | ||
(errorDelaySeconds || 0) * 1000 | ||
) | ||
); | ||
} | ||
return Reflect.apply(applyTarget, thisArg, methodArguments); | ||
}, | ||
}); | ||
}; | ||
|
||
const interceptClientApi = (apiName: string, api: any): any => | ||
new Proxy(api, { | ||
get(target, prop) { | ||
return typeof target[prop] === 'function' | ||
? interceptClientMethod(`${apiName}.${prop.toString()}`, target[prop]) | ||
: target[prop]; | ||
}, | ||
}); | ||
|
||
const wrapClient = (client: Client): any => | ||
new Proxy(client, { | ||
get(target, prop, receiver) { | ||
switch (prop) { | ||
// intercept top level esClient methods | ||
case 'bulk': | ||
case 'deleteByQuery': | ||
case 'info': | ||
case 'search': | ||
case 'updateByQuery': | ||
const clientMethod = Reflect.get(target, prop, receiver); | ||
return interceptClientMethod(prop, clientMethod); | ||
// intercept esClient APIs | ||
case 'cluster': | ||
case 'indices': | ||
case 'tasks': | ||
const clientApi = Reflect.get(target, prop, receiver); | ||
return interceptClientApi(prop, clientApi); | ||
// proxy child Clients too | ||
case 'child': | ||
return new Proxy(target[prop], { | ||
apply(applyTarget, thisArg, argArray) { | ||
const childClient = Reflect.apply(applyTarget, thisArg, argArray); | ||
return wrapClient(childClient); | ||
}, | ||
}); | ||
// do NOT intercept the rest of properties and symbols | ||
default: | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
}, | ||
}); | ||
|
||
return wrapClient; | ||
}; |
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
Oops, something went wrong.