diff --git a/x-pack/packages/kbn-slo-schema/src/rest_specs/routes/put_settings.ts b/x-pack/packages/kbn-slo-schema/src/rest_specs/routes/put_settings.ts index ff5e4a1d98051..9bd8b8ca0e95f 100644 --- a/x-pack/packages/kbn-slo-schema/src/rest_specs/routes/put_settings.ts +++ b/x-pack/packages/kbn-slo-schema/src/rest_specs/routes/put_settings.ts @@ -5,17 +5,25 @@ * 2.0. */ import * as t from 'io-ts'; -import { sloSettingsSchema } from '../../schema/settings'; +import { sloServerlessSettingsSchema, sloSettingsSchema } from '../../schema/settings'; const putSLOSettingsParamsSchema = t.type({ body: sloSettingsSchema, }); +const putSLOServerlessSettingsParamsSchema = t.type({ + body: sloServerlessSettingsSchema, +}); + const putSLOSettingsResponseSchema = sloSettingsSchema; type PutSLOSettingsParams = t.TypeOf; type PutSLOSettingsResponse = t.OutputOf; type GetSLOSettingsResponse = t.OutputOf; -export { putSLOSettingsParamsSchema, putSLOSettingsResponseSchema }; +export { + putSLOSettingsParamsSchema, + putSLOSettingsResponseSchema, + putSLOServerlessSettingsParamsSchema, +}; export type { PutSLOSettingsParams, PutSLOSettingsResponse, GetSLOSettingsResponse }; diff --git a/x-pack/packages/kbn-slo-schema/src/schema/settings.ts b/x-pack/packages/kbn-slo-schema/src/schema/settings.ts index 5eb7e7b23abf3..c4f797e427c48 100644 --- a/x-pack/packages/kbn-slo-schema/src/schema/settings.ts +++ b/x-pack/packages/kbn-slo-schema/src/schema/settings.ts @@ -11,3 +11,5 @@ export const sloSettingsSchema = t.type({ useAllRemoteClusters: t.boolean, selectedRemoteClusters: t.array(t.string), }); + +export const sloServerlessSettingsSchema = t.type({}); diff --git a/x-pack/plugins/observability_solution/slo/public/application.tsx b/x-pack/plugins/observability_solution/slo/public/application.tsx index 7d74467e6868c..9cf739f5e543a 100644 --- a/x-pack/plugins/observability_solution/slo/public/application.tsx +++ b/x-pack/plugins/observability_solution/slo/public/application.tsx @@ -21,18 +21,22 @@ import { Storage } from '@kbn/kibana-utils-plugin/public'; import { ObservabilityRuleTypeRegistry } from '@kbn/observability-plugin/public'; import { i18n } from '@kbn/i18n'; +import { usePluginContext } from './hooks/use_plugin_context'; import { PluginContext } from './context/plugin_context'; import { SloPublicPluginsStart } from './types'; -import { routes } from './routes/routes'; +import { getRoutes } from './routes/routes'; import { ExperimentalFeatures } from '../common/config'; function App() { + const { isServerless } = usePluginContext(); + + const routes = getRoutes(isServerless); + return ( <> - {Object.keys(routes).map((key) => { - const path = key as keyof typeof routes; + {Object.keys(routes).map((path) => { const { handler, exact } = routes[path]; const Wrapper = () => { return handler(); @@ -124,6 +128,7 @@ export const renderApp = ({ - - {i18n.translate('xpack.slo.headerMenu.settings', { - defaultMessage: 'Settings', - })} - + {!isServerless && ( + + {i18n.translate('xpack.slo.headerMenu.settings', { + defaultMessage: 'Settings', + })} + + )} diff --git a/x-pack/plugins/observability_solution/slo/public/context/plugin_context.tsx b/x-pack/plugins/observability_solution/slo/public/context/plugin_context.tsx index 13e0158e92055..1f8d6f25e0961 100644 --- a/x-pack/plugins/observability_solution/slo/public/context/plugin_context.tsx +++ b/x-pack/plugins/observability_solution/slo/public/context/plugin_context.tsx @@ -13,6 +13,7 @@ import { ExperimentalFeatures } from '../../common/config'; export interface PluginContextValue { isDev?: boolean; + isServerless?: boolean; appMountParameters?: AppMountParameters; observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry; ObservabilityPageTemplate: React.ComponentType; diff --git a/x-pack/plugins/observability_solution/slo/public/routes/routes.tsx b/x-pack/plugins/observability_solution/slo/public/routes/routes.tsx index 98243caec301e..ebf14ea4a7df0 100644 --- a/x-pack/plugins/observability_solution/slo/public/routes/routes.tsx +++ b/x-pack/plugins/observability_solution/slo/public/routes/routes.tsx @@ -22,54 +22,68 @@ import { import { SlosOutdatedDefinitions } from '../pages/slo_outdated_definitions'; import { SloSettingsPage } from '../pages/slo_settings/slo_settings'; -export const routes = { - [SLOS_PATH]: { - handler: () => { - return ; +export const getRoutes = ( + isServerless?: boolean +): { + [key: string]: { + handler: () => React.ReactElement; + params: Record; + exact: boolean; + }; +} => { + return { + [SLOS_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, }, - params: {}, - exact: true, - }, - [SLO_CREATE_PATH]: { - handler: () => { - return ; + [SLO_CREATE_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, }, - params: {}, - exact: true, - }, - [SLOS_WELCOME_PATH]: { - handler: () => { - return ; + [SLOS_WELCOME_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, }, - params: {}, - exact: true, - }, - [SLOS_OUTDATED_DEFINITIONS_PATH]: { - handler: () => { - return ; + [SLOS_OUTDATED_DEFINITIONS_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, }, - params: {}, - exact: true, - }, - [SLO_EDIT_PATH]: { - handler: () => { - return ; + [SLO_EDIT_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, }, - params: {}, - exact: true, - }, - [SLO_SETTINGS_PATH]: { - handler: () => { - return ; + ...(!isServerless + ? { + [SLO_SETTINGS_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, + }, + } + : {}), + [SLO_DETAIL_PATH]: { + handler: () => { + return ; + }, + params: {}, + exact: true, }, - params: {}, - exact: true, - }, - [SLO_DETAIL_PATH]: { - handler: () => { - return ; - }, - params: {}, - exact: true, - }, + }; }; diff --git a/x-pack/plugins/observability_solution/slo/server/plugin.ts b/x-pack/plugins/observability_solution/slo/server/plugin.ts index b61d0cc200adc..668d7cc6a51be 100644 --- a/x-pack/plugins/observability_solution/slo/server/plugin.ts +++ b/x-pack/plugins/observability_solution/slo/server/plugin.ts @@ -29,6 +29,7 @@ import { SpacesPluginSetup, SpacesPluginStart } from '@kbn/spaces-plugin/server' import { AlertsLocatorDefinition } from '@kbn/observability-plugin/common'; import { SLO_BURN_RATE_RULE_TYPE_ID } from '@kbn/rule-data-utils'; import { sloFeatureId } from '@kbn/observability-plugin/common'; +import { ServerlessPluginStart } from '@kbn/serverless/server'; import { registerSloUsageCollector } from './lib/collectors/register'; import { SloOrphanSummaryCleanupTask } from './services/tasks/orphan_summary_cleanup_task'; import { slo, SO_SLO_TYPE } from './saved_objects'; @@ -56,6 +57,7 @@ export interface PluginStart { alerting: PluginStartContract; taskManager: TaskManagerStartContract; spaces?: SpacesPluginStart; + serverless: ServerlessPluginStart; } const sloRuleTypes = [SLO_BURN_RATE_RULE_TYPE_ID]; @@ -150,7 +152,9 @@ export class SloPlugin implements Plugin { getRulesClientWithRequest: pluginStart.alerting.getRulesClientWithRequest, }, logger: this.logger, - repository: getSloServerRouteRepository(config), + repository: getSloServerRouteRepository({ + isServerless: !!pluginStart.serverless, + }), }); const esInternalClient = coreStart.elasticsearch.client.asInternalUser; diff --git a/x-pack/plugins/observability_solution/slo/server/routes/get_slo_server_route_repository.ts b/x-pack/plugins/observability_solution/slo/server/routes/get_slo_server_route_repository.ts index bd062771017fd..b04b6209054a9 100644 --- a/x-pack/plugins/observability_solution/slo/server/routes/get_slo_server_route_repository.ts +++ b/x-pack/plugins/observability_solution/slo/server/routes/get_slo_server_route_repository.ts @@ -5,14 +5,12 @@ * 2.0. */ -import { SloConfig } from '..'; -import { sloRouteRepository } from './slo/route'; +import { getSloRouteRepository } from './slo/route'; -export function getSloServerRouteRepository(config: SloConfig) { - const repository = { - ...sloRouteRepository, +export function getSloServerRouteRepository({ isServerless }: { isServerless?: boolean } = {}) { + return { + ...getSloRouteRepository(isServerless), }; - return repository; } export type SloServerRouteRepository = ReturnType; diff --git a/x-pack/plugins/observability_solution/slo/server/routes/slo/route.ts b/x-pack/plugins/observability_solution/slo/server/routes/slo/route.ts index 3d55a9caa3223..1853d09c81f54 100644 --- a/x-pack/plugins/observability_solution/slo/server/routes/slo/route.ts +++ b/x-pack/plugins/observability_solution/slo/server/routes/slo/route.ts @@ -21,6 +21,8 @@ import { getSLOInstancesParamsSchema, getSLOParamsSchema, manageSLOParamsSchema, + putSLOServerlessSettingsParamsSchema, + PutSLOSettingsParams, putSLOSettingsParamsSchema, resetSLOParamsSchema, updateSLOParamsSchema, @@ -645,41 +647,44 @@ const getSloSettingsRoute = createSloServerRoute({ }, }); -const putSloSettings = createSloServerRoute({ - endpoint: 'PUT /internal/slo/settings', - options: { - tags: ['access:slo_write'], - access: 'internal', - }, - params: putSLOSettingsParamsSchema, - handler: async ({ context, params }) => { - await assertPlatinumLicense(context); - - const soClient = (await context.core).savedObjects.client; - return await storeSloSettings(soClient, params.body); - }, -}); - -export const sloRouteRepository = { - ...fetchSloHealthRoute, - ...getSloSettingsRoute, - ...putSloSettings, - ...createSLORoute, - ...inspectSLORoute, - ...deleteSLORoute, - ...deleteSloInstancesRoute, - ...disableSLORoute, - ...enableSLORoute, - ...fetchHistoricalSummary, - ...findSloDefinitionsRoute, - ...findSLORoute, - ...getSLORoute, - ...updateSLORoute, - ...getDiagnosisRoute, - ...getSloBurnRates, - ...getPreviewData, - ...getSLOInstancesRoute, - ...resetSLORoute, - ...findSLOGroupsRoute, - ...getSLOSuggestionsRoute, +const putSloSettings = (isServerless?: boolean) => + createSloServerRoute({ + endpoint: 'PUT /internal/slo/settings', + options: { + tags: ['access:slo_write'], + access: 'internal', + }, + params: isServerless ? putSLOServerlessSettingsParamsSchema : putSLOSettingsParamsSchema, + handler: async ({ context, params }) => { + await assertPlatinumLicense(context); + + const soClient = (await context.core).savedObjects.client; + return await storeSloSettings(soClient, params.body as PutSLOSettingsParams); + }, + }); + +export const getSloRouteRepository = (isServerless?: boolean) => { + return { + ...fetchSloHealthRoute, + ...getSloSettingsRoute, + ...putSloSettings(isServerless), + ...createSLORoute, + ...inspectSLORoute, + ...deleteSLORoute, + ...deleteSloInstancesRoute, + ...disableSLORoute, + ...enableSLORoute, + ...fetchHistoricalSummary, + ...findSloDefinitionsRoute, + ...findSLORoute, + ...getSLORoute, + ...updateSLORoute, + ...getDiagnosisRoute, + ...getSloBurnRates, + ...getPreviewData, + ...getSLOInstancesRoute, + ...resetSLORoute, + ...findSLOGroupsRoute, + ...getSLOSuggestionsRoute, + }; };