Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(slo): Migrate to server-route-repository #198726

Merged
merged 56 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
090c53d
wip: migration attempt to http core router
kdelemme Nov 1, 2024
d0a9883
Update Plugin types
kdelemme Nov 1, 2024
88fd533
Use correct plugins from dependencies
kdelemme Nov 1, 2024
861d205
Fix usage of licensing
kdelemme Nov 1, 2024
e05e672
Replace usage of custom licensing and spaces start function
kdelemme Nov 1, 2024
7ea5f27
Remove usage of custom start function
kdelemme Nov 1, 2024
6e3bbb2
Remove rac and rules specific start function
kdelemme Nov 1, 2024
2540e6f
Remove usage of leftover plugins
kdelemme Nov 1, 2024
f580480
Fix plugins and corePlugins usage
kdelemme Nov 1, 2024
377fc19
Add SLORepositoryClient to public plugin and context
kdelemme Nov 4, 2024
44273f6
Use client from use fetch slo list hook
kdelemme Nov 4, 2024
6e96060
Use client from use fetch slo definitions hook
kdelemme Nov 4, 2024
232486d
Use client from use create slo hook
kdelemme Nov 4, 2024
1b93e2b
Use client from use delete instance hook
kdelemme Nov 4, 2024
073560c
Use client from use delete slo hook
kdelemme Nov 4, 2024
708e1c2
Use client from use fetch global diagnosis hook
kdelemme Nov 4, 2024
7caf413
Use client from use fetch historical summary hook
kdelemme Nov 4, 2024
db15edf
Use client from use fetch slo burn rates hook
kdelemme Nov 4, 2024
8a94f42
Use client from use fetch slo details hook
kdelemme Nov 4, 2024
a204ad0
Use client from use fetch slo groups hook
kdelemme Nov 4, 2024
7bea57b
Use client from use fetch slo health
kdelemme Nov 4, 2024
b2f09e6
Use client from use fetch slo inspect hook
kdelemme Nov 4, 2024
6cd5ceb
Use client from use fetch preview data hook
kdelemme Nov 4, 2024
f5fe891
Use client from use reset slo hook
kdelemme Nov 4, 2024
f3d5672
Use client from use update slo hook
kdelemme Nov 4, 2024
46db725
Remove import
kdelemme Nov 4, 2024
7694fe2
Fix usage of query params
kdelemme Nov 4, 2024
3b7a5b8
Use client from use suggestion hook
kdelemme Nov 4, 2024
8a3d28f
update local hooks from slo pages
kdelemme Nov 4, 2024
7e25fd8
wip: refactor SLO public Plugin
kdelemme Nov 4, 2024
885ee36
wip: refactor SLO public plugin
kdelemme Nov 4, 2024
d81a3f2
wip: Refactor slo embeddable overview
kdelemme Nov 4, 2024
478bae0
Fix alerts embeddable deps
kdelemme Nov 4, 2024
02e5e1c
Fix error budget embeddable deps
kdelemme Nov 4, 2024
69b2183
fix burn rate embeddable
kdelemme Nov 4, 2024
bb3e780
Fix ui actions registering
kdelemme Nov 4, 2024
2de2399
fix flyout
kdelemme Nov 4, 2024
4f70c8a
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 4, 2024
cc67e0f
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 4, 2024
4cdca40
fix mock import
kdelemme Nov 5, 2024
65d06fc
Fix open configuration
kdelemme Nov 5, 2024
4e3270c
Move useKibana hooks into hooks folder
kdelemme Nov 5, 2024
688c62a
rename kibana_react to use_kibana
kdelemme Nov 5, 2024
1d6dbfd
Remove unused constant
kdelemme Nov 5, 2024
803c813
Add spaces to optional plugin
kdelemme Nov 5, 2024
ec0d9b6
Fix lazy loading of alerts section with missing context providers
kdelemme Nov 5, 2024
b8d0087
Merge branch 'main' into chore/migrate-to-core-http-router
kdelemme Nov 5, 2024
a4ffd0b
Fix tests mock
kdelemme Nov 5, 2024
acf22fd
Fix type
kdelemme Nov 5, 2024
9945ab4
Fix duplication of context providers
kdelemme Nov 5, 2024
f81ed59
Fix documentation response code
kdelemme Nov 6, 2024
ef1715c
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 6, 2024
ab5510c
Fix test
kdelemme Nov 6, 2024
5a421e5
Handle SLO domain errors on the routes
kdelemme Nov 7, 2024
fca3bbb
Merge branch 'main' into chore/migrate-to-core-http-router
shahzad31 Nov 12, 2024
11b8a0f
Merge branch 'main' into chore/migrate-to-core-http-router
kdelemme Nov 12, 2024
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 @@ -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'];
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
* 2.0.
*/
export const SLO_LONG_REFETCH_INTERVAL = 60 * 1000; // 1 minute
export const SLO_SHORT_REFETCH_INTERVAL = 5 * 1000; // 5 seconds
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { AppMountParameters } from '@kbn/core/public';
import type { LazyObservabilityPageTemplateProps } from '@kbn/observability-shared-plugin/public';
import type { ObservabilityRuleTypeRegistry } from '@kbn/observability-plugin/public';
import { ExperimentalFeatures } from '../../common/config';
import type { SLORepositoryClient } from '../types';

