Skip to content

Commit

Permalink
[Alerting] Add scoped cluster client to alerts and actions services (#…
Browse files Browse the repository at this point in the history
…80794)

* Add scoped cluster client to alerts and actions services.

* Modify functional test to use new ES client.
  • Loading branch information
justinkambic authored Oct 20, 2020
1 parent c5bcef4 commit cc43b14
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const createServicesMock = () => {
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
getLegacyScopedClusterClient: jest.fn(),
savedObjectsClient: savedObjectsClientMock.create(),
scopedClusterClient: elasticsearchServiceMock.createScopedClusterClient().asCurrentUser,
};
return mock;
};
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ export class ActionsPlugin implements Plugin<Promise<PluginSetupContract>, Plugi
return (request) => ({
callCluster: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
savedObjectsClient: getScopedClient(request),
scopedClusterClient: elasticsearch.client.asScoped(request).asCurrentUser,
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient) {
return clusterClient.asScoped(request);
},
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/actions/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
KibanaRequest,
SavedObjectsClientContract,
SavedObjectAttributes,
ElasticsearchClient,
} from '../../../../src/core/server';
import { ActionTypeExecutorResult } from '../common';
export { ActionTypeExecutorResult } from '../common';
Expand All @@ -30,6 +31,7 @@ export type ActionTypeParams = Record<string, unknown>;
export interface Services {
callCluster: ILegacyScopedClusterClient['callAsCurrentUser'];
savedObjectsClient: SavedObjectsClientContract;
scopedClusterClient: ElasticsearchClient;
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient): ILegacyScopedClusterClient;
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const createAlertServicesMock = () => {
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
getLegacyScopedClusterClient: jest.fn(),
savedObjectsClient: savedObjectsClientMock.create(),
scopedClusterClient: elasticsearchServiceMock.createScopedClusterClient().asCurrentUser,
};
};
export type AlertServicesMock = ReturnType<typeof createAlertServicesMock>;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class AlertingPlugin {
return (request) => ({
callCluster: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
savedObjectsClient: this.getScopedClientWithAlertSavedObjectType(savedObjects, request),
scopedClusterClient: elasticsearch.client.asScoped(request).asCurrentUser,
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient) {
return clusterClient.asScoped(request);
},
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerts/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PluginSetupContract, PluginStartContract } from './plugin';
import { AlertsClient } from './alerts_client';
export * from '../common';
import {
ElasticsearchClient,
ILegacyClusterClient,
ILegacyScopedClusterClient,
KibanaRequest,
Expand Down Expand Up @@ -45,6 +46,7 @@ declare module 'src/core/server' {
export interface Services {
callCluster: ILegacyScopedClusterClient['callAsCurrentUser'];
savedObjectsClient: SavedObjectsClientContract;
scopedClusterClient: ElasticsearchClient;
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient): ILegacyScopedClusterClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function getAlwaysFiringAlertType() {
instanceContextValue: true,
});
}
await services.callCluster('index', {
await services.scopedClusterClient.index({
index: params.index,
refresh: 'wait_for',
body: {
Expand Down

0 comments on commit cc43b14

Please sign in to comment.