Skip to content

Commit ac4adf1

Browse files
[9.1] [SLO] Use internal es client for fetching remote cluster info !! (#224870) (#226410)
# Backport This will backport the following commits from `main` to `9.1`: - [[SLO] Use internal es client for fetching remote cluster info !! (#224870)](#224870) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-07-03T12:24:13Z","message":"[SLO] Use internal es client for fetching remote cluster info !! (#224870)\n\n## Summary\n\nUse internal es client for fetching remote cluster info !!","sha":"f3e826cbf68c2dfd74113440a14c744c18b76931","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0","v9.0.3","v8.18.3","v8.17.8","v9.2.0"],"title":"[SLO] Use internal es client for fetching remote cluster info !!","number":224870,"url":"https://github.com/elastic/kibana/pull/224870","mergeCommit":{"message":"[SLO] Use internal es client for fetching remote cluster info !! (#224870)\n\n## Summary\n\nUse internal es client for fetching remote cluster info !!","sha":"f3e826cbf68c2dfd74113440a14c744c18b76931"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.0","8.18","8.17"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.8","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224870","number":224870,"mergeCommit":{"message":"[SLO] Use internal es client for fetching remote cluster info !! (#224870)\n\n## Summary\n\nUse internal es client for fetching remote cluster info !!","sha":"f3e826cbf68c2dfd74113440a14c744c18b76931"}}]}] BACKPORT--> Co-authored-by: Shahzad <[email protected]>
1 parent c7c96dc commit ac4adf1

File tree

7 files changed

+22
-24
lines changed

7 files changed

+22
-24
lines changed

x-pack/solutions/observability/plugins/slo/server/routes/slo/find_groups.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ export const findSLOGroupsRoute = createSloServerRoute({
2323
await assertPlatinumLicense(plugins);
2424
const { scopedClusterClient, soClient, spaceId } = await getScopedClients({ request, logger });
2525

26-
const findSLOGroups = new FindSLOGroups(
27-
scopedClusterClient.asCurrentUser,
28-
soClient,
29-
logger,
30-
spaceId
31-
);
26+
const findSLOGroups = new FindSLOGroups(scopedClusterClient, soClient, logger, spaceId);
3227
return await findSLOGroups.execute(params?.query ?? {});
3328
},
3429
});

x-pack/solutions/observability/plugins/slo/server/routes/slo/find_slo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const findSLORoute = createSloServerRoute({
2828
});
2929