export interface PluginContextValue {
isDev?: boolean;
Expand All @@ -18,6 +19,7 @@ export interface PluginContextValue {
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
experimentalFeatures?: ExperimentalFeatures;
sloClient: SLORepositoryClient;
}

export const PluginContext = createContext<PluginContextValue | null>(null);
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import React, { useEffect } from 'react';
import { Router } from '@kbn/shared-ux-router';
import { BehaviorSubject, Subject } from 'rxjs';
import type { CoreStart } from '@kbn/core-lifecycle-browser';
import { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import {
FetchContext,
fetch$,
initializeTitles,
useBatchedPublishingSubjects,
fetch$,
FetchContext,
useFetchContext,
} from '@kbn/presentation-publishing';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { Router } from '@kbn/shared-ux-router';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { createBrowserHistory } from 'history';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import type { StartServicesAccessor } from '@kbn/core-lifecycle-browser';
import React, { useEffect } from 'react';
import { BehaviorSubject, Subject } from 'rxjs';
import { PluginContext } from '../../../context/plugin_context';
import { SLOPublicPluginsStart, SLORepositoryClient } from '../../../types';
import { SLO_ALERTS_EMBEDDABLE_ID } from './constants';
import { SloAlertsEmbeddableState, SloAlertsApi } from './types';
import { SloPublicPluginsStart, SloPublicStart } from '../../../types';
import { SloAlertsWrapper } from './slo_alerts_wrapper';
import { SloAlertsApi, SloAlertsEmbeddableState } from './types';
const history = createBrowserHistory();
const queryClient = new QueryClient();

Expand All @@ -34,10 +35,17 @@ export const getAlertsPanelTitle = () =>
defaultMessage: 'SLO Alerts',
});

export function getAlertsEmbeddableFactory(
getStartServices: StartServicesAccessor<SloPublicPluginsStart, SloPublicStart>,
kibanaVersion: string
) {
export function getAlertsEmbeddableFactory({
coreStart,
pluginsStart,
sloClient,
kibanaVersion,
}: {
coreStart: CoreStart;
pluginsStart: SLOPublicPluginsStart;
sloClient: SLORepositoryClient;
kibanaVersion: string;
}) {
const factory: ReactEmbeddableFactory<
SloAlertsEmbeddableState,
SloAlertsEmbeddableState,
Expand All @@ -48,15 +56,15 @@ export function getAlertsEmbeddableFactory(
return state.rawState as SloAlertsEmbeddableState;
},
buildEmbeddable: async (state, buildApi, uuid, parentApi) => {
const [coreStart, pluginStart] = await getStartServices();
const deps = { ...coreStart, ...pluginStart };
const deps = { ...coreStart, ...pluginsStart };
async function onEdit() {
try {
const { openSloConfiguration } = await import('./slo_alerts_open_configuration');

const result = await openSloConfiguration(
coreStart,
pluginStart,
pluginsStart,
sloClient,
api.getSloAlertsConfig()
);
api.updateSloAlertsConfig(result);
Expand Down Expand Up @@ -143,18 +151,28 @@ export function getAlertsEmbeddableFactory(
kibanaVersion,
}}
>
<Router history={history}>
<QueryClientProvider client={queryClient}>
<SloAlertsWrapper
onEdit={onEdit}
deps={deps}
slos={slos}
timeRange={fetchContext.timeRange ?? { from: 'now-15m/m', to: 'now' }}
reloadSubject={reload$}
showAllGroupByInstances={showAllGroupByInstances}
/>
</QueryClientProvider>
</Router>
<PluginContext.Provider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the embeddables registration would need to be refactored to use a common context providers instead of creating from scratch for the 5 different embeddable we have. Very error prone.

Copy link
Contributor

@mgiota mgiota Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking with this comment here. There is indeed an SloEmbeddableContext which I introduced as part of refactoring the alerts embeddable. I will create an issue for this

value={{
observabilityRuleTypeRegistry:
pluginsStart.observability.observabilityRuleTypeRegistry,
ObservabilityPageTemplate:
pluginsStart.observabilityShared.navigation.PageTemplate,
sloClient,
}}
>
<Router history={history}>
<QueryClientProvider client={queryClient}>
<SloAlertsWrapper
onEdit={onEdit}
deps={deps}
slos={slos}
timeRange={fetchContext.timeRange ?? { from: 'now-15m/m', to: 'now' }}
reloadSubject={reload$}
showAllGroupByInstances={showAllGroupByInstances}
/>
</QueryClientProvider>
</Router>
</PluginContext.Provider>
</KibanaContextProvider>
</I18nContext>
);
Expand Down
Loading