forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Synthetics] Added alerts page (elastic#190751)
## Summary Synthetics - add alerts page , it shows related alerts for selected monitor and location !! <img width="1717" alt="image" src="https://github.com/user-attachments/assets/590d2110-ad75-4c95-b413-496eff3a2544"> --------- Co-authored-by: shahzad31 <shahzad31comp@gmail.com>
- Loading branch information
1 parent
9ff78cf
commit 398daa1
Showing
11 changed files
with
221 additions
and
42 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
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
63 changes: 63 additions & 0 deletions
63
...hetics/public/apps/synthetics/components/monitor_details/hooks/use_fetch_active_alerts.ts
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,63 @@ | ||
/* | ||
* 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 { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common'; | ||
import { AlertConsumers } from '@kbn/rule-registry-plugin/common/technical_rule_data_field_names'; | ||
import { useFetcher } from '@kbn/observability-shared-plugin/public'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { useParams } from 'react-router-dom'; | ||
import type { ESSearchResponse } from '@kbn/es-types'; | ||
import { useSelectedLocation } from './use_selected_location'; | ||
|
||
import { ClientPluginsStart } from '../../../../../plugin'; | ||
|
||
export function useFetchActiveAlerts() { | ||
const { http } = useKibana<ClientPluginsStart>().services; | ||
|
||
const { monitorId: configId } = useParams<{ monitorId: string }>(); | ||
|
||
const selectedLocation = useSelectedLocation(); | ||
|
||
const { loading, data } = useFetcher(async () => { | ||
return await http.post<ESSearchResponse>(`${BASE_RAC_ALERTS_API_PATH}/find`, { | ||
body: JSON.stringify({ | ||
feature_ids: [AlertConsumers.UPTIME], | ||
size: 0, | ||
track_total_hits: true, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
range: { | ||
'@timestamp': { | ||
gte: 'now-24h/h', | ||
}, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
configId, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'location.id': selectedLocation?.id, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
}); | ||
}, [configId, http, selectedLocation?.id]); | ||
|
||
return { | ||
loading, | ||
data, | ||
numberOfAlerts: data?.hits?.total.value ?? 0, | ||
}; | ||
} |
15 changes: 15 additions & 0 deletions
15
...nthetics/public/apps/synthetics/components/monitor_details/monitor_alerts/alerts_icon.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 { EuiBadge } from '@elastic/eui'; | ||
import { useFetchActiveAlerts } from '../hooks/use_fetch_active_alerts'; | ||
|
||
export const MonitorAlertsIcon = () => { | ||
const { numberOfAlerts } = useFetchActiveAlerts(); | ||
|
||
return numberOfAlerts > 0 ? <EuiBadge color="danger">{numberOfAlerts}</EuiBadge> : null; | ||
}; |
65 changes: 65 additions & 0 deletions
65
...ublic/apps/synthetics/components/monitor_details/monitor_alerts/monitor_detail_alerts.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,65 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiLoadingSpinner } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { AlertConsumers } from '@kbn/rule-data-utils'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useRefreshedRangeFromUrl } from '../../../hooks'; | ||
import { SyntheticsDatePicker } from '../../common/date_picker/synthetics_date_picker'; | ||
import { useSelectedLocation } from '../hooks/use_selected_location'; | ||
import { ClientPluginsStart } from '../../../../../plugin'; | ||
|
||
export const MONITOR_ALERTS_TABLE_ID = 'xpack.observability.slo.sloDetails.alertTable'; | ||
|
||
export function MonitorDetailsAlerts() { | ||
const { | ||
triggersActionsUi: { alertsTableConfigurationRegistry, getAlertsStateTable: AlertsStateTable }, | ||
observability: { observabilityRuleTypeRegistry }, | ||
} = useKibana<ClientPluginsStart>().services; | ||
|
||
const { monitorId: configId } = useParams<{ monitorId: string }>(); | ||
|
||
const selectedLocation = useSelectedLocation(); | ||
const { from, to } = useRefreshedRangeFromUrl(); | ||
|
||
if (!selectedLocation) { | ||
return <EuiLoadingSpinner size="xl" />; | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<EuiFlexGroup direction="column" gutterSize="xl"> | ||
<EuiFlexItem> | ||
<SyntheticsDatePicker fullWidth={true} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<AlertsStateTable | ||
alertsTableConfigurationRegistry={alertsTableConfigurationRegistry} | ||
configurationId={AlertConsumers.OBSERVABILITY} | ||
id={MONITOR_ALERTS_TABLE_ID} | ||
data-test-subj="monitorAlertsTable" | ||
featureIds={[AlertConsumers.UPTIME]} | ||
query={{ | ||
bool: { | ||
filter: [ | ||
{ term: { configId } }, | ||
{ term: { 'location.id': selectedLocation?.id } }, | ||
{ range: { '@timestamp': { gte: from, lte: to } } }, | ||
], | ||
}, | ||
}} | ||
showAlertStatusWithFlapping | ||
initialPageSize={100} | ||
cellContext={{ observabilityRuleTypeRegistry }} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.