[alerting] replace internal legacy API calls with new APIs (#121048)

resolves https://github.com/elastic/kibana/issues/116939

Removes the remaining calls to the legacy HTTP alerting endpoints by internal Kibana code.
This commit is contained in:
Patrick Mueller 2021-12-16 15:56:02 -05:00 committed by GitHub
parent 825e35dcba
commit b4c44a135e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 698 additions and 115 deletions

View file

@ -23,26 +23,27 @@ import { CoreStart } from 'kibana/public';
import { isEmpty } from 'lodash';
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';
import {
Alert,
RuleTaskState,
LEGACY_BASE_ALERT_API_PATH,
BASE_ALERTING_API_PATH,
INTERNAL_BASE_ALERTING_API_PATH,
} from '../../../../plugins/alerting/common';
import { Rule, RuleTaskState } from '../../common/types';
type Props = RouteComponentProps & {
http: CoreStart['http'];
id: string;
};
export const ViewAlertPage = withRouter(({ http, id }: Props) => {
const [alert, setAlert] = useState<Alert | null>(null);
const [alert, setAlert] = useState<Rule | null>(null);
const [alertState, setAlertState] = useState<RuleTaskState | null>(null);
useEffect(() => {
if (!alert) {
http.get<Alert | null>(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
http.get<Rule | null>(`${BASE_ALERTING_API_PATH}/rule/${id}`).then(setAlert);
}
if (!alertState) {
http
.get<RuleTaskState | null>(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`)
.get<RuleTaskState | null>(`${INTERNAL_BASE_ALERTING_API_PATH}/rule/${id}/state`)
.then(setAlertState);
}
}, [alert, alertState, http, id]);
@ -60,7 +61,7 @@ export const ViewAlertPage = withRouter(({ http, id }: Props) => {
Rule, whose ID is <EuiTextColor color="accent">{`${alert.id}`}</EuiTextColor>.
</p>
<p>
Its RuleType is <EuiTextColor color="accent">{`${alert.alertTypeId}`}</EuiTextColor> and
Its RuleType is <EuiTextColor color="accent">{`${alert.rule_type_id}`}</EuiTextColor> and
its scheduled to run at an interval of
<EuiTextColor color="accent"> {`${alert.schedule.interval}`}</EuiTextColor>.
</p>
@ -69,7 +70,7 @@ export const ViewAlertPage = withRouter(({ http, id }: Props) => {
<EuiText>
<h2>Alerts</h2>
</EuiText>
{isEmpty(alertState.alertInstances) ? (
{isEmpty(alertState.alerts) ? (
<EuiCallOut title="No Alerts!" color="warning" iconType="help">
<p>This Rule doesn&apos;t have any active alerts at the moment.</p>
</EuiCallOut>
@ -84,7 +85,7 @@ export const ViewAlertPage = withRouter(({ http, id }: Props) => {
</EuiCallOut>
<EuiSpacer size="l" />
<EuiDescriptionList compressed>
{Object.entries(alertState.alertInstances ?? {}).map(([instance, { state }]) => (
{Object.entries(alertState.alerts ?? {}).map(([instance, { state }]) => (
<Fragment>
<EuiDescriptionListTitle>{instance}</EuiDescriptionListTitle>
<EuiDescriptionListDescription>