Skip to content

Commit

Permalink
[SLOs] Disable federated view settings in serverless (#181880)
Browse files Browse the repository at this point in the history
Fixes #181739

Disable federated view settings in serverless !!

- [ ] Disabled route and settings page in public
- [ ] Uses different put request schema on serverless which doesn't
contains remote cluster settings

(cherry picked from commit 390628d)
  • Loading branch information
shahzad31 committed May 2, 2024
1 parent c8626b2 commit 9f2d37c
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof putSLOSettingsParamsSchema.props.body>;
type PutSLOSettingsResponse = t.OutputOf<typeof putSLOSettingsResponseSchema>;
type GetSLOSettingsResponse = t.OutputOf<typeof sloSettingsSchema>;

export { putSLOSettingsParamsSchema, putSLOSettingsResponseSchema };
export {
putSLOSettingsParamsSchema,
putSLOSettingsResponseSchema,
putSLOServerlessSettingsParamsSchema,
};
export type { PutSLOSettingsParams, PutSLOSettingsResponse, GetSLOSettingsResponse };
2 changes: 2 additions & 0 deletions x-pack/packages/kbn-slo-schema/src/schema/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export const sloSettingsSchema = t.type({
useAllRemoteClusters: t.boolean,
selectedRemoteClusters: t.array(t.string),
});

export const sloServerlessSettingsSchema = t.type({});
11 changes: 8 additions & 3 deletions x-pack/plugins/observability_solution/slo/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<Routes>
{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();
Expand Down Expand Up @@ -124,6 +128,7 @@ export const renderApp = ({
<PluginContext.Provider
value={{
isDev,
isServerless,
appMountParameters,
ObservabilityPageTemplate,
observabilityRuleTypeRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SLOS_BASE_PATH, SLO_SETTINGS_PATH } from '../../../common/locators/path
export function HeaderMenu(): React.ReactElement | null {
const { http, theme } = useKibana().services;

const { appMountParameters } = usePluginContext();
const { appMountParameters, isServerless } = usePluginContext();
return (
<HeaderMenuPortal
setHeaderActionMenu={appMountParameters?.setHeaderActionMenu!}
Expand All @@ -34,15 +34,17 @@ export function HeaderMenu(): React.ReactElement | null {
defaultMessage: 'Add integrations',
})}
</EuiHeaderLink>
<EuiHeaderLink
color="primary"
href={http.basePath.prepend(`${SLOS_BASE_PATH}${SLO_SETTINGS_PATH}`)}
iconType="gear"
>
{i18n.translate('xpack.slo.headerMenu.settings', {
defaultMessage: 'Settings',
})}
</EuiHeaderLink>
{!isServerless && (
<EuiHeaderLink
color="primary"
href={http.basePath.prepend(`${SLOS_BASE_PATH}${SLO_SETTINGS_PATH}`)}
iconType="gear"
>
{i18n.translate('xpack.slo.headerMenu.settings', {
defaultMessage: 'Settings',
})}
</EuiHeaderLink>
)}
</EuiHeaderLinks>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ExperimentalFeatures } from '../../common/config';

export interface PluginContextValue {
isDev?: boolean;
isServerless?: boolean;
appMountParameters?: AppMountParameters;
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
Expand Down
102 changes: 58 additions & 44 deletions x-pack/plugins/observability_solution/slo/public/routes/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SlosPage />;
export const getRoutes = (
isServerless?: boolean
): {
[key: string]: {
handler: () => React.ReactElement;
params: Record<string, string>;
exact: boolean;
};
} => {
return {
[SLOS_PATH]: {
handler: () => {
return <SlosPage />;
},
params: {},
exact: true,
},
params: {},
exact: true,
},
[SLO_CREATE_PATH]: {
handler: () => {
return <SloEditPage />;
[SLO_CREATE_PATH]: {
handler: () => {
return <SloEditPage />;
},
params: {},
exact: true,
},
params: {},
exact: true,
},
[SLOS_WELCOME_PATH]: {
handler: () => {
return <SlosWelcomePage />;
[SLOS_WELCOME_PATH]: {
handler: () => {
return <SlosWelcomePage />;
},
params: {},
exact: true,
},
params: {},
exact: true,
},
[SLOS_OUTDATED_DEFINITIONS_PATH]: {
handler: () => {
return <SlosOutdatedDefinitions />;
[SLOS_OUTDATED_DEFINITIONS_PATH]: {
handler: () => {
return <SlosOutdatedDefinitions />;
},
params: {},
exact: true,
},
params: {},
exact: true,
},
[SLO_EDIT_PATH]: {
handler: () => {
return <SloEditPage />;
[SLO_EDIT_PATH]: {
handler: () => {
return <SloEditPage />;
},
params: {},
exact: true,
},
params: {},
exact: true,
},
[SLO_SETTINGS_PATH]: {
handler: () => {
return <SloSettingsPage />;
...(!isServerless
? {
[SLO_SETTINGS_PATH]: {
handler: () => {
return <SloSettingsPage />;
},
params: {},
exact: true,
},
}
: {}),
[SLO_DETAIL_PATH]: {
handler: () => {
return <SloDetailsPage />;
},
params: {},
exact: true,
},
params: {},
exact: true,
},
[SLO_DETAIL_PATH]: {
handler: () => {
return <SloDetailsPage />;
},
params: {},
exact: true,
},
};
};
6 changes: 5 additions & 1 deletion x-pack/plugins/observability_solution/slo/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -56,6 +57,7 @@ export interface PluginStart {
alerting: PluginStartContract;
taskManager: TaskManagerStartContract;
spaces?: SpacesPluginStart;
serverless: ServerlessPluginStart;
}

const sloRuleTypes = [SLO_BURN_RATE_RULE_TYPE_ID];
Expand Down Expand Up @@ -150,7 +152,9 @@ export class SloPlugin implements Plugin<SloPluginSetup> {
getRulesClientWithRequest: pluginStart.alerting.getRulesClientWithRequest,
},
logger: this.logger,
repository: getSloServerRouteRepository(config),
repository: getSloServerRouteRepository({
isServerless: !!pluginStart.serverless,
}),
});

const esInternalClient = coreStart.elasticsearch.client.asInternalUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof getSloServerRouteRepository>;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
getSLOInstancesParamsSchema,
getSLOParamsSchema,
manageSLOParamsSchema,
putSLOServerlessSettingsParamsSchema,
PutSLOSettingsParams,
putSLOSettingsParamsSchema,
resetSLOParamsSchema,
updateSLOParamsSchema,
Expand Down Expand Up @@ -607,39 +609,42 @@ 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 = {
...getSloSettingsRoute,
...putSloSettings,
...createSLORoute,
...inspectSLORoute,
...deleteSLORoute,
...deleteSloInstancesRoute,
...disableSLORoute,
...enableSLORoute,
...fetchHistoricalSummary,
...findSloDefinitionsRoute,
...findSLORoute,
...getSLORoute,
...updateSLORoute,
...getDiagnosisRoute,
...getSloBurnRates,
...getPreviewData,
...getSLOInstancesRoute,
...resetSLORoute,
...findSLOGroupsRoute,
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 {
...getSloSettingsRoute,
...putSloSettings(isServerless),
...createSLORoute,
...inspectSLORoute,
...deleteSLORoute,
...deleteSloInstancesRoute,
...disableSLORoute,
...enableSLORoute,
...fetchHistoricalSummary,
...findSloDefinitionsRoute,
...findSLORoute,
...getSLORoute,
...updateSLORoute,
...getDiagnosisRoute,
...getSloBurnRates,
...getPreviewData,
...getSLOInstancesRoute,
...resetSLORoute,
...findSLOGroupsRoute,
};
};

0 comments on commit 9f2d37c

Please sign in to comment.