mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
This PR has two steps that together create a functional dry-run capability for the migration.
By enabling the feature flag alertingPreviewUpgrade when on legacy alerting it will:
a. Allow all Grafana Alerting background services except for the scheduler to start (multiorg alertmanager, state manager, routes, …).
b. Allow the UI to show Grafana Alerting pages alongside legacy ones (with appropriate in-app warnings that UA is not actually running).
c. Show a new “Alerting Upgrade” page and register associated /api/v1/upgrade endpoints that will allow the user to upgrade their organization live without restart and present a summary of the upgrade in a table.
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import React, { PropsWithChildren } from 'react';
|
|
import { useLocation } from 'react-use';
|
|
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
import { PageProps } from 'app/core/components/Page/types';
|
|
|
|
import { UAPreviewNotice } from '../../components/UAPreviewNotice';
|
|
import { AlertmanagerProvider, useAlertmanager } from '../state/AlertmanagerContext';
|
|
|
|
import { AlertManagerPicker } from './AlertManagerPicker';
|
|
import { NoAlertManagerWarning } from './NoAlertManagerWarning';
|
|
|
|
/**
|
|
* This is the main alerting page wrapper, used by the alertmanager page wrapper and the alert rules list view
|
|
*/
|
|
interface AlertingPageWrapperProps extends PageProps {
|
|
isLoading?: boolean;
|
|
}
|
|
|
|
export const AlertingPageWrapper = ({ children, isLoading, ...rest }: AlertingPageWrapperProps) => (
|
|
<Page {...rest}>
|
|
<Page.Contents isLoading={isLoading}>
|
|
<div>
|
|
<UAPreviewNotice />
|
|
{children}
|
|
</div>
|
|
</Page.Contents>
|
|
</Page>
|
|
);
|
|
|
|
/**
|
|
* This wrapper is for pages that use the Alertmanager API
|
|
*/
|
|
interface AlertmanagerPageWrapperProps extends AlertingPageWrapperProps {
|
|
accessType: 'instance' | 'notification';
|
|
}
|
|
export const AlertmanagerPageWrapper = ({ children, accessType, ...props }: AlertmanagerPageWrapperProps) => {
|
|
const disableAlertmanager = useIsDisabledAlertmanagerSelection();
|
|
|
|
return (
|
|
<AlertmanagerProvider accessType={accessType}>
|
|
<AlertingPageWrapper {...props} actions={<AlertManagerPicker disabled={disableAlertmanager} />}>
|
|
<AlertManagerPagePermissionsCheck>{children}</AlertManagerPagePermissionsCheck>
|
|
</AlertingPageWrapper>
|
|
</AlertmanagerProvider>
|
|
);
|
|
};
|
|
|
|
/**
|
|
* This function tells us when we want to disable the alertmanager picker
|
|
* It's not great...
|
|
*/
|
|
function useIsDisabledAlertmanagerSelection() {
|
|
const location = useLocation();
|
|
const disabledPathSegment = ['/edit', '/new'];
|
|
|
|
return disabledPathSegment.some((match) => location?.pathname?.includes(match));
|
|
}
|
|
|
|
/**
|
|
* This component will render an error message if the user doesn't have sufficient permissions or if the requested
|
|
* alertmanager doesn't exist
|
|
*/
|
|
const AlertManagerPagePermissionsCheck = ({ children }: PropsWithChildren) => {
|
|
const { availableAlertManagers, selectedAlertmanager } = useAlertmanager();
|
|
|
|
if (!selectedAlertmanager) {
|
|
return <NoAlertManagerWarning availableAlertManagers={availableAlertManagers} />;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|