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 @@ -11,7 +11,6 @@ import {
groupBySchema,
groupingsSchema,
groupSummarySchema,
historicalSummarySchema,
metaSchema,
objectiveSchema,
sloSettingsSchema,
Expand All @@ -22,7 +21,6 @@ import {
type Objective = t.TypeOf<typeof objectiveSchema>;
type Status = t.TypeOf<typeof statusSchema>;
type DateRange = t.TypeOf<typeof dateRangeSchema>;
type HistoricalSummary = t.TypeOf<typeof historicalSummarySchema>;
type Summary = t.TypeOf<typeof summarySchema>;
type Groupings = t.TypeOf<typeof groupingsSchema>;
type Meta = t.TypeOf<typeof metaSchema>;
Expand All @@ -35,7 +33,6 @@ export type {
Objective,
DateRange,
Groupings,
HistoricalSummary,
Meta,
Status,
Summary,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
*/

export * from './errors';
export * from './handler';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@
* 2.0.
*/
import { createServerRouteFactory } from '@kbn/server-route-repository';
import { Boom, forbidden, notFound, conflict, badRequest } from '@hapi/boom';
import { CreateServerRouteFactory } from '@kbn/server-route-repository-utils/src/typings';
import { SLORouteHandlerResources } from './types';
import { SLOError, SLONotFound, SLOIdConflict, SecurityException } from '../errors';

export const createSloServerRoute = createServerRouteFactory<SLORouteHandlerResources>();
function handleSLOError(error: SLOError): Boom {
if (error instanceof SLONotFound) {
return notFound(error.message);
}

if (error instanceof SLOIdConflict) {
return conflict(error.message);
}

if (error instanceof SecurityException) {
return forbidden(error.message);
}

return badRequest(error.message);
}

const createPlainSloServerRoute = createServerRouteFactory<SLORouteHandlerResources>();

export const createSloServerRoute: CreateServerRouteFactory<
SLORouteHandlerResources,
undefined
> = ({ handler, ...config }) => {
return createPlainSloServerRoute({
...config,
handler: (options) => {
return handler(options).catch((error) => {
if (error instanceof SLOError) {
throw handleSLOError(error);
}
throw error;
});
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
*/

import { createSLOParamsSchema } from '@kbn/slo-schema';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
import { getSpaceId } from './utils/get_space_id';
import { createTransformGenerators } from '../../services/transform_generators';
import { DefaultSummaryTransformGenerator } from '../../services/summary_transform_generator/summary_transform_generator';
import { executeWithErrorHandler } from '../../errors';
import {
CreateSLO,
DefaultSummaryTransformManager,
DefaultTransformManager,
KibanaSavedObjectsSLORepository,
} from '../../services';
import { DefaultSummaryTransformGenerator } from '../../services/summary_transform_generator/summary_transform_generator';
import { createTransformGenerators } from '../../services/transform_generators';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
import { getSpaceId } from './utils/get_space_id';

export const createSLORoute = createSloServerRoute({
endpoint: 'POST /api/observability/slos 2023-10-31',
Expand Down Expand Up @@ -74,6 +73,6 @@ export const createSLORoute = createSloServerRoute({
userId
);

return await executeWithErrorHandler(() => createSLO.execute(params.body));
return await createSLO.execute(params.body);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { deleteSLOInstancesParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { DeleteSLOInstances } from '../../services';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
Expand All @@ -26,7 +25,7 @@ export const deleteSloInstancesRoute = createSloServerRoute({
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const deleteSloInstances = new DeleteSLOInstances(esClient);

await executeWithErrorHandler(() => deleteSloInstances.execute(params.body));
await deleteSloInstances.execute(params.body);
return response.noContent();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { deleteSLOParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import {
DefaultSummaryTransformManager,
DefaultTransformManager,
Expand Down Expand Up @@ -72,7 +71,7 @@ export const deleteSLORoute = createSloServerRoute({
rulesClient
);

await executeWithErrorHandler(() => deleteSLO.execute(params.path.id));
await deleteSLO.execute(params.path.id);
return response.noContent();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { manageSLOParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import {
DefaultSummaryTransformManager,
DefaultTransformManager,
Expand Down Expand Up @@ -60,7 +59,7 @@ export const disableSLORoute = createSloServerRoute({

const manageSLO = new ManageSLO(repository, transformManager, summaryTransformManager);

await executeWithErrorHandler(() => manageSLO.disable(params.path.id));
await manageSLO.disable(params.path.id);
return response.noContent();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { manageSLOParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import {
DefaultSummaryTransformManager,
DefaultTransformManager,
Expand Down Expand Up @@ -60,7 +59,7 @@ export const enableSLORoute = createSloServerRoute({

const manageSLO = new ManageSLO(repository, transformManager, summaryTransformManager);

await executeWithErrorHandler(() => manageSLO.enable(params.path.id));
await manageSLO.enable(params.path.id);

return response.noContent();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { fetchSLOHealthParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { GetSLOHealth, KibanaSavedObjectsSLORepository } from '../../services';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
Expand All @@ -31,6 +30,6 @@ export const fetchSloHealthRoute = createSloServerRoute({

const getSLOHealth = new GetSLOHealth(esClient, scopedClusterClient, repository);

return await executeWithErrorHandler(() => getSLOHealth.execute(params.body));
return await getSLOHealth.execute(params.body);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import { fetchHistoricalSummaryParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { DefaultHistoricalSummaryClient } from '../../services/historical_summary_client';
import { HistoricalSummaryClient } from '../../services/historical_summary_client';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';

Expand All @@ -24,8 +23,8 @@ export const fetchHistoricalSummary = createSloServerRoute({
await assertPlatinumLicense(plugins);

const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const historicalSummaryClient = new DefaultHistoricalSummaryClient(esClient);
const historicalSummaryClient = new HistoricalSummaryClient(esClient);

return await executeWithErrorHandler(() => historicalSummaryClient.fetch(params.body));
return await historicalSummaryClient.fetch(params.body);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { findSloDefinitionsParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { KibanaSavedObjectsSLORepository } from '../../services';
import { FindSLODefinitions } from '../../services/find_slo_definitions';
import { createSloServerRoute } from '../create_slo_server_route';
Expand All @@ -28,6 +27,6 @@ export const findSloDefinitionsRoute = createSloServerRoute({
const repository = new KibanaSavedObjectsSLORepository(soClient, logger);
const findSloDefinitions = new FindSLODefinitions(repository);

return await executeWithErrorHandler(() => findSloDefinitions.execute(params?.query ?? {}));
return await findSloDefinitions.execute(params?.query ?? {});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { findSLOGroupsParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { FindSLOGroups } from '../../services';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
Expand All @@ -29,6 +28,6 @@ export const findSLOGroupsRoute = createSloServerRoute({
const coreContext = context.core;
const esClient = (await coreContext).elasticsearch.client.asCurrentUser;
const findSLOGroups = new FindSLOGroups(esClient, soClient, logger, spaceId);
return await executeWithErrorHandler(() => findSLOGroups.execute(params?.query ?? {}));
return await findSLOGroups.execute(params?.query ?? {});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { findSLOParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { FindSLO, KibanaSavedObjectsSLORepository } from '../../services';
import { DefaultSummarySearchClient } from '../../services/summary_search_client/summary_search_client';
import { createSloServerRoute } from '../create_slo_server_route';
Expand All @@ -33,6 +32,6 @@ export const findSLORoute = createSloServerRoute({

const findSLO = new FindSLO(repository, summarySearchClient);

return await executeWithErrorHandler(() => findSLO.execute(params?.query ?? {}));
return await findSLO.execute(params?.query ?? {});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { getSLOGroupingsParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { KibanaSavedObjectsSLORepository } from '../../services';
import { GetSLOGroupings } from '../../services/get_slo_groupings';
import { SloDefinitionClient } from '../../services/slo_definition_client';
Expand Down Expand Up @@ -38,8 +37,6 @@ export const getSLOGroupingsRoute = createSloServerRoute({

const getSLOGroupings = new GetSLOGroupings(definitionClient, esClient, settings, spaceId);

return await executeWithErrorHandler(() =>
getSLOGroupings.execute(params.path.id, params.query)
);
return await getSLOGroupings.execute(params.path.id, params.query);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { getSLOParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import {
DefaultBurnRatesClient,
DefaultSummaryClient,
Expand Down Expand Up @@ -40,8 +39,6 @@ export const getSLORoute = createSloServerRoute({
const definitionClient = new SloDefinitionClient(repository, esClient, logger);
const getSLO = new GetSLO(definitionClient, summaryClient);

return await executeWithErrorHandler(() =>
getSLO.execute(params.path.id, spaceId, params.query)
);
return await getSLO.execute(params.path.id, spaceId, params.query);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { getSLOBurnRatesParamsSchema } from '@kbn/slo-schema';
import { executeWithErrorHandler } from '../../errors';
import { getBurnRates } from '../../services/get_burn_rates';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
Expand All @@ -30,19 +29,17 @@ export const getSloBurnRates = createSloServerRoute({
const soClient = (await context.core).savedObjects.client;
const { instanceId, windows, remoteName } = params.body;

return await executeWithErrorHandler(() =>
getBurnRates({
instanceId,
spaceId,
windows,
remoteName,
sloId: params.path.id,
services: {
soClient,
esClient,
logger,
},
})
);
return await getBurnRates({
instanceId,
spaceId,
windows,
remoteName,
sloId: params.path.id,
services: {
soClient,
esClient,
logger,
},
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { executeWithErrorHandler } from '../../errors';
import { getSloSettings } from '../../services/slo_settings';
import { createSloServerRoute } from '../create_slo_server_route';
import { assertPlatinumLicense } from './utils/assert_platinum_license';
Expand All @@ -23,6 +22,6 @@ export const getSloSettingsRoute = createSloServerRoute({

const soClient = (await context.core).savedObjects.client;

return await executeWithErrorHandler(() => getSloSettings(soClient));
return await getSloSettings(soClient);
},
});
Loading