Skip to content

Commit

Permalink
fix(slo): handle invalid stored SLO (#175125)
Browse files Browse the repository at this point in the history
(cherry picked from commit ed41989)

# Conflicts:
#	x-pack/plugins/observability/server/routes/slo/route.ts
#	x-pack/plugins/observability/server/services/slo/slo_repository.ts
  • Loading branch information
kdelemme committed Jan 24, 2024
1 parent 8471403 commit 369e302
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const getRuleExecutor = ({
async function executor({
services,
params,
logger,
startedAt,
spaceId,
getTimeRange,
Expand All @@ -82,7 +83,7 @@ export const getRuleExecutor = ({
getAlertUuid,
} = services;

const sloRepository = new KibanaSavedObjectsSLORepository(soClient);
const sloRepository = new KibanaSavedObjectsSLORepository(soClient, logger);
const slo = await sloRepository.findById(params.sloId);

if (!slo.enabled) {
Expand Down
33 changes: 17 additions & 16 deletions x-pack/plugins/observability/server/routes/slo/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const createSLORoute = createObservabilityServerRoute({

const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const soClient = (await context.core).savedObjects.client;
const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(transformGenerators, esClient, logger);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
Expand Down Expand Up @@ -129,7 +129,7 @@ const updateSLORoute = createObservabilityServerRoute({
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const soClient = (await context.core).savedObjects.client;

const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(transformGenerators, esClient, logger);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
Expand Down Expand Up @@ -172,7 +172,7 @@ const deleteSLORoute = createObservabilityServerRoute({
const soClient = (await context.core).savedObjects.client;
const rulesClient = getRulesClientWithRequest(request);

const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(transformGenerators, esClient, logger);

const summaryTransformManager = new DefaultSummaryTransformManager(
Expand Down Expand Up @@ -200,12 +200,12 @@ const getSLORoute = createObservabilityServerRoute({
access: 'public',
},
params: getSLOParamsSchema,
handler: async ({ context, params }) => {
handler: async ({ context, params, logger }) => {
await assertPlatinumLicense(context);

const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const summaryClient = new DefaultSummaryClient(esClient);
const getSLO = new GetSLO(repository, summaryClient);

Expand All @@ -228,7 +228,7 @@ const enableSLORoute = createObservabilityServerRoute({
const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;

const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(transformGenerators, esClient, logger);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
Expand Down Expand Up @@ -257,7 +257,7 @@ const disableSLORoute = createObservabilityServerRoute({
const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;

const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(transformGenerators, esClient, logger);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
Expand Down Expand Up @@ -288,7 +288,7 @@ const resetSLORoute = createObservabilityServerRoute({
const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;

const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const transformManager = new DefaultTransformManager(transformGenerators, esClient, logger);
const summaryTransformManager = new DefaultSummaryTransformManager(
new DefaultSummaryTransformGenerator(),
Expand Down Expand Up @@ -326,7 +326,7 @@ const findSLORoute = createObservabilityServerRoute({

const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const summarySearchClient = new DefaultSummarySearchClient(esClient, logger, spaceId);
const findSLO = new FindSLO(repository, summarySearchClient);

Expand Down Expand Up @@ -358,11 +358,11 @@ const findSloDefinitionsRoute = createObservabilityServerRoute({
tags: ['access:slo_read'],
},
params: findSloDefinitionsParamsSchema,
handler: async ({ context, params }) => {
handler: async ({ context, params, logger }) => {
await assertPlatinumLicense(context);

const soClient = (await context.core).savedObjects.client;
const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const findSloDefinitions = new FindSLODefinitions(repository);

const response = await findSloDefinitions.execute(params?.query ?? {});
Expand All @@ -377,12 +377,12 @@ const fetchHistoricalSummary = createObservabilityServerRoute({
tags: ['access:slo_read'],
},
params: fetchHistoricalSummaryParamsSchema,
handler: async ({ context, params }) => {
handler: async ({ context, params, logger }) => {
await assertPlatinumLicense(context);

const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const historicalSummaryClient = new DefaultHistoricalSummaryClient(esClient);

const fetchSummaryData = new FetchHistoricalSummary(repository, historicalSummaryClient);
Expand All @@ -400,12 +400,12 @@ const getSLOInstancesRoute = createObservabilityServerRoute({
access: 'internal',
},
params: getSLOInstancesParamsSchema,
handler: async ({ context, params }) => {
handler: async ({ context, params, logger }) => {
await assertPlatinumLicense(context);

const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);

const getSLOInstances = new GetSLOInstances(repository, esClient);

Expand Down Expand Up @@ -445,7 +445,7 @@ const getSloBurnRates = createObservabilityServerRoute({
access: 'internal',
},
params: getSLOBurnRatesParamsSchema,
handler: async ({ context, params }) => {
handler: async ({ context, params, logger }) => {
await assertPlatinumLicense(context);

const esClient = (await context.core).elasticsearch.client.asCurrentUser;
Expand All @@ -457,6 +457,7 @@ const getSloBurnRates = createObservabilityServerRoute({
{
soClient,
esClient,
logger,
}
);
return { burnRates };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* 2.0.
*/

import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { KibanaSavedObjectsSLORepository } from './slo_repository';
import { DefaultSLIClient } from './sli_client';
import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import { Logger } from '@kbn/core/server';
import { Duration } from '../../domain/models';
import { computeSLI, computeBurnRate } from '../../domain/services';
import { computeBurnRate, computeSLI } from '../../domain/services';
import { DefaultSLIClient } from './sli_client';
import { KibanaSavedObjectsSLORepository } from './slo_repository';

interface Services {
soClient: SavedObjectsClientContract;
esClient: ElasticsearchClient;
logger: Logger;
}

interface LookbackWindow {
Expand All @@ -28,9 +30,9 @@ export async function getBurnRates(
windows: LookbackWindow[],
services: Services
) {
const { soClient, esClient } = services;
const { soClient, esClient, logger } = services;

const repository = new KibanaSavedObjectsSLORepository(soClient);
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const sliClient = new DefaultSLIClient(esClient);
const slo = await repository.findById(sloId);

Expand Down
Loading

0 comments on commit 369e302

Please sign in to comment.