36 Commits

Author SHA1 Message Date
edfe690ea2 Chore: Move Mock API into separate package (#104644) 2025-05-14 16:50:34 +03:00
67214c0a56 Alerting: Tidy up some leftover logic from pre-alertingApiServer (#104776) 2025-05-07 10:32:23 +03:00
3e15459d20 Alerting: Enhance Ruler and Prometheus group synchronization (#99012)
* Add group actions menu

* Refactor modals to accept raw ruler group

* Use prometheus and ruler responses to dispaly GMA rules in the hierarchical view

* Add groups loader component for data source managed rules

* Improve rules matching algorithm for the search results

* Use plus and minus icons for reconciliation state

* loading spinner WIP for operations / transactions

* update comment

* Use ruler rules order when displaying a group, change rurler preload behaviour

* Add ruler-based ordering for GMA rules

* Refactor ruler API mocking

* Refactor rule components to accept ruler only rules

* Add tests for GrafanaGroupLoader

* Add tests for vanilla prom groups

* Unify data matching code, add tests for DS groups loader

* Fix errors after rebasing

* Improve handling of ruler group absence

* Fix cache key

* Add group action buttons for the new group pages

* Add new rule action buttons to the new list page

* Address PR feeback, component renaming, missing translations

* Unify groups and rules links and actions

* Fix new rule button

* Add rule list action buttons tests

* Fix lint errors

* Add redirect to rule details page on save

* Update FilterView tests

* Fix imports and remove unused code

* Improve type definitions, add pooling to Prom hooks, add inline docs

* Remove unused code of group modals

* Update translations

* Disable cache population for filter-view generators

* Add consistency check Alert to the RuleViewer when V2 list is enabled

* Disable UI errors in prom generator

* Improve missing datasouce handling

* Add missing translations

* Improve group loader tests, remove unused code

* Enhance Prometheus API query to include notification options

* Improve error handling, remove consistency check for vanilla prom data sources

* Address PR feedback, add new version of the useHasRuler hook

---------

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2025-04-01 09:58:09 +02:00
2014d27def Alerting: Add alert rule version history - part1 (#99490)
* Add alertingRuleVersionHistory feature toggle

* WIP: Add version history tab

* revert temp change in index.ts

* wip2

* --wip--

* sync code with the BE changes in the endpoint

* add translations

* Add translations

* use ff only for restore feature

* WIP: Add tracking, make version required, and start mapping dif results
Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>

* Tweak more translations and improve types

* Add button to show/hide JSON diff

* update type for top level rule fields

* Create types

* Make updated_by/version properties optional

* Update mocks to remove updated by and version

* add comments to restore code

* rename fetature flag, as we use this one only for the restore feature

* Update version history to handle special cases

* Add diff numbers

* Fix conflicts

* Move generic computeVersionDiff to a utils file

* Update DOM structure of version summary and tidy up types

* Add tests for version comparison logic

* Lint fix utils file

* Rename props and add docs

* Change to EmptyState and log when no versions

* Remove CreatedBy component and simplify

* Add missing i18n for version history

* add test for computeVersionDiff

* update test

* fix number diff order and add a test

* fix prettier

* fix prettier

* Add promise resolve back in

* Rename to humanReadableDiff and tweak translation

* Show tab for recording rules as well

* Split components out to separate files

* Add optional interval seconds

* Update i18n

* Remove commented code

* Remove value

* Remove unneeded version

* Consistent rendering of updated by

* Mode parseVersionInfo to a separate pure function

* update invalidate/provide tags for getAlertVersionHistory

* Use checkedVersions state only in the parent component

* update getSpecialUidMap name and create an interface

* Fix prettier

* update tab description

* use set instead of map for checkedVersions

---------

Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
2025-02-17 13:25:32 +01:00
482af91782 Alerting: Remove manual feature discovery mocking (#96243)
* Update mock methods to remove discovery API

* Update tests to remove mock discovery API

* Remove ref in TESTING.md

* Fix other references to 'mimir'
2024-12-12 19:11:04 +02:00
4f7ffafe98 Alerting: Consistently order member imports in alerting code (#97688)
* Lint import member orders within alerting

* Consistently order member imports in alerting code
2024-12-10 17:42:33 +00:00
a2c407854f Alerting: Make alert rule policies preview use k8s API (#97070)
* Add translations for notification preview

* Make notifications endpoints use alertmanager config mock entity

* Fix translations and error handling in preview component

* Update preview hook to use new k8s APIs

* Move receivers k8s mock logic so it always comes from the mock config

* Fix test that wasn't using the correct receiver

* Fix object_matchers

* Remove mockApi method and update tests

* Update translation for error case

* Remove useMemo
2024-11-29 13:05:41 +00:00
e4a1243948 Alerting: Consume k8s API for notification policies tree (#96147)
* Add basic usage of K8s API for notification policies

* Add permissions checks for navtree for routes

* Add and update permissions for routing tree logic

* Add capability to skip calling contact points hook

* Conditionally show list of mute timings depending on permissions

* Conditionally link to mute timings if user can see at least one

* Add work in progress k8s handlers for routing tree

* Update notification policy hooks

* Wire up policies to permissions better (conditionally calling APIs)

* Add additional checks for whether to show grafana AM

* Add permission checks to access control

* Remove accidental permissions after rebase

* Update types and const for k8s routes

* Improve statefulness and reset routing tree in tests

* Update notif policy tests to check k8s and config API

* Fix type assertion

* Move non-grafana test out of .each

* Make failure case safer

* Override tag invalidation for notification policies API

* Pass in error and add new error alert component

* Add basic mock server conflict check

* Add test to check user can save after a conflict

* Add logic to allow reloading policies if changed by another user

* Fix test

* Update translations in Modals

* Add ViewAlertGroups ability

* Tweak provisioning logic and memoize AM config response

* Update snapshots for useAbilities

* Update result destructure

* Use enums for provenance in routingtrees

* Use consistent memoisation

* Fix _metadata for vanilla AM

* useAsync for error / update state

* move k8s api error handling to separate file

* use cause for error codes

* Use `supported` bools from Alertmanager abilities and clarify default policy

---------

Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2024-11-26 13:46:39 +00:00
4c5483ee15 Alerting: Fix notification policies tests and implement "stateful" mock endpoints (#94732) 2024-10-17 11:57:57 +01:00
41b175e7ae Alerting: Use useProduceNewAlertmanagerConfiguration for contact points (#88456) 2024-10-02 17:56:35 +03:00
9d639278f4 Alerting: Refactor simplified routing contact points hook (#90762) 2024-07-29 19:22:31 +03:00
a61cd94a70 Alerting: Tidy up contact points/misc other tests' mock server behaviour (#90469) 2024-07-19 16:11:48 +01:00
79df1b1e10 Alerting: Remove some unused mock server methods (#90432)
Remove some unused mock server methods
2024-07-17 16:50:25 +02:00
e84e0c9f08 Alerting: Make alert group editing safer (#88627) 2024-06-24 16:04:43 +03:00
170d476bdc Alerting: Add RBAC logic for silences creation (#87322)
* Remove role requirement for editing silence (instead handled by silence editor displaying error)

* Send query params for metadata/access control silence logic

* Add new access control types to enum

* Add folder-specific checks for silences

* Remove filtering in alert manager picker

* fix flakey rule viewer test and update permissions helper

* Use `returnTo` in rule viewer page

* Fix incorrect display of duration

* Clean up some mock server behaviour in rule details tests

* Tweak styles for silences alerts table

* Remove alertmanager picker from silences drawer

* Add error if user cannot edit a silence

* Show alert rule name in silences table and consume RBAC logic

* Update mocks to include RBAC access control logic

* Update silences tests

* Update silences type to include access control info

* Update comment for missing alertmanager

* Update mock handlers and query param logic

* Tweak query params again

* Update access control mock

* Revert AM picker fix as user may not have access to Grafana AM

* Swap ternary order

* Change text for no alert rule targeted

* Don't show error alert from RTKQ query and remove alert instance preview in case of error

* Add missing translations

* Fix test adding missing mock for getting alert rule

* Add missing translations in SilencesTable

* Add translations autogenerated files

* fix allowing edit silence in external alert manager

---------

Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2024-06-05 15:09:26 -04:00
9e29c215c3 Alerting: Update silences creation to support __alert_rule_uid__ and move into drawer (#87320) 2024-05-16 09:34:07 +01:00
f4d55d2612 Alerting: Restructure mock server handlers slightly and remove unnecessary handlers (#87759) 2024-05-15 16:53:16 +01:00
10fcd541e3 Add handlers to mock server 2024-04-29 14:15:48 +01:00
0582e05f8f Add PoC for different MSW approach 2024-04-24 15:57:11 +01:00
a5c75c5ffb Remove explicit imports of whatwg-fetch from individual test files 2024-04-18 12:23:38 +01:00
e234d098e9 Alerting: Get oncall metada only when we have alert manager configuration data (#85622)
* Get oncall metada from url in settings only when we have alert manager configuration

* Add test in useContactPointsWithStatus hook

* Fix tests
2024-04-09 09:02:44 +02:00
fb40c09eaf Reuse existing mock user method 2024-04-03 18:38:49 +01:00
b84962ef3f Update tests to use existing mock server approach 2024-04-03 18:38:49 +01:00
8dc1cd6d59 Alerting: Fix reading props from undefined in settings (#82418)
* Fix reading props from undefined in settings

* Make settings optional in GrafanaManagedReceiverConfig type
2024-02-15 00:38:20 +11:00
cf65d91ee9 Chore: upgrade to msw v2 (#82270)
* Update dependency msw to v2

* close

* minor fixes

* fetch import changes

* fix some alerting tests

* fix another alerting test

* fix systemjs tests

* don't return undefined in json mocks

* don't return undefined in json response

* add type

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-14 13:16:44 +00:00
d1dab5828d Alerting: Update rule API to address folders by UID (#74600)
* Change ruler API to expect the folder UID as namespace

* Update example requests

* Fix tests

* Update swagger

* Modify FIle field in /api/prometheus/grafana/api/v1/rules

* Fix ruler export

* Modify folder in responses to be formatted as <parent UID>/<title>

* Add alerting test with nested folders

* Apply suggestion from code review

* Alerting: use folder UID instead of title in rule API (#77166)

Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>

* Drop a few more latent uses of namespace_id

* move getNamespaceKey to models package

* switch GetAlertRulesForScheduling to use folder table

* update GetAlertRulesForScheduling to return folder titles in format `parent_uid/title`.

* fi tests

* add tests for GetAlertRulesForScheduling when parent uid

* fix integration tests after merge

* fix test after merge

* change format of the namespace to JSON array

this is needed for forward compatibility, when we migrate to full paths

* update EF code to decode nested folder

---------

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
Co-authored-by: Virginia Cepeda <virginia.cepeda@grafana.com>
Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
Co-authored-by: Alex Weaver <weaver.alex.d@gmail.com>
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2024-01-17 11:07:39 +02:00
be436ec6f6 Alerting: Adds contact point sorting and searching (#77390) 2023-11-07 11:05:12 +01:00
3c915d0502 Alerting: Fix Alert rule form editing when associated panel has no id (#77209) 2023-10-31 08:38:25 +01:00
42f4244026 Alerting: Add rules export on a folder level (#76016) 2023-10-12 20:17:32 +03:00
5484e0a2d5 Alerting: Add export drawer with yaml and json formats, in policies and contact points view. (#74613)
* Add export formats drawer when exporting contact points

* Add 'export by format' drawer in policies (root policy)

* Add test for showing export policies button

* Add tests for Policy.tsx

* Add tests for export functionality in receivers

* Add exporter drawer for receivers

* Fix prettier warnings

* Allow HCL only for alert rules exports

* Add tests for Policies

* Fix tests

* Refactor: Update ExportProviders types for limiting the avaliable export formats when using GrafanaExportDrawer

* Delete unused shouldShowExportOption method and tests

* Use useAlertmanagerAbility hook to check if canReadSecrets

* Update snapshot for useAbilities test

* Fix prettier

* Convert decrypt to boolean

* Fix prettier

* Rename CanReadSecrets action to DecryptSecrets

* Update the string value for DecryptSecrets

* Fix snapshor for useAbilities after renaming the can-read-secrets
2023-09-18 08:36:50 +02:00
e7a2c95586 Alerting: Add Grafana-managed groups and rules export (#74522) 2023-09-08 16:26:54 +02:00
7baf9cc033 Alerting: Custom contact point for OnCall in Grafana AM (#72021) 2023-09-06 12:33:35 +02:00
7631b0cf3f Alerting: Improve tests setup (#73316) 2023-08-22 13:50:41 +02:00
df3d10606d Alerting: Optimize rule details page data fetching (#72977) 2023-08-08 20:36:38 +02:00
f10527cfe3 Alerting: Contact points v2 part 2 (#71135) 2023-07-27 13:28:00 +02:00
9a252c763a Alerting: Add notification policies preview in alert creation (#68839)
* Add notification policies preview in alert rule form
Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>

* Refactor using new useGetPotentialInstances hook and apply some style changes

* Add notification policy detail modal

* Use backtesting api for simulating  potential alert instances

* Fix logic to travserse all the children from the root route

* Split notification preview by alert manager

* Add instance count to matching policy header and fix some styles

* Move some logic to a new hook useGetAlertManagersSourceNames to make the code more clean

* Fix some tests

* Add initial test for NotificationPreview

* Use button to preview potential instances

* Add link to contact point details

* Add route matching result details

* Show AlertManager image in the routing preview list

* Add tests setup, add single AM preview test

* Handle no matchers and no labels use case

* Update some style in collapse component and fix policy path in modal

* Update modal styles

* Update styles

* Update collapse header styling

* Normalize tree nodes should happen before findMatchingRoutes call

* Fix findMatchingRoutes and findMatchingAlertGroups methods after reabasing

* Move instances matching to the web worker code

* Fix config fetching for vanilla prometheus AMs

* Add tests

* Add tests mocks

* Fix tests after adding web worker

* Display matching labels for each matching alert instance

* Add minor css improvements

* Revert changes added in Collapse component as we don't use it anymore

* Move the route details modal to a separate file

* Move NotificationRoute and preview hook into separate files

* Fix Alertmanager preview tests

* Fix tests

* Move matcher code to a separate file, improve matcher mock

* Add permissions control for contact point edit view link

* Fix from and to for the temporal use of backtesting api

* Fix tests, add lazy loading of the preview component

Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>

* Fix preview test

* Add onclick on the header div so it collapse and expands when clicking on it, and update styles to be consistent with the rest of tables

* Adapt the code to the new rule testing endpoint definition

* Fix tests

* small changes after reviewing the final code

* compute entire inherited tree before computing the routes map

* Throw error in case of not having receiver in routesByIdMap and add test for the use case of inheriting receiver from parent to check UI throws no errors

* Add list of labels in the policy route path that produces the policy matchers to match potential instances

* Use color determined by the key, in label tags when hovering matchers in the policy tree

* Remove labels in modal and handle empty string as receiver to inherit from parent as we do with undefined

* Revert "Add list of labels in the policy route path that produces the policy matchers to match potential instances"

This reverts commit ee73ae9cf9caf10c33bcd58973279f23437a9146.

* fix inheritance for computeInheritedTree

* Fix message shown when preview has not been executed yet

* First round for adressing PR review comments

* Adress the rest of PR review commments

* Update texts and rename id prop in NotificaitonStep to alertUid

---------

Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2023-06-19 13:32:17 +02:00