Skip to content

Commit

Permalink
chore(slo): Migrate to server-route-repository (#198726)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Nov 12, 2024
1 parent da85efe commit efcc2ab
Show file tree
Hide file tree
Showing 162 changed files with 1,312 additions and 1,356 deletions.
4 changes: 2 additions & 2 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36267,7 +36267,7 @@ paths:
- $ref: '#/components/parameters/SLOs_space_id'
- $ref: '#/components/parameters/SLOs_slo_id'
responses:
'204':
'200':
content:
application/json; Elastic-Api-Version=2023-10-31:
schema:
Expand Down Expand Up @@ -36311,7 +36311,7 @@ paths:
- $ref: '#/components/parameters/SLOs_space_id'
- $ref: '#/components/parameters/SLOs_slo_id'
responses:
'200':
'204':
description: Successful request
'400':
content:
Expand Down
4 changes: 2 additions & 2 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40728,7 +40728,7 @@ paths:
- $ref: '#/components/parameters/SLOs_space_id'
- $ref: '#/components/parameters/SLOs_slo_id'
responses:
'204':
'200':
content:
application/json; Elastic-Api-Version=2023-10-31:
schema:
Expand Down Expand Up @@ -40772,7 +40772,7 @@ paths:
- $ref: '#/components/parameters/SLOs_space_id'
- $ref: '#/components/parameters/SLOs_slo_id'
responses:
'200':
'204':
description: Successful request
'400':
content:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import { errors } from '@elastic/elasticsearch';
import Boom from '@hapi/boom';
import { RulesClientApi } from '@kbn/alerting-plugin/server/types';
import { CoreSetup, KibanaRequest, Logger, RouteRegistrar } from '@kbn/core/server';
import { DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import { RuleDataPluginService } from '@kbn/rule-registry-plugin/server';
import {
IoTsParamsObject,
decodeRequestParams,
stripNullishRequestParameters,
parseEndpoint,
passThroughValidationObject,
stripNullishRequestParameters,
} from '@kbn/server-route-repository';
import { SpacesPluginStart } from '@kbn/spaces-plugin/server';
import axios from 'axios';
import * as t from 'io-ts';
import { DataViewsServerPluginStart } from '@kbn/data-views-plugin/server';
import { ObservabilityConfig } from '..';
import { getHTTPResponseCode, ObservabilityError } from '../errors';
import { AlertDetailsContextualInsightsService } from '../services';
import { ObservabilityRequestHandlerContext } from '../types';
import { AbstractObservabilityServerRouteRepository } from './types';
Expand Down Expand Up @@ -88,16 +87,6 @@ export function registerRoutes({ config, repository, core, logger, dependencies

return response.ok({ body: data });
} catch (error) {
if (error instanceof ObservabilityError) {
logger.error(error.message);
return response.customError({
statusCode: getHTTPResponseCode(error),
body: {
message: error.message,
},
});
}

if (axios.isAxiosError(error)) {
logger.error(error);
return response.customError({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/publi
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { SloPublicStart } from '@kbn/slo-plugin/public';
import { SLOPublicStart } from '@kbn/slo-plugin/public';
import { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/public';
import {
ObservabilityLogsExplorerLocators,
Expand Down Expand Up @@ -53,7 +53,7 @@ export interface ObservabilityLogsExplorerStartDeps {
logsDataAccess: LogsDataAccessPluginStart;
observabilityAIAssistant?: ObservabilityAIAssistantPublicStart;
observabilityShared: ObservabilitySharedPluginStart;
slo: SloPublicStart;
slo: SLOPublicStart;
serverless?: ServerlessPluginStart;
triggersActionsUi?: TriggersAndActionsUIPublicPluginStart;
unifiedSearch?: UnifiedSearchPublicPluginStart;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/observability_solution/slo/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const config = {
experimental: true,
},
};
export type SloConfig = TypeOf<typeof configSchema>;
export type ExperimentalFeatures = SloConfig['experimental'];
export type SLOConfig = TypeOf<typeof configSchema>;
export type ExperimentalFeatures = SLOConfig['experimental'];
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@
}
],
"responses": {
"200": {
"204": {
"description": "Successful request"
},
"400": {
Expand Down Expand Up @@ -625,7 +625,7 @@
}
],
"responses": {
"204": {
"200": {
"description": "Successful request",
"content": {
"application/json": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ paths:
- $ref: '#/components/parameters/space_id'
- $ref: '#/components/parameters/slo_id'
responses:
'200':
'204':
description: Successful request
'400':
description: Bad request
Expand Down Expand Up @@ -380,7 +380,7 @@ paths:
- $ref: '#/components/parameters/space_id'
- $ref: '#/components/parameters/slo_id'
responses:
'204':
'200':
description: Successful request
content:
application/json:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ post:
- $ref: ../components/parameters/space_id.yaml
- $ref: ../components/parameters/slo_id.yaml
responses:
'204':
'200':
description: Successful request
content:
application/json:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ post:
- $ref: ../components/parameters/space_id.yaml
- $ref: ../components/parameters/slo_id.yaml
responses:
'200':
'204':
description: Successful request
'400':
description: Bad request
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/observability_solution/slo/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"presentationUtil",
"features",
"licensing",
"usageCollection"
"usageCollection",
],
"optionalPlugins": [
"cloud",
"spaces",
"serverless",
"discover",
"observabilityAIAssistant"
"observabilityAIAssistant",
"spaces",
],
"requiredBundles": [
"controls",
Expand Down
65 changes: 34 additions & 31 deletions x-pack/plugins/observability_solution/slo/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,20 @@ import { ExperimentalFeatures } from '../common/config';
import { PluginContext } from './context/plugin_context';
import { usePluginContext } from './hooks/use_plugin_context';
import { getRoutes } from './routes/routes';
import { SloPublicPluginsStart } from './types';
import { SLORepositoryClient, SLOPublicPluginsStart } from './types';

function App() {
const { isServerless } = usePluginContext();

const routes = getRoutes(isServerless);

return (
<>
<Routes>
{Object.keys(routes).map((path) => {
const { handler, exact } = routes[path];
const Wrapper = () => {
return handler();
};
return <Route key={path} path={path} exact={exact} component={Wrapper} />;
})}
</Routes>
</>
);
interface Props {
core: CoreStart;
plugins: SLOPublicPluginsStart;
appMountParameters: AppMountParameters;
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
usageCollection: UsageCollectionSetup;
isDev?: boolean;
kibanaVersion: string;
isServerless?: boolean;
experimentalFeatures: ExperimentalFeatures;
sloClient: SLORepositoryClient;
}

export const renderApp = ({
Expand All @@ -58,18 +52,8 @@ export const renderApp = ({
isServerless,
observabilityRuleTypeRegistry,
experimentalFeatures,
}: {
core: CoreStart;
plugins: SloPublicPluginsStart;
appMountParameters: AppMountParameters;
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
usageCollection: UsageCollectionSetup;
isDev?: boolean;
kibanaVersion: string;
isServerless?: boolean;
experimentalFeatures: ExperimentalFeatures;
}) => {
sloClient,
}: Props) => {
const { element, history, theme$ } = appMountParameters;
const isDarkMode = core.theme.getTheme().darkMode;

Expand Down Expand Up @@ -128,6 +112,7 @@ export const renderApp = ({
ObservabilityPageTemplate,
observabilityRuleTypeRegistry,
experimentalFeatures,
sloClient,
}}
>
<Router history={history}>
Expand Down Expand Up @@ -160,3 +145,21 @@ export const renderApp = ({
ReactDOM.unmountComponentAtNode(element);
};
};

function App() {
const { isServerless } = usePluginContext();

const routes = getRoutes(isServerless);

return (
<Routes>
{Object.keys(routes).map((path) => {
const { handler, exact } = routes[path];
const Wrapper = () => {
return handler();
};
return <Route key={path} path={path} exact={exact} component={Wrapper} />;
})}
</Routes>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import React, { useRef } from 'react';
import { useAnnotations } from '@kbn/observability-plugin/public';
import { TimeBounds } from '../../pages/slo_details/types';
import { getBrushTimeBounds } from '../../utils/slo/duration';
import { useKibana } from '../../utils/kibana_react';
import { useKibana } from '../../hooks/use_kibana';
import { openInDiscover } from '../../utils/slo/get_discover_link';

export interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFlexGroup, EuiFlexItem, EuiHeaderLink, EuiHeaderLinks } from '@elastic/eui';
import { HeaderMenuPortal } from '@kbn/observability-shared-plugin/public';
import { useKibana } from '../../utils/kibana_react';
import { useKibana } from '../../hooks/use_kibana';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { SLOS_BASE_PATH, SLO_SETTINGS_PATH } from '../../../common/locators/paths';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useEffect } from 'react';
import { EuiFlexGroup, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { AlertDetailsAppSectionProps } from '@kbn/observability-plugin/public';
import { useKibana } from '../../../../utils/kibana_react';
import { useKibana } from '../../../../hooks/use_kibana';
import { useFetchSloDetails } from '../../../../hooks/use_fetch_slo_details';
import { CustomAlertDetailsPanel } from './components/custom_panels/custom_panels';
import { ErrorRatePanel } from './components/error_rate/error_rate_panel';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { WindowSchema } from '../../../../../../../typings';
import { TimeRange } from '../../../../../error_rate_chart/use_lens_definition';
import { BurnRateAlert, BurnRateRule } from '../../../types';
import { getActionGroupFromReason } from '../../../utils/alert';
import { useKibana } from '../../../../../../../utils/kibana_react';
import { useKibana } from '../../../../../../../hooks/use_kibana';
import { getESQueryForLogRateAnalysis } from './helpers/log_rate_analysis_query';
function getDataTimeRange(
timeRange: { gte: string; lte?: string },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { ALERT_EVALUATION_VALUE, ALERT_TIME_RANGE } from '@kbn/rule-data-utils';
import { GetSLOResponse } from '@kbn/slo-schema';
import React from 'react';
import { useKibana } from '../../../../../../utils/kibana_react';
import { useKibana } from '../../../../../../hooks/use_kibana';
import { ErrorRateChart } from '../../../../error_rate_chart';
import { TimeRange } from '../../../../error_rate_chart/use_lens_definition';
import { BurnRateAlert } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import moment from 'moment';
import React from 'react';
import { SloTabId } from '../../../pages/slo_details/components/slo_details';
import { TimeBounds } from '../../../pages/slo_details/types';
import { useKibana } from '../../../utils/kibana_react';
import { useKibana } from '../../../hooks/use_kibana';
import { getDelayInSecondsFromSLO } from '../../../utils/slo/get_delay_in_seconds_from_slo';
import { AlertAnnotation, TimeRange, useLensDefinition } from './use_lens_definition';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EuiButton, EuiCallOut, EuiSpacer } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '../../../utils/kibana_react';
import { useKibana } from '../../../hooks/use_kibana';
import { useFetchSloDefinitions } from '../../../hooks/use_fetch_slo_definitions';
import { paths } from '../../../../common/locators/paths';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
import React, { MouseEvent } from 'react';
import { SLOWithSummaryResponse } from '@kbn/slo-schema';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { useKibana } from '../../../utils/kibana_react';
import { useKibana } from '../../../hooks/use_kibana';

export interface Props {
viewMode?: 'compact' | 'default';
Expand Down
Loading

0 comments on commit efcc2ab

Please sign in to comment.