-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Stack Monitoring] Adding alerts to react app (#114029)
* [Stack Monitoring] Adding alerts to react app * Fixing global state context path * adding alerts to pages; adding alerts model to cluster_overview; removing loadAlerts from page template * Fixing request for enable alerts * remove loadAlerts from page template * Adding request error handlers * removing redundent error handling * Changing useRequestErrorHandler function to be async due to error.response.json call * removing old comment * Fixing contexts paths * Converting ajaxRequestErrorHandler to useRequestErrorHandler * Refactoring error handler for page template and setup mode * Removing unnecessary async/await * Removing unnecessary async/await in useClusters * adding alertTypeIds to each page * fixing instance count * Adding alertTypeIds to index page * Adding alert filters for specific pages * Adding alerts to Logstash nodes Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
b03237a
commit c8a0108
Showing
47 changed files
with
990 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/monitoring/public/application/contexts/header_action_menu_context.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { AppMountParameters } from 'kibana/public'; | ||
|
||
interface ContextProps { | ||
setHeaderActionMenu?: AppMountParameters['setHeaderActionMenu']; | ||
} | ||
|
||
export const HeaderActionMenuContext = React.createContext<ContextProps>({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/monitoring/public/application/hooks/use_request_error_handler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React, { useCallback } from 'react'; | ||
import { includes } from 'lodash'; | ||
import { IHttpFetchError } from 'kibana/public'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { EuiButton, EuiSpacer, EuiText } from '@elastic/eui'; | ||
import { formatMsg } from '../../../../../../src/plugins/kibana_legacy/public'; | ||
import { toMountPoint, useKibana } from '../../../../../../src/plugins/kibana_react/public'; | ||
import { MonitoringStartPluginDependencies } from '../../types'; | ||
|
||
export function formatMonitoringError(err: IHttpFetchError) { | ||
if (err.response?.status && err.response?.status !== -1) { | ||
return ( | ||
<EuiText> | ||
<p>{err.body?.message}</p> | ||
<EuiText size="xs"> | ||
<FormattedMessage | ||
id="xpack.monitoring.ajaxErrorHandler.httpErrorMessage" | ||
defaultMessage="HTTP {errStatus}" | ||
values={{ errStatus: err.response?.status }} | ||
/> | ||
</EuiText> | ||
</EuiText> | ||
); | ||
} | ||
|
||
return formatMsg(err); | ||
} | ||
|
||
export const useRequestErrorHandler = () => { | ||
const { services } = useKibana<MonitoringStartPluginDependencies>(); | ||
return useCallback( | ||
(err: IHttpFetchError) => { | ||
if (err.response?.status === 403) { | ||
// redirect to error message view | ||
history.replaceState(null, '', '#/access-denied'); | ||
} else if (err.response?.status === 404 && !includes(window.location.hash, 'no-data')) { | ||
// pass through if this is a 404 and we're already on the no-data page | ||
const formattedError = formatMonitoringError(err); | ||
services.notifications?.toasts.addDanger({ | ||
title: toMountPoint( | ||
<FormattedMessage | ||
id="xpack.monitoring.ajaxErrorHandler.requestFailedNotificationTitle" | ||
defaultMessage="Monitoring Request Failed" | ||
/> | ||
), | ||
text: toMountPoint( | ||
<div> | ||
{formattedError} | ||
<EuiSpacer /> | ||
<EuiButton size="s" color="danger" onClick={() => window.location.reload()}> | ||
<FormattedMessage | ||
id="xpack.monitoring.ajaxErrorHandler.requestFailedNotification.retryButtonLabel" | ||
defaultMessage="Retry" | ||
/> | ||
</EuiButton> | ||
</div> | ||
), | ||
}); | ||
} else { | ||
services.notifications?.toasts.addDanger({ | ||
title: toMountPoint( | ||
<FormattedMessage | ||
id="xpack.monitoring.ajaxErrorHandler.requestErrorNotificationTitle" | ||
defaultMessage="Monitoring Request Error" | ||
/> | ||
), | ||
text: toMountPoint(formatMonitoringError(err)), | ||
}); | ||
} | ||
}, | ||
[services.notifications] | ||
); | ||
}; |
Oops, something went wrong.