3030
const summarySearchClient = new DefaultSummarySearchClient(
31-
scopedClusterClient.asCurrentUser,
31+
scopedClusterClient,
3232
soClient,
3333
logger,
3434
spaceId

x-pack/solutions/observability/plugins/slo/server/routes/slo/get_slo_stats_overview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const getSLOStatsOverview = createSloServerRoute({
2929

3030
const slosOverview = new GetSLOStatsOverview(
3131
soClient,
32-
scopedClusterClient.asCurrentUser,
32+
scopedClusterClient,
3333
spaceId,
3434
logger,
3535
rulesClient,

x-pack/solutions/observability/plugins/slo/server/services/find_slo_groups.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
import { ElasticsearchClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
7+
import { IScopedClusterClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
88
import {
99
FindSLOGroupsParams,
1010
FindSLOGroupsResponse,
@@ -38,7 +38,7 @@ function toPagination(params: FindSLOGroupsParams): Pagination {
3838

3939
export class FindSLOGroups {
4040
constructor(
41-
private esClient: ElasticsearchClient,
41+
private scopedClusterClient: IScopedClusterClient,
4242
private soClient: SavedObjectsClientContract,
4343
private logger: Logger,
4444
private spaceId: string
@@ -53,11 +53,11 @@ export class FindSLOGroups {
5353
const parsedFilters = parseStringFilters(filters, this.logger);
5454

5555
const settings = await getSloSettings(this.soClient);
56-
const { indices } = await getSummaryIndices(this.esClient, settings);
56+
const { indices } = await getSummaryIndices(this.scopedClusterClient.asInternalUser, settings);
5757

5858
const hasSelectedTags = groupBy === 'slo.tags' && groupsFilter.length > 0;
5959

60-
const response = await typedSearch(this.esClient, {
60+
const response = await typedSearch(this.scopedClusterClient.asCurrentUser, {
6161
index: indices,
6262
size: 0,
6363
query: {

x-pack/solutions/observability/plugins/slo/server/services/get_slo_stats_overview.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { RulesClientApi } from '@kbn/alerting-plugin/server/types';
9-
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
9+
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
1010
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
1111
import { Logger } from '@kbn/logging';
1212
import { AlertConsumers, SLO_RULE_TYPE_IDS } from '@kbn/rule-data-utils';
@@ -20,7 +20,7 @@ import { getElasticsearchQueryOrThrow, parseStringFilters } from './transform_ge
2020
export class GetSLOStatsOverview {
2121
constructor(
2222
private soClient: SavedObjectsClientContract,
23-
private esClient: ElasticsearchClient,
23+
private scopedClusterClient: IScopedClusterClient,
2424
private spaceId: string,
2525
private logger: Logger,
2626
private rulesClient: RulesClientApi,
@@ -29,13 +29,13 @@ export class GetSLOStatsOverview {
2929

3030
public async execute(params: GetSLOStatsOverviewParams): Promise<GetSLOStatsOverviewResponse> {
3131
const settings = await getSloSettings(this.soClient);
32-
const { indices } = await getSummaryIndices(this.esClient, settings);
32+
const { indices } = await getSummaryIndices(this.scopedClusterClient.asInternalUser, settings);
3333

3434
const kqlQuery = params.kqlQuery ?? '';
3535
const filters = params.filters ?? '';
3636
const parsedFilters = parseStringFilters(filters, this.logger);
3737

38-
const response = await typedSearch(this.esClient, {
38+
const response = await typedSearch(this.scopedClusterClient.asCurrentUser, {
3939
index: indices,
4040
size: 0,
4141
query: {

x-pack/solutions/observability/plugins/slo/server/services/summary_search_client/summary_search_client.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '../fixtures/summary_search_document';
1717
import { DefaultSummarySearchClient } from './summary_search_client';
1818
import type { Sort, SummarySearchClient } from './types';
19+
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
1920

2021
const defaultSort: Sort = {
2122
field: 'sli_value',
@@ -27,11 +28,13 @@ const defaultPagination: Pagination = {
2728
};
2829

2930
describe('Summary Search Client', () => {
30-
let esClientMock: ElasticsearchClientMock;
31+
let scopedClusterClient: IScopedClusterClient;
3132
let service: SummarySearchClient;
33+
let esClientMock: ElasticsearchClientMock;
3234

3335
beforeEach(() => {
34-
esClientMock = elasticsearchServiceMock.createElasticsearchClient();
36+
scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
37+
esClientMock = scopedClusterClient.asCurrentUser as ElasticsearchClientMock;
3538
const soClientMock = {
3639
getCurrentNamespace: jest.fn().mockReturnValue('default'),
3740
get: jest.fn().mockResolvedValue({
@@ -42,7 +45,7 @@ describe('Summary Search Client', () => {
4245
}),
4346
} as any;
4447
service = new DefaultSummarySearchClient(
45-
esClientMock,
48+
scopedClusterClient,
4649
soClientMock,
4750
loggerMock.create(),
4851
'default'

x-pack/solutions/observability/plugins/slo/server/services/summary_search_client/summary_search_client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import type { estypes } from '@elastic/elasticsearch';
9-
import { ElasticsearchClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
9+
import { IScopedClusterClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
1010
import { isCCSRemoteIndexName } from '@kbn/es-query';
1111
import { ALL_VALUE } from '@kbn/slo-schema';
1212
import { assertNever } from '@kbn/std';
@@ -32,7 +32,7 @@ import { isCursorPagination } from './types';
3232

3333
export class DefaultSummarySearchClient implements SummarySearchClient {
3434
constructor(
35-
private esClient: ElasticsearchClient,
35+
private scopedClusterClient: IScopedClusterClient,
3636
private soClient: SavedObjectsClientContract,
3737
private logger: Logger,
3838
private spaceId: string
@@ -47,7 +47,7 @@ export class DefaultSummarySearchClient implements SummarySearchClient {
4747
): Promise<Paginated<SummaryResult>> {
4848
const parsedFilters = parseStringFilters(filters, this.logger);
4949
const settings = await getSloSettings(this.soClient);
50-
const { indices } = await getSummaryIndices(this.esClient, settings);
50+
const { indices } = await getSummaryIndices(this.scopedClusterClient.asInternalUser, settings);
5151

5252
const esParams = createEsParams({
5353
index: indices,
@@ -83,7 +83,7 @@ export class DefaultSummarySearchClient implements SummarySearchClient {
8383

8484
try {
8585
const summarySearch = await typedSearch<EsSummaryDocument, typeof esParams>(
86-
this.esClient,
86+
this.scopedClusterClient.asCurrentUser,
8787
esParams
8888
);
8989

@@ -173,7 +173,7 @@ export class DefaultSummarySearchClient implements SummarySearchClient {
173173
// Always attempt to delete temporary summary documents with an existing non-temp summary document
174174
// The temp summary documents are _eventually_ removed as we get through the real summary documents
175175

176-
await this.esClient.deleteByQuery({
176+
await this.scopedClusterClient.asCurrentUser.deleteByQuery({
177177
index: SUMMARY_DESTINATION_INDEX_PATTERN,
178178
wait_for_completion: false,
179179
conflicts: 'proceed',

0 commit comments

Comments
 (0)