mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
Allow access to ElasticsearchClient's child function from core's TS interface (#126731)
* Expose child from core ElasticsearchClient * Update docs * Fix typecheck Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
004f0d4daa
commit
a4febd7709
6 changed files with 11 additions and 31 deletions
|
@ -9,5 +9,5 @@ Client used to query the elasticsearch cluster.
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'>;
|
||||
export declare type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'close' | 'diagnostic'>;
|
||||
```
|
||||
|
|
|
@ -15,7 +15,7 @@ import type { Client } from '@elastic/elasticsearch';
|
|||
*/
|
||||
export type ElasticsearchClient = Omit<
|
||||
Client,
|
||||
'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'
|
||||
'connectionPool' | 'serializer' | 'extend' | 'close' | 'diagnostic'
|
||||
>;
|
||||
|
||||
/**
|
||||
|
|
|
@ -886,7 +886,7 @@ export { EcsEventOutcome }
|
|||
export { EcsEventType }
|
||||
|
||||
// @public
|
||||
export type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'>;
|
||||
export type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'close' | 'diagnostic'>;
|
||||
|
||||
// @public
|
||||
export type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'compression' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password' | 'serviceAccountToken'> & {
|
||||
|
|
|
@ -9,7 +9,6 @@ import { Client } from '@elastic/elasticsearch';
|
|||
import { loggingSystemMock } from 'src/core/server/mocks';
|
||||
import { elasticsearchServiceMock } from '../../../../../src/core/server/mocks';
|
||||
import { createWrappedScopedClusterClientFactory } from './wrap_scoped_cluster_client';
|
||||
import { ElasticsearchClientWithChild } from '../types';
|
||||
|
||||
const esQuery = {
|
||||
body: { query: { bool: { filter: { range: { '@timestamp': { gte: 0 } } } } } },
|
||||
|
@ -41,9 +40,7 @@ describe('wrapScopedClusterClient', () => {
|
|||
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
const childClient = elasticsearchServiceMock.createElasticsearchClient();
|
||||
|
||||
(
|
||||
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
|
||||
).child.mockReturnValue(childClient as unknown as Client);
|
||||
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
|
||||
const asInternalUserWrappedSearchFn = childClient.search;
|
||||
|
||||
const wrappedSearchClient = createWrappedScopedClusterClientFactory({
|
||||
|
@ -62,9 +59,7 @@ describe('wrapScopedClusterClient', () => {
|
|||
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
const childClient = elasticsearchServiceMock.createElasticsearchClient();
|
||||
|
||||
(
|
||||
scopedClusterClient.asCurrentUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
|
||||
).child.mockReturnValue(childClient as unknown as Client);
|
||||
scopedClusterClient.asCurrentUser.child.mockReturnValue(childClient as unknown as Client);
|
||||
const asCurrentUserWrappedSearchFn = childClient.search;
|
||||
|
||||
const wrappedSearchClient = createWrappedScopedClusterClientFactory({
|
||||
|
@ -83,9 +78,7 @@ describe('wrapScopedClusterClient', () => {
|
|||
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
const childClient = elasticsearchServiceMock.createElasticsearchClient();
|
||||
|
||||
(
|
||||
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
|
||||
).child.mockReturnValue(childClient as unknown as Client);
|
||||
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
|
||||
const asInternalUserWrappedSearchFn = childClient.search;
|
||||
|
||||
const wrappedSearchClient = createWrappedScopedClusterClientFactory({
|
||||
|
@ -106,9 +99,7 @@ describe('wrapScopedClusterClient', () => {
|
|||
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
const childClient = elasticsearchServiceMock.createElasticsearchClient();
|
||||
|
||||
(
|
||||
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
|
||||
).child.mockReturnValue(childClient as unknown as Client);
|
||||
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
|
||||
const asInternalUserWrappedSearchFn = childClient.search;
|
||||
|
||||
asInternalUserWrappedSearchFn.mockRejectedValueOnce(new Error('something went wrong!'));
|
||||
|
@ -127,9 +118,7 @@ describe('wrapScopedClusterClient', () => {
|
|||
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
const childClient = elasticsearchServiceMock.createElasticsearchClient();
|
||||
|
||||
(
|
||||
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
|
||||
).child.mockReturnValue(childClient as unknown as Client);
|
||||
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
|
||||
const asInternalUserWrappedSearchFn = childClient.search;
|
||||
// @ts-ignore incomplete return type
|
||||
asInternalUserWrappedSearchFn.mockResolvedValue({});
|
||||
|
@ -156,9 +145,7 @@ describe('wrapScopedClusterClient', () => {
|
|||
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
const childClient = elasticsearchServiceMock.createElasticsearchClient();
|
||||
|
||||
(
|
||||
scopedClusterClient.asInternalUser as unknown as jest.Mocked<ElasticsearchClientWithChild>
|
||||
).child.mockReturnValue(childClient as unknown as Client);
|
||||
scopedClusterClient.asInternalUser.child.mockReturnValue(childClient as unknown as Client);
|
||||
const asInternalUserWrappedSearchFn = childClient.search;
|
||||
// @ts-ignore incomplete return type
|
||||
asInternalUserWrappedSearchFn.mockResolvedValue({ took: 333 });
|
||||
|
|
|
@ -21,7 +21,7 @@ import type {
|
|||
AggregationsAggregate,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { IScopedClusterClient, ElasticsearchClient, Logger } from 'src/core/server';
|
||||
import { ElasticsearchClientWithChild, RuleExecutionMetrics } from '../types';
|
||||
import { RuleExecutionMetrics } from '../types';
|
||||
import { Alert as Rule } from '../types';
|
||||
|
||||
type RuleInfo = Pick<Rule, 'name' | 'alertTypeId' | 'id'> & { spaceId: string };
|
||||
|
@ -87,8 +87,7 @@ function wrapScopedClusterClient(opts: WrapScopedClusterClientOpts): IScopedClus
|
|||
function wrapEsClient(opts: WrapEsClientOpts): ElasticsearchClient {
|
||||
const { esClient, ...rest } = opts;
|
||||
|
||||
// Core hides access to .child via TS
|
||||
const wrappedClient = (esClient as ElasticsearchClientWithChild).child({});
|
||||
const wrappedClient = esClient.child({});
|
||||
|
||||
// Mutating the functions we want to wrap
|
||||
wrappedClient.search = getWrappedSearchFn({ esClient: wrappedClient, ...rest });
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Client } from '@elastic/elasticsearch';
|
||||
import type {
|
||||
IRouter,
|
||||
RequestHandlerContext,
|
||||
SavedObjectReference,
|
||||
ElasticsearchClient,
|
||||
IUiSettingsClient,
|
||||
} from 'src/core/server';
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
|
@ -48,10 +46,6 @@ import { IAbortableClusterClient } from './lib/create_abortable_es_client_factor
|
|||
export type WithoutQueryAndParams<T> = Pick<T, Exclude<keyof T, 'query' | 'params'>>;
|
||||
export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefined;
|
||||
|
||||
export interface ElasticsearchClientWithChild extends ElasticsearchClient {
|
||||
child: Client['child'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue