From c76b490c577a3e66cea0283481371d7e9fc3588f Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:09:52 +0200 Subject: [PATCH] Alerting: Central alert history part4 (#90088) * Implement EventDetails for expanded rows and pagination on the events list * Add test for getPanelDataForRule function * prettier * refactor EventState component * create interfaces for props * Add missing translations * Update some comments * Add plus button in alertrulename , to add it into the filter * Add plus button to add filters from the list labels and alert name * Add clear labels filter button * run prettier * fix RBAC checks * Update AlertLabels onLabelClick functionality * add limit=0 in useCombinedRule call * Add filter by state * remove plus button in labels * Fix state filter * Add filter by previous state * fix some errors after solving conflicts * Add comments and remove some type assertions * Update the number of transitions calculation to be for each instance * Add tests for state filters * remove type assertion * Address review comments * Update returnTo prop in alert list view url * Update translations * address review comments * prettier * update cursor to pointer * Address Deyan review comments * address review pr comments from Deyan * fix label styles * Visualize expanded row as a state graph and address some pr review comments * Add warning when limit of events is reached and rename onClickLabel * Update texts * Fix translations * Update some Labels in the expanded states visualization * move getPanelDataForRule to a separate file * Add header to the list of events * Move HistoryErrorMessage to a separate file * remove getPanelDataForRule function and test * add comment * fitler by instance label results shown inthe state chart * remove defaults.ini changes * fix having single event on time state chart --------- Co-authored-by: Gilles De Mey --- pkg/services/navtree/navtreeimpl/navtree.go | 16 +- public/app/features/alerting/routes.tsx | 5 +- .../unified/components/AlertLabels.tsx | 37 ++- .../alerting/unified/components/Label.tsx | 43 ++- .../CentralAlertHistoryScene.tsx | 136 ++++++++- .../central-state-history/EventDetails.tsx | 265 +++++++++++------- .../EventListSceneObject.tsx | 257 +++++++++++++---- .../HistoryErrorMessage.tsx | 20 ++ .../HistoryEventsList.test.tsx | 127 ++++++++- .../getPanelDataForRule.test.ts | 53 ---- .../rules/central-state-history/utils.ts | 130 ++++++++- .../rules/state-history/LogTimelineViewer.tsx | 4 +- .../rules/state-history/LokiStateHistory.tsx | 4 +- .../useRuleHistoryRecords.test.tsx | 2 +- .../state-history/useRuleHistoryRecords.tsx | 4 +- .../alerting/unified/mocks/alertRuleApi.ts | 12 +- public/locales/en-US/grafana.json | 17 +- public/locales/pseudo-LOCALE/grafana.json | 17 +- 18 files changed, 860 insertions(+), 289 deletions(-) create mode 100644 public/app/features/alerting/unified/components/rules/central-state-history/HistoryErrorMessage.tsx delete mode 100644 public/app/features/alerting/unified/components/rules/central-state-history/getPanelDataForRule.test.ts diff --git a/pkg/services/navtree/navtreeimpl/navtree.go b/pkg/services/navtree/navtreeimpl/navtree.go index e53356c0997..69bd5de2aec 100644 --- a/pkg/services/navtree/navtreeimpl/navtree.go +++ b/pkg/services/navtree/navtreeimpl/navtree.go @@ -409,13 +409,15 @@ func (s *ServiceImpl) buildAlertNavLinks(c *contextmodel.ReqContext) *navtree.Na } if s.features.IsEnabled(c.Req.Context(), featuremgmt.FlagAlertingCentralAlertHistory) { - alertChildNavs = append(alertChildNavs, &navtree.NavLink{ - Text: "History", - SubTitle: "History of events that were generated by your Grafana-managed alert rules. Silences and Mute timings are ignored.", - Id: "alerts-history", - Url: s.cfg.AppSubURL + "/alerting/history", - Icon: "history", - }) + if hasAccess(ac.EvalAny(ac.EvalPermission(ac.ActionAlertingRuleRead))) { + alertChildNavs = append(alertChildNavs, &navtree.NavLink{ + Text: "History", + SubTitle: "View a history of all alert events generated by your Grafana-managed alert rules. All alert events are displayed regardless of whether silences or mute timings are set.", + Id: "alerts-history", + Url: s.cfg.AppSubURL + "/alerting/history", + Icon: "history", + }) + } } if c.SignedInUser.GetOrgRole() == org.RoleAdmin { diff --git a/public/app/features/alerting/routes.tsx b/public/app/features/alerting/routes.tsx index 23031c03dc4..82a46aeacba 100644 --- a/public/app/features/alerting/routes.tsx +++ b/public/app/features/alerting/routes.tsx @@ -168,10 +168,7 @@ export function getAlertingRoutes(cfg = config): RouteDescriptor[] { }, { path: '/alerting/history/', - roles: evaluateAccess([ - AccessControlAction.AlertingInstanceRead, - AccessControlAction.AlertingInstancesExternalRead, - ]), + roles: evaluateAccess([AccessControlAction.AlertingRuleRead]), component: importAlertingComponent( () => import( diff --git a/public/app/features/alerting/unified/components/AlertLabels.tsx b/public/app/features/alerting/unified/components/AlertLabels.tsx index 5083e7c6f29..651dadb49e5 100644 --- a/public/app/features/alerting/unified/components/AlertLabels.tsx +++ b/public/app/features/alerting/unified/components/AlertLabels.tsx @@ -15,9 +15,10 @@ interface Props { labels: Record; commonLabels?: Record; size?: LabelSize; + onClick?: (label: string, value: string) => void; } -export const AlertLabels = ({ labels, commonLabels = {}, size }: Props) => { +export const AlertLabels = ({ labels, commonLabels = {}, size, onClick }: Props) => { const styles = useStyles2(getStyles, size); const [showCommonLabels, setShowCommonLabels] = useState(false); @@ -33,9 +34,19 @@ export const AlertLabels = ({ labels, commonLabels = {}, size }: Props) => { return (
- {labelsToShow.map(([label, value]) => ( -