Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ export const findSLOGroupsRoute = createSloServerRoute({
await assertPlatinumLicense(plugins);
const { scopedClusterClient, soClient, spaceId } = await getScopedClients({ request, logger });

const findSLOGroups = new FindSLOGroups(
scopedClusterClient.asCurrentUser,
soClient,
logger,
spaceId
);
const findSLOGroups = new FindSLOGroups(scopedClusterClient, soClient, logger, spaceId);
return await findSLOGroups.execute(params?.query ?? {});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const findSLORoute = createSloServerRoute({
});

const summarySearchClient = new DefaultSummarySearchClient(
scopedClusterClient.asCurrentUser,
scopedClusterClient,
soClient,
logger,
spaceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getSLOStatsOverview = createSloServerRoute({

const slosOverview = new GetSLOStatsOverview(
soClient,
scopedClusterClient.asCurrentUser,
scopedClusterClient,
spaceId,
logger,
rulesClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ElasticsearchClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
import { IScopedClusterClient, Logger, SavedObjectsClientContract } from '@kbn/core/server';
import {
FindSLOGroupsParams,
FindSLOGroupsResponse,
Expand Down Expand Up @@ -38,7 +38,7 @@ function toPagination(params: FindSLOGroupsParams): Pagination {

export class FindSLOGroups {
constructor(
private esClient: ElasticsearchClient,
private scopedClusterClient: IScopedClusterClient,
private soClient: SavedObjectsClientContract,
private logger: Logger,
private spaceId: string
Expand All @@ -53,11 +53,11 @@ export class FindSLOGroups {
const parsedFilters = parseStringFilters(filters, this.logger);

const settings = await getSloSettings(this.soClient);
const { indices } = await getSummaryIndices(this.esClient, settings);
const { indices } = await getSummaryIndices(this.scopedClusterClient.asInternalUser, settings);

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

const response = await typedSearch(this.esClient, {
const response = await typedSearch(this.scopedClusterClient.asCurrentUser, {
index: indices,
size: 0,
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { RulesClientApi } from '@kbn/alerting-plugin/server/types';
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import { Logger } from '@kbn/logging';
import { AlertConsumers, SLO_RULE_TYPE_IDS } from '@kbn/rule-data-utils';
Expand All @@ -20,7 +20,7 @@ import { getElasticsearchQueryOrThrow, parseStringFilters } from './transform_ge
export class GetSLOStatsOverview {
constructor(
private soClient: SavedObjectsClientContract,
private esClient: ElasticsearchClient,
private scopedClusterClient: IScopedClusterClient,
private spaceId: string,
private logger: Logger,
private rulesClient: RulesClientApi,
Expand All @@ -29,13 +29,13 @@ export class GetSLOStatsOverview {

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

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

const response = await typedSearch(this.esClient, {
const response = await typedSearch(this.scopedClusterClient.asCurrentUser, {
index: indices,
size: 0,
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../fixtures/summary_search_document';
import { DefaultSummarySearchClient } from './summary_search_client';
import type { Sort, SummarySearchClient } from './types';
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server';

const defaultSort: Sort = {
field: 'sli_value',
Expand All @@ -27,11 +28,13 @@ const defaultPagination: Pagination = {
};

describe('Summary Search Client', () => {
let esClientMock: ElasticsearchClientMock;
let scopedClusterClient: IScopedClusterClient;
let service: SummarySearchClient;
let esClientMock: ElasticsearchClientMock;

beforeEach(() => {
esClientMock = elasticsearchServiceMock.createElasticsearchClient();
scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
esClientMock = scopedClusterClient.asCurrentUser as ElasticsearchClientMock;
const soClientMock = {
getCurrentNamespace: jest.fn().mockReturnValue('default'),
get: jest.fn().mockResolvedValue({
Expand All @@ -42,7 +45,7 @@ describe('Summary Search Client', () => {
}),
} as any;
service = new DefaultSummarySearchClient(
esClientMock,
scopedClusterClient,
soClientMock,
loggerMock.create(),
'default'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

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

export class DefaultSummarySearchClient implements SummarySearchClient {
constructor(
private esClient: ElasticsearchClient,
private scopedClusterClient: IScopedClusterClient,
private soClient: SavedObjectsClientContract,
private logger: Logger,
private spaceId: string
Expand All @@ -47,7 +47,7 @@ export class DefaultSummarySearchClient implements SummarySearchClient {
): Promise<Paginated<SummaryResult>> {
const parsedFilters = parseStringFilters(filters, this.logger);
const settings = await getSloSettings(this.soClient);
const { indices } = await getSummaryIndices(this.esClient, settings);
const { indices } = await getSummaryIndices(this.scopedClusterClient.asInternalUser, settings);

const esParams = createEsParams({
index: indices,
Expand Down Expand Up @@ -83,7 +83,7 @@ export class DefaultSummarySearchClient implements SummarySearchClient {

try {
const summarySearch = await typedSearch<EsSummaryDocument, typeof esParams>(
this.esClient,
this.scopedClusterClient.asCurrentUser,
esParams
);

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

await this.esClient.deleteByQuery({
await this.scopedClusterClient.asCurrentUser.deleteByQuery({
index: SUMMARY_DESTINATION_INDEX_PATTERN,
wait_for_completion: false,
conflicts: 'proceed',
Expand Down