grafana/public/app/features/alerting/unified/state/actions.ts

950 lines
33 KiB
TypeScript
Raw Normal View History

import { AsyncThunk, createAsyncThunk } from '@reduxjs/toolkit';
import { isEmpty } from 'lodash';
import { config, locationService } from '@grafana/runtime';
import {
AlertmanagerAlert,
AlertManagerCortexConfig,
AlertmanagerGroup,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
ExternalAlertmanagerConfig,
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
ExternalAlertmanagersResponse,
Receiver,
Silence,
SilenceCreatePayload,
TestReceiversAlert,
} from 'app/plugins/datasource/alertmanager/types';
import { FolderDTO, NotifierDTO, StoreState, ThunkResult } from 'app/types';
import {
CombinedRuleGroup,
CombinedRuleNamespace,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
PromBasedDataSource,
RuleIdentifier,
RuleNamespace,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
RulerDataSourceConfig,
RuleWithLocation,
StateHistoryItem,
} from 'app/types/unified-alerting';
import {
PostableRulerRuleGroupDTO,
PromApplication,
RulerRuleDTO,
RulerRulesConfigDTO,
} from 'app/types/unified-alerting-dto';
import { contextSrv } from '../../../../core/core';
import { backendSrv } from '../../../../core/services/backend_srv';
import { logInfo, LogMessages, trackNewAlerRuleFormSaved, withPerformanceLogging } from '../Analytics';
import {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
addAlertManagers,
createOrUpdateSilence,
deleteAlertManagerConfig,
expireSilence,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
fetchAlertGroups,
fetchAlertManagerConfig,
fetchAlerts,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
fetchExternalAlertmanagerConfig,
fetchExternalAlertmanagers,
fetchSilences,
fetchStatus,
testReceivers,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
updateAlertManagerConfig,
} from '../api/alertmanager';
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
import { fetchAnnotations } from '../api/annotations';
import { discoverFeatures } from '../api/buildInfo';
import { featureDiscoveryApi } from '../api/featureDiscoveryApi';
import { fetchNotifiers } from '../api/grafana';
import { FetchPromRulesFilter, fetchRules } from '../api/prometheus';
2021-04-14 07:57:36 -05:00
import {
deleteNamespace,
2021-04-14 07:57:36 -05:00
deleteRulerRulesGroup,
fetchRulerRules,
FetchRulerRulesFilter,
2021-04-14 07:57:36 -05:00
setRulerRuleGroup,
} from '../api/ruler';
import { getAlertInfo, safeParseDurationstr } from '../components/rules/EditRuleGroupModal';
2021-04-14 07:57:36 -05:00
import { RuleFormType, RuleFormValues } from '../types/rule-form';
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
import { addDefaultsToAlertmanagerConfig, removeMuteTimingFromRoute } from '../utils/alertmanager';
import {
getAllRulesSourceNames,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
getRulesDataSource,
getRulesSourceName,
GRAFANA_RULES_SOURCE_NAME,
isVanillaPrometheusAlertManagerDataSource,
} from '../utils/datasource';
import { makeAMLink, retryWhile } from '../utils/misc';
import { AsyncRequestMapSlice, messageFromError, withAppEvents, withSerializedError } from '../utils/redux';
Alerting: view to display alert rule and its underlying data. (#35546) * add page and basic things * quick annotations * added so we can run queries on the view rule page. * wip. * merge * cleaned up the combined rule hook. * readd queries * fixing so you can run queries. * renamed variable. * fix rerenders and visualizing * minor fixes. * work in progress. * wip * a working version that can be tested. * changing check if we have data. * removed unused styling. * removed unused dep. * removed another dep. * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * refactored and changed UI according to figma. * resseting menu item. * removing unused external link. * refactor according to feedback. * changed so we always fetch the rule. * fixing so datasource only is displayed once. Also changed so we only navigate to alert list when rule has been deleted. * removed unused dep. * Will display query as json if we can't find data source. * changed to a function instead of the React.FC. * refactoring of id generation and added support to generate ids for native prometheus alerts without ruler. * set max width on page content * added page where you can easily link to a rule in grafana. * listing rules with same name. * fixing error cases. * updates after pr feedback * more pr feedback * use 1h-now as timerange * remove unused import * start on test * add test for cloud case * add ruleview render test * add render tests for grafana and cloud alerts * add mock for backendsrv * add rendering test for the find route * check if cards are rendered Co-authored-by: Peter Holmberg <peter.hlmbrg@gmail.com> Co-authored-by: Domas <domas.lapinskas@grafana.com>
2021-07-01 05:02:41 -05:00
import * as ruleId from '../utils/rule-id';
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
import { getRulerClient } from '../utils/rulerClient';
import { isRulerNotSupportedResponse } from '../utils/rules';
const FETCH_CONFIG_RETRY_TIMEOUT = 30 * 1000;
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
function getDataSourceConfig(getState: () => unknown, rulesSourceName: string) {
const dataSources = (getState() as StoreState).unifiedAlerting.dataSources;
const dsConfig = dataSources[rulesSourceName]?.result;
if (!dsConfig) {
throw new Error(`Data source configuration is not available for "${rulesSourceName}" data source`);
}
return dsConfig;
}
function getDataSourceRulerConfig(getState: () => unknown, rulesSourceName: string) {
const dsConfig = getDataSourceConfig(getState, rulesSourceName);
if (!dsConfig.rulerConfig) {
throw new Error(`Ruler API is not available for ${rulesSourceName}`);
}
return dsConfig.rulerConfig;
}
export const fetchPromRulesAction = createAsyncThunk(
'unifiedalerting/fetchPromRules',
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
async (
{ rulesSourceName, filter }: { rulesSourceName: string; filter?: FetchPromRulesFilter },
thunkAPI
): Promise<RuleNamespace[]> => {
await thunkAPI.dispatch(fetchRulesSourceBuildInfoAction({ rulesSourceName }));
2022-10-31 09:55:47 -05:00
const fetchRulesWithLogging = withPerformanceLogging(fetchRules, `[${rulesSourceName}] Prometheus rules loaded`, {
dataSourceName: rulesSourceName,
thunk: 'unifiedalerting/fetchPromRules',
});
return await withSerializedError(fetchRulesWithLogging(rulesSourceName, filter));
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
}
);
export const fetchAlertManagerConfigAction = createAsyncThunk(
'unifiedalerting/fetchAmConfig',
(alertManagerSourceName: string, thunkAPI): Promise<AlertManagerCortexConfig> =>
withSerializedError(
(async () => {
// for vanilla prometheus, there is no config endpoint. Only fetch config from status
if (isVanillaPrometheusAlertManagerDataSource(alertManagerSourceName)) {
return fetchStatus(alertManagerSourceName).then((status) => ({
alertmanager_config: status.config,
template_files: {},
}));
}
const { data: amFeatures } = await thunkAPI.dispatch(
featureDiscoveryApi.endpoints.discoverAmFeatures.initiate({
amSourceName: alertManagerSourceName,
})
);
const lazyConfigInitSupported = amFeatures?.lazyConfigInit ?? false;
2022-10-31 09:55:47 -05:00
const fetchAMconfigWithLogging = withPerformanceLogging(
fetchAlertManagerConfig,
`[${alertManagerSourceName}] Alertmanager config loaded`,
{
dataSourceName: alertManagerSourceName,
thunk: 'unifiedalerting/fetchAmConfig',
}
);
return retryWhile(
2022-10-31 09:55:47 -05:00
() => fetchAMconfigWithLogging(alertManagerSourceName),
// if config has been recently deleted, it takes a while for cortex start returning the default one.
// retry for a short while instead of failing
(e) => !!messageFromError(e)?.includes('alertmanager storage object not found') && !lazyConfigInitSupported,
FETCH_CONFIG_RETRY_TIMEOUT
)
.then((result) => {
// if user config is empty for cortex alertmanager, try to get config from status endpoint
if (
isEmpty(result.alertmanager_config) &&
isEmpty(result.template_files) &&
alertManagerSourceName !== GRAFANA_RULES_SOURCE_NAME
) {
return fetchStatus(alertManagerSourceName).then((status) => ({
alertmanager_config: status.config,
template_files: {},
template_file_provenances: result.template_file_provenances,
Alerting: Choose a previous valid AM configuration in case of error (#65746) * Add new property to AlertmanagerConfig type * Implement fetching successfully applied configurations Added method to fetch them from the API and its corresponding action and reducer * Extract ConfigEditor as component to avoid code duplication * Display dropdown with valid configs upon error and allow to save them * Fix tests * Refactor to call new endpoint using RTK * Improve texts * Apply suggested refactor * Change constant casing * Only show config selector for Grafana AM * Remove ts-ignore * Move code together for simplicity * Remove invalid mock * Update endpoint and types based on backend changes * Rename property * Rename alermanager config property from backend changes * Disable editing old configurations Due to the latest backend changes, we no longer will provide the option to edit previous AM configurations in a textearea. Instead users will only be allowed to reset to a specific one with the same content. For this reason the textearea for old conf igurations is disabled and a different form action (not submit) is executed on the "reset config" button. The updateAlertManage rConfigAction is reset to its old functionality due to these changes. * Add id to AlertManagerCortexConfig type We'll need it to pass as a parameter to the new reset endpoint * Add new endpoint for resetting AM configs to an old version * Move the "Reset to selected configuration" button next to the drop-down * Add relative offset to configurations
2023-04-05 13:13:33 -05:00
last_applied: result.last_applied,
id: result.id,
}));
}
return result;
})
.catch((e) => {
// When mimir doesn't have fallback AM url configured the default response will be as above
// However it's fine, and it's possible to create AM configuration
if (lazyConfigInitSupported && messageFromError(e)?.includes('alertmanager storage object not found')) {
return Promise.resolve<AlertManagerCortexConfig>({
alertmanager_config: {},
template_files: {},
template_file_provenances: {},
});
}
throw e;
});
})()
)
);
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
export const fetchExternalAlertmanagersAction = createAsyncThunk(
'unifiedAlerting/fetchExternalAlertmanagers',
(): Promise<ExternalAlertmanagersResponse> => {
return withSerializedError(fetchExternalAlertmanagers());
}
);
export const fetchExternalAlertmanagersConfigAction = createAsyncThunk(
'unifiedAlerting/fetchExternAlertmanagersConfig',
(): Promise<ExternalAlertmanagerConfig> => {
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
return withSerializedError(fetchExternalAlertmanagerConfig());
}
);
export const fetchRulerRulesAction = createAsyncThunk(
'unifiedalerting/fetchRulerRules',
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
async (
{
rulesSourceName,
filter,
}: {
rulesSourceName: string;
filter?: FetchRulerRulesFilter;
},
{ dispatch, getState }
): Promise<RulerRulesConfigDTO | null> => {
await dispatch(fetchRulesSourceBuildInfoAction({ rulesSourceName }));
const rulerConfig = getDataSourceRulerConfig(getState, rulesSourceName);
2022-10-31 09:55:47 -05:00
const fetchRulerRulesWithLogging = withPerformanceLogging(
fetchRulerRules,
`[${rulesSourceName}] Ruler rules loaded`,
{
dataSourceName: rulesSourceName,
thunk: 'unifiedalerting/fetchRulerRules',
}
);
return await withSerializedError(fetchRulerRulesWithLogging(rulerConfig, filter));
}
);
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
export function fetchPromAndRulerRulesAction({ rulesSourceName }: { rulesSourceName: string }): ThunkResult<void> {
return async (dispatch, getState) => {
await dispatch(fetchRulesSourceBuildInfoAction({ rulesSourceName }));
const dsConfig = getDataSourceConfig(getState, rulesSourceName);
await dispatch(fetchPromRulesAction({ rulesSourceName }));
if (dsConfig.rulerConfig) {
await dispatch(fetchRulerRulesAction({ rulesSourceName }));
}
};
}
export const fetchSilencesAction = createAsyncThunk(
'unifiedalerting/fetchSilences',
(alertManagerSourceName: string): Promise<Silence[]> => {
2022-10-31 09:55:47 -05:00
const fetchSilencesWithLogging = withPerformanceLogging(
fetchSilences,
`[${alertManagerSourceName}] Silences loaded`,
{
dataSourceName: alertManagerSourceName,
thunk: 'unifiedalerting/fetchSilences',
}
);
return withSerializedError(fetchSilencesWithLogging(alertManagerSourceName));
}
);
2021-04-14 07:57:36 -05:00
// this will only trigger ruler rules fetch if rules are not loaded yet and request is not in flight
export function fetchRulerRulesIfNotFetchedYet(rulesSourceName: string): ThunkResult<void> {
2021-04-14 07:57:36 -05:00
return (dispatch, getStore) => {
const { rulerRules } = getStore().unifiedAlerting;
const resp = rulerRules[rulesSourceName];
const emptyResults = isEmpty(resp?.result);
if (emptyResults && !(resp && isRulerNotSupportedResponse(resp)) && !resp?.loading) {
dispatch(fetchRulerRulesAction({ rulesSourceName }));
2021-04-14 07:57:36 -05:00
}
};
}
// TODO: memoize this or move to RTK Query so we can cache results!
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
export function fetchAllPromBuildInfoAction(): ThunkResult<Promise<void>> {
return async (dispatch) => {
const allRequests = getAllRulesSourceNames().map((rulesSourceName) =>
dispatch(fetchRulesSourceBuildInfoAction({ rulesSourceName }))
);
await Promise.allSettled(allRequests);
};
}
export const fetchRulesSourceBuildInfoAction = createAsyncThunk(
'unifiedalerting/fetchPromBuildinfo',
async ({ rulesSourceName }: { rulesSourceName: string }): Promise<PromBasedDataSource> => {
return withSerializedError<PromBasedDataSource>(
(async (): Promise<PromBasedDataSource> => {
if (rulesSourceName === GRAFANA_RULES_SOURCE_NAME) {
return {
name: GRAFANA_RULES_SOURCE_NAME,
id: GRAFANA_RULES_SOURCE_NAME,
rulerConfig: {
dataSourceName: GRAFANA_RULES_SOURCE_NAME,
apiVersion: 'legacy',
},
};
}
const ds = getRulesDataSource(rulesSourceName);
if (!ds) {
throw new Error(`Missing data source configuration for ${rulesSourceName}`);
}
const { id, name } = ds;
2022-10-31 09:55:47 -05:00
const discoverFeaturesWithLogging = withPerformanceLogging(
discoverFeatures,
`[${rulesSourceName}] Rules source features discovered`,
{
dataSourceName: rulesSourceName,
thunk: 'unifiedalerting/fetchPromBuildinfo',
}
);
const buildInfo = await discoverFeaturesWithLogging(name);
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulerConfig: RulerDataSourceConfig | undefined = buildInfo.features.rulerApiEnabled
? {
dataSourceName: name,
apiVersion: buildInfo.application === PromApplication.Cortex ? 'legacy' : 'config',
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
}
: undefined;
return {
name: name,
id: id,
rulerConfig,
};
})()
);
},
{
condition: ({ rulesSourceName }, { getState }) => {
const dataSources: AsyncRequestMapSlice<PromBasedDataSource> = (getState() as StoreState).unifiedAlerting
.dataSources;
const hasLoaded = Boolean(dataSources[rulesSourceName]?.result);
const hasError = Boolean(dataSources[rulesSourceName]?.error);
return !(hasLoaded || hasError);
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
},
}
);
export function fetchAllPromAndRulerRulesAction(force = false): ThunkResult<Promise<void>> {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
return async (dispatch, getStore) => {
2022-10-31 09:55:47 -05:00
const allStartLoadingTs = performance.now();
await Promise.allSettled(
getAllRulesSourceNames().map(async (rulesSourceName) => {
await dispatch(fetchRulesSourceBuildInfoAction({ rulesSourceName }));
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const { promRules, rulerRules, dataSources } = getStore().unifiedAlerting;
const dataSourceConfig = dataSources[rulesSourceName].result;
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
if (!dataSourceConfig) {
return;
}
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const shouldLoadProm = force || !promRules[rulesSourceName]?.loading;
2022-10-31 09:55:47 -05:00
const shouldLoadRuler =
(force || !rulerRules[rulesSourceName]?.loading) && Boolean(dataSourceConfig.rulerConfig);
await Promise.allSettled([
shouldLoadProm && dispatch(fetchPromRulesAction({ rulesSourceName })),
shouldLoadRuler && dispatch(fetchRulerRulesAction({ rulesSourceName })),
]);
})
);
2022-10-31 09:55:47 -05:00
logInfo('All Prom and Ruler rules loaded', {
loadTimeMs: (performance.now() - allStartLoadingTs).toFixed(0),
});
};
}
export function fetchAllPromRulesAction(force = false): ThunkResult<void> {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
return async (dispatch, getStore) => {
const { promRules } = getStore().unifiedAlerting;
getAllRulesSourceNames().map((rulesSourceName) => {
if (force || !promRules[rulesSourceName]?.loading) {
dispatch(fetchPromRulesAction({ rulesSourceName }));
}
});
};
}
Alerting: view to display alert rule and its underlying data. (#35546) * add page and basic things * quick annotations * added so we can run queries on the view rule page. * wip. * merge * cleaned up the combined rule hook. * readd queries * fixing so you can run queries. * renamed variable. * fix rerenders and visualizing * minor fixes. * work in progress. * wip * a working version that can be tested. * changing check if we have data. * removed unused styling. * removed unused dep. * removed another dep. * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * refactored and changed UI according to figma. * resseting menu item. * removing unused external link. * refactor according to feedback. * changed so we always fetch the rule. * fixing so datasource only is displayed once. Also changed so we only navigate to alert list when rule has been deleted. * removed unused dep. * Will display query as json if we can't find data source. * changed to a function instead of the React.FC. * refactoring of id generation and added support to generate ids for native prometheus alerts without ruler. * set max width on page content * added page where you can easily link to a rule in grafana. * listing rules with same name. * fixing error cases. * updates after pr feedback * more pr feedback * use 1h-now as timerange * remove unused import * start on test * add test for cloud case * add ruleview render test * add render tests for grafana and cloud alerts * add mock for backendsrv * add rendering test for the find route * check if cards are rendered Co-authored-by: Peter Holmberg <peter.hlmbrg@gmail.com> Co-authored-by: Domas <domas.lapinskas@grafana.com>
2021-07-01 05:02:41 -05:00
export const fetchEditableRuleAction = createAsyncThunk(
'unifiedalerting/fetchEditableRule',
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
(ruleIdentifier: RuleIdentifier, thunkAPI): Promise<RuleWithLocation | null> => {
const rulerConfig = getDataSourceRulerConfig(thunkAPI.getState, ruleIdentifier.ruleSourceName);
return withSerializedError(getRulerClient(rulerConfig).findEditableRule(ruleIdentifier));
}
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
);
export function deleteRulesGroupAction(
namespace: CombinedRuleNamespace,
ruleGroup: CombinedRuleGroup
): ThunkResult<void> {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
return async (dispatch, getState) => {
withAppEvents(
(async () => {
const sourceName = getRulesSourceName(namespace.rulesSource);
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulerConfig = getDataSourceRulerConfig(getState, sourceName);
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
await deleteRulerRulesGroup(rulerConfig, namespace.name, ruleGroup.name);
await dispatch(fetchPromAndRulerRulesAction({ rulesSourceName: sourceName }));
})(),
{ successMessage: 'Group deleted' }
);
};
}
Alerting: view to display alert rule and its underlying data. (#35546) * add page and basic things * quick annotations * added so we can run queries on the view rule page. * wip. * merge * cleaned up the combined rule hook. * readd queries * fixing so you can run queries. * renamed variable. * fix rerenders and visualizing * minor fixes. * work in progress. * wip * a working version that can be tested. * changing check if we have data. * removed unused styling. * removed unused dep. * removed another dep. * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * refactored and changed UI according to figma. * resseting menu item. * removing unused external link. * refactor according to feedback. * changed so we always fetch the rule. * fixing so datasource only is displayed once. Also changed so we only navigate to alert list when rule has been deleted. * removed unused dep. * Will display query as json if we can't find data source. * changed to a function instead of the React.FC. * refactoring of id generation and added support to generate ids for native prometheus alerts without ruler. * set max width on page content * added page where you can easily link to a rule in grafana. * listing rules with same name. * fixing error cases. * updates after pr feedback * more pr feedback * use 1h-now as timerange * remove unused import * start on test * add test for cloud case * add ruleview render test * add render tests for grafana and cloud alerts * add mock for backendsrv * add rendering test for the find route * check if cards are rendered Co-authored-by: Peter Holmberg <peter.hlmbrg@gmail.com> Co-authored-by: Domas <domas.lapinskas@grafana.com>
2021-07-01 05:02:41 -05:00
export function deleteRuleAction(
ruleIdentifier: RuleIdentifier,
options: { navigateTo?: string } = {}
): ThunkResult<void> {
/*
* fetch the rules group from backend, delete group if it is found and+
* reload ruler rules
*/
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
return async (dispatch, getState) => {
withAppEvents(
(async () => {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulerConfig = getDataSourceRulerConfig(getState, ruleIdentifier.ruleSourceName);
const rulerClient = getRulerClient(rulerConfig);
const ruleWithLocation = await rulerClient.findEditableRule(ruleIdentifier);
if (!ruleWithLocation) {
throw new Error('Rule not found.');
}
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
await rulerClient.deleteRule(ruleWithLocation);
// refetch rules for this rules source
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
await dispatch(fetchPromAndRulerRulesAction({ rulesSourceName: ruleWithLocation.ruleSourceName }));
Alerting: view to display alert rule and its underlying data. (#35546) * add page and basic things * quick annotations * added so we can run queries on the view rule page. * wip. * merge * cleaned up the combined rule hook. * readd queries * fixing so you can run queries. * renamed variable. * fix rerenders and visualizing * minor fixes. * work in progress. * wip * a working version that can be tested. * changing check if we have data. * removed unused styling. * removed unused dep. * removed another dep. * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * Update public/app/features/alerting/unified/hooks/useCombinedRule.ts Co-authored-by: Domas <domas.lapinskas@grafana.com> * refactored and changed UI according to figma. * resseting menu item. * removing unused external link. * refactor according to feedback. * changed so we always fetch the rule. * fixing so datasource only is displayed once. Also changed so we only navigate to alert list when rule has been deleted. * removed unused dep. * Will display query as json if we can't find data source. * changed to a function instead of the React.FC. * refactoring of id generation and added support to generate ids for native prometheus alerts without ruler. * set max width on page content * added page where you can easily link to a rule in grafana. * listing rules with same name. * fixing error cases. * updates after pr feedback * more pr feedback * use 1h-now as timerange * remove unused import * start on test * add test for cloud case * add ruleview render test * add render tests for grafana and cloud alerts * add mock for backendsrv * add rendering test for the find route * check if cards are rendered Co-authored-by: Peter Holmberg <peter.hlmbrg@gmail.com> Co-authored-by: Domas <domas.lapinskas@grafana.com>
2021-07-01 05:02:41 -05:00
if (options.navigateTo) {
locationService.replace(options.navigateTo);
}
})(),
{
successMessage: 'Rule deleted.',
}
);
};
}
2021-04-14 07:57:36 -05:00
export const saveRuleFormAction = createAsyncThunk(
'unifiedalerting/saveRuleForm',
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
(
{
values,
existing,
redirectOnSave,
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
evaluateEvery,
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
}: {
values: RuleFormValues;
existing?: RuleWithLocation;
redirectOnSave?: string;
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
initialAlertRuleName?: string;
evaluateEvery: string;
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
},
thunkAPI
): Promise<void> =>
withAppEvents(
withSerializedError(
(async () => {
const { type } = values;
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
// TODO getRulerConfig should be smart enough to provide proper rulerClient implementation
// For the dataSourceName specified
// in case of system (cortex/loki)
let identifier: RuleIdentifier;
if (type === RuleFormType.cloudAlerting || type === RuleFormType.cloudRecording) {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
if (!values.dataSourceName) {
throw new Error('The Data source has not been defined.');
}
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulerConfig = getDataSourceRulerConfig(thunkAPI.getState, values.dataSourceName);
const rulerClient = getRulerClient(rulerConfig);
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
identifier = await rulerClient.saveLotexRule(values, evaluateEvery, existing);
await thunkAPI.dispatch(fetchRulerRulesAction({ rulesSourceName: values.dataSourceName }));
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
// in case of grafana managed
} else if (type === RuleFormType.grafana) {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulerConfig = getDataSourceRulerConfig(thunkAPI.getState, GRAFANA_RULES_SOURCE_NAME);
const rulerClient = getRulerClient(rulerConfig);
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
identifier = await rulerClient.saveGrafanaRule(values, evaluateEvery, existing);
await thunkAPI.dispatch(fetchRulerRulesAction({ rulesSourceName: GRAFANA_RULES_SOURCE_NAME }));
} else {
throw new Error('Unexpected rule form type');
}
logInfo(LogMessages.successSavingAlertRule, { type, isNew: (!existing).toString() });
if (!existing) {
trackNewAlerRuleFormSaved({
grafana_version: config.buildInfo.version,
org_id: contextSrv.user.orgId,
user_id: contextSrv.user.id,
});
}
if (redirectOnSave) {
locationService.push(redirectOnSave);
} else {
// if the identifier comes up empty (this happens when Grafana managed rule moves to another namespace or group)
const stringifiedIdentifier = ruleId.stringifyIdentifier(identifier);
if (!stringifiedIdentifier) {
locationService.push('/alerting/list');
return;
}
// redirect to edit page
const newLocation = `/alerting/${encodeURIComponent(stringifiedIdentifier)}/edit`;
if (locationService.getLocation().pathname !== newLocation) {
locationService.replace(newLocation);
} else {
// refresh the details of the current editable rule after saving
thunkAPI.dispatch(fetchEditableRuleAction(identifier));
}
}
})()
),
{
successMessage: existing ? `Rule "${values.name}" updated.` : `Rule "${values.name}" saved.`,
errorMessage: 'Failed to save rule',
}
2021-04-14 07:57:36 -05:00
)
);
export const fetchGrafanaNotifiersAction = createAsyncThunk(
'unifiedalerting/fetchGrafanaNotifiers',
(): Promise<NotifierDTO[]> => withSerializedError(fetchNotifiers())
);
2021-12-14 09:36:54 -06:00
export const fetchGrafanaAnnotationsAction = createAsyncThunk(
'unifiedalerting/fetchGrafanaAnnotations',
(alertId: string): Promise<StateHistoryItem[]> => withSerializedError(fetchAnnotations(alertId))
);
interface UpdateAlertManagerConfigActionOptions {
alertManagerSourceName: string;
oldConfig: AlertManagerCortexConfig; // it will be checked to make sure it didn't change in the meanwhile
newConfig: AlertManagerCortexConfig;
successMessage?: string; // show toast on success
redirectPath?: string; // where to redirect on success
refetch?: boolean; // refetch config on success
}
export const updateAlertManagerConfigAction = createAsyncThunk<void, UpdateAlertManagerConfigActionOptions, {}>(
'unifiedalerting/updateAMConfig',
({ alertManagerSourceName, oldConfig, newConfig, successMessage, redirectPath, refetch }, thunkAPI): Promise<void> =>
withAppEvents(
withSerializedError(
(async () => {
// TODO there must be a better way here than to dispatch another fetch as this causes re-rendering :(
const latestConfig = await thunkAPI.dispatch(fetchAlertManagerConfigAction(alertManagerSourceName)).unwrap();
Alerting: Choose a previous valid AM configuration in case of error (#65746) * Add new property to AlertmanagerConfig type * Implement fetching successfully applied configurations Added method to fetch them from the API and its corresponding action and reducer * Extract ConfigEditor as component to avoid code duplication * Display dropdown with valid configs upon error and allow to save them * Fix tests * Refactor to call new endpoint using RTK * Improve texts * Apply suggested refactor * Change constant casing * Only show config selector for Grafana AM * Remove ts-ignore * Move code together for simplicity * Remove invalid mock * Update endpoint and types based on backend changes * Rename property * Rename alermanager config property from backend changes * Disable editing old configurations Due to the latest backend changes, we no longer will provide the option to edit previous AM configurations in a textearea. Instead users will only be allowed to reset to a specific one with the same content. For this reason the textearea for old conf igurations is disabled and a different form action (not submit) is executed on the "reset config" button. The updateAlertManage rConfigAction is reset to its old functionality due to these changes. * Add id to AlertManagerCortexConfig type We'll need it to pass as a parameter to the new reset endpoint * Add new endpoint for resetting AM configs to an old version * Move the "Reset to selected configuration" button next to the drop-down * Add relative offset to configurations
2023-04-05 13:13:33 -05:00
const isLatestConfigEmpty = isEmpty(latestConfig.alertmanager_config) && isEmpty(latestConfig.template_files);
const oldLastConfigsDiffer = JSON.stringify(latestConfig) !== JSON.stringify(oldConfig);
if (!isLatestConfigEmpty && oldLastConfigsDiffer) {
throw new Error(
'It seems configuration has been recently updated. Please reload page and try again to make sure that recent changes are not overwritten.'
);
}
await updateAlertManagerConfig(alertManagerSourceName, addDefaultsToAlertmanagerConfig(newConfig));
if (refetch) {
await thunkAPI.dispatch(fetchAlertManagerConfigAction(alertManagerSourceName));
}
if (redirectPath) {
locationService.push(makeAMLink(redirectPath, alertManagerSourceName));
}
})()
),
{
successMessage,
}
)
);
export const fetchAmAlertsAction = createAsyncThunk(
'unifiedalerting/fetchAmAlerts',
(alertManagerSourceName: string): Promise<AlertmanagerAlert[]> =>
withSerializedError(fetchAlerts(alertManagerSourceName, [], true, true, true))
);
export const expireSilenceAction = (alertManagerSourceName: string, silenceId: string): ThunkResult<void> => {
return async (dispatch) => {
await withAppEvents(expireSilence(alertManagerSourceName, silenceId), {
successMessage: 'Silence expired.',
});
dispatch(fetchSilencesAction(alertManagerSourceName));
dispatch(fetchAmAlertsAction(alertManagerSourceName));
};
};
type UpdateSilenceActionOptions = {
alertManagerSourceName: string;
payload: SilenceCreatePayload;
exitOnSave: boolean;
successMessage?: string;
};
export const createOrUpdateSilenceAction = createAsyncThunk<void, UpdateSilenceActionOptions, {}>(
'unifiedalerting/updateSilence',
({ alertManagerSourceName, payload, exitOnSave, successMessage }): Promise<void> =>
withAppEvents(
withSerializedError(
(async () => {
await createOrUpdateSilence(alertManagerSourceName, payload);
if (exitOnSave) {
locationService.push('/alerting/silences');
}
})()
),
{
successMessage,
}
)
);
export const deleteReceiverAction = (receiverName: string, alertManagerSourceName: string): ThunkResult<void> => {
return (dispatch, getState) => {
const config = getState().unifiedAlerting.amConfigs?.[alertManagerSourceName]?.result;
if (!config) {
throw new Error(`Config for ${alertManagerSourceName} not found`);
}
if (!config.alertmanager_config.receivers?.find((receiver) => receiver.name === receiverName)) {
throw new Error(`Cannot delete receiver ${receiverName}: not found in config.`);
}
const newConfig: AlertManagerCortexConfig = {
...config,
alertmanager_config: {
...config.alertmanager_config,
receivers: config.alertmanager_config.receivers.filter((receiver) => receiver.name !== receiverName),
},
};
return dispatch(
updateAlertManagerConfigAction({
newConfig,
oldConfig: config,
alertManagerSourceName,
successMessage: 'Contact point deleted.',
refetch: true,
})
);
};
};
export const deleteTemplateAction = (templateName: string, alertManagerSourceName: string): ThunkResult<void> => {
return (dispatch, getState) => {
const config = getState().unifiedAlerting.amConfigs?.[alertManagerSourceName]?.result;
if (!config) {
throw new Error(`Config for ${alertManagerSourceName} not found`);
}
if (typeof config.template_files?.[templateName] !== 'string') {
throw new Error(`Cannot delete template ${templateName}: not found in config.`);
}
const newTemplates = { ...config.template_files };
delete newTemplates[templateName];
const newConfig: AlertManagerCortexConfig = {
...config,
alertmanager_config: {
...config.alertmanager_config,
templates: config.alertmanager_config.templates?.filter((existing) => existing !== templateName),
},
template_files: newTemplates,
};
return dispatch(
updateAlertManagerConfigAction({
newConfig,
oldConfig: config,
alertManagerSourceName,
successMessage: 'Template deleted.',
refetch: true,
})
);
};
};
export const fetchFolderAction = createAsyncThunk(
'unifiedalerting/fetchFolder',
(uid: string): Promise<FolderDTO> => withSerializedError(backendSrv.getFolderByUid(uid, { withAccessControl: true }))
);
export const fetchFolderIfNotFetchedAction = (uid: string): ThunkResult<void> => {
return (dispatch, getState) => {
if (!getState().unifiedAlerting.folders[uid]?.dispatched) {
dispatch(fetchFolderAction(uid));
}
};
};
export const fetchAlertGroupsAction = createAsyncThunk(
'unifiedalerting/fetchAlertGroups',
(alertManagerSourceName: string): Promise<AlertmanagerGroup[]> => {
return withSerializedError(fetchAlertGroups(alertManagerSourceName));
}
);
export const deleteAlertManagerConfigAction = createAsyncThunk(
'unifiedalerting/deleteAlertManagerConfig',
async (alertManagerSourceName: string, thunkAPI): Promise<void> => {
return withAppEvents(
withSerializedError(
(async () => {
await deleteAlertManagerConfig(alertManagerSourceName);
await thunkAPI.dispatch(fetchAlertManagerConfigAction(alertManagerSourceName));
})()
),
{
errorMessage: 'Failed to reset Alertmanager configuration',
successMessage: 'Alertmanager configuration reset.',
}
);
}
);
export const deleteMuteTimingAction = (alertManagerSourceName: string, muteTimingName: string): ThunkResult<void> => {
return async (dispatch, getState) => {
const config = getState().unifiedAlerting.amConfigs[alertManagerSourceName].result;
const muteIntervals =
config?.alertmanager_config?.mute_time_intervals?.filter(({ name }) => name !== muteTimingName) ?? [];
if (config) {
withAppEvents(
dispatch(
updateAlertManagerConfigAction({
alertManagerSourceName,
oldConfig: config,
newConfig: {
...config,
alertmanager_config: {
...config.alertmanager_config,
route: config.alertmanager_config.route
? removeMuteTimingFromRoute(muteTimingName, config.alertmanager_config?.route)
: undefined,
mute_time_intervals: muteIntervals,
},
},
refetch: true,
})
),
{
successMessage: `Deleted "${muteTimingName}" from Alertmanager configuration`,
errorMessage: 'Failed to delete mute timing',
}
);
}
};
};
interface TestReceiversOptions {
alertManagerSourceName: string;
receivers: Receiver[];
alert?: TestReceiversAlert;
}
export const testReceiversAction = createAsyncThunk(
'unifiedalerting/testReceivers',
({ alertManagerSourceName, receivers, alert }: TestReceiversOptions): Promise<void> => {
return withAppEvents(withSerializedError(testReceivers(alertManagerSourceName, receivers, alert)), {
errorMessage: 'Failed to send test alert.',
successMessage: 'Test alert sent.',
});
}
);
interface UpdateNamespaceAndGroupOptions {
rulesSourceName: string;
namespaceName: string;
groupName: string;
newNamespaceName: string;
newGroupName: string;
groupInterval?: string;
}
export const rulesInSameGroupHaveInvalidFor = (rules: RulerRuleDTO[], everyDuration: string) => {
return rules.filter((rule: RulerRuleDTO) => {
const { forDuration } = getAlertInfo(rule, everyDuration);
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
const forNumber = safeParseDurationstr(forDuration);
const everyNumber = safeParseDurationstr(everyDuration);
Alerting: Improve UI for making more clear that evaluation interval belongs to the group (#56397) * In GrafanaEvaluationBehaviour component : Split evaluation interval from for duration and add button to edit to allow editing it and warning * Move folder and group fields to the evaluation section in the alert form * Include 'Group behaviour' info in a card and fix 'Edit group behaviour' button onClick. * Create hook for getting groups for a particular folder * Use dropdown in group instead of input and fill it with groups that belong to the selected folder * Add evaluation interval for each group in dropdown , and show warning in case user wants to update it * Avoid saving evaluation interval when some rules in the same group would have invalid For with this change * Clear group value when reseting the drop down * Remove evaluationEvery from form values, show this as a label and add a button to edit the group * Open EditRuleGroupModal for editing evaluation interval form the alert rule form * Fix aligment in group behaviour card * compact space in evaluation behaviour card and change group drop down label * In EditgroupModal, in case of grafana managed group, show folder instead of namespcace label and disable the folder name input * Add edge case in rulesInSameGroupHaveInvalidFor method when For value is zero * Vertically align annotations input to the evaluation section in alert rule form * Fix width when editing new group * Add placeholder for group input * Make folder and group in modal readonly from alert form and disable edit group button when new group * Update texts * Don't show evaluation behaviour section until folder and group are selected * Update texts * Fix merge conflits * Fix wrong margin in evaluation label * Remove non-used isRulerGrafanaRuleDTO method * Remove negative margin to avoid overlaping on Firefox
2022-11-21 10:59:19 -06:00
return forNumber !== 0 && forNumber < everyNumber;
});
};
// allows renaming namespace, renaming group and changing group interval, all in one go
export const updateLotexNamespaceAndGroupAction: AsyncThunk<
void,
UpdateNamespaceAndGroupOptions,
{ state: StoreState }
> = createAsyncThunk<void, UpdateNamespaceAndGroupOptions, { state: StoreState }>(
'unifiedalerting/updateLotexNamespaceAndGroup',
async (options: UpdateNamespaceAndGroupOptions, thunkAPI): Promise<void> => {
return withAppEvents(
withSerializedError(
(async () => {
const { rulesSourceName, namespaceName, groupName, newNamespaceName, newGroupName, groupInterval } = options;
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulerConfig = getDataSourceRulerConfig(thunkAPI.getState, rulesSourceName);
// fetch rules and perform sanity checks
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
const rulesResult = await fetchRulerRules(rulerConfig);
const existingNamespace = Boolean(rulesResult[namespaceName]);
if (!existingNamespace) {
throw new Error(`Namespace "${namespaceName}" not found.`);
}
const existingGroup = rulesResult[namespaceName].find((group) => group.name === groupName);
if (!existingGroup) {
throw new Error(`Group "${groupName}" not found.`);
}
const newGroupAlreadyExists = Boolean(
rulesResult[namespaceName].find((group) => group.name === newGroupName)
);
if (newGroupName !== groupName && newGroupAlreadyExists) {
throw new Error(`Group "${newGroupName}" already exists in namespace "${namespaceName}".`);
}
const newNamespaceAlreadyExists = Boolean(rulesResult[newNamespaceName]);
if (newNamespaceName !== namespaceName && newNamespaceAlreadyExists) {
throw new Error(`Namespace "${newNamespaceName}" already exists.`);
}
if (
newNamespaceName === namespaceName &&
groupName === newGroupName &&
groupInterval === existingGroup.interval
) {
throw new Error('Nothing changed.');
}
// validation for new groupInterval
if (groupInterval !== existingGroup.interval) {
const notValidRules = rulesInSameGroupHaveInvalidFor(existingGroup.rules, groupInterval ?? '1m');
if (notValidRules.length > 0) {
throw new Error(
`These alerts belonging to this group will have an invalid 'For' value: ${notValidRules
.map((rule) => {
const { alertName } = getAlertInfo(rule, groupInterval ?? '');
return alertName;
})
.join(',')}`
);
}
}
// if renaming namespace - make new copies of all groups, then delete old namespace
if (newNamespaceName !== namespaceName) {
for (const group of rulesResult[namespaceName]) {
await setRulerRuleGroup(
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
rulerConfig,
newNamespaceName,
group.name === groupName
? {
...group,
name: newGroupName,
interval: groupInterval,
}
: group
);
}
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
await deleteNamespace(rulerConfig, namespaceName);
// if only modifying group...
} else {
// save updated group
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
await setRulerRuleGroup(rulerConfig, namespaceName, {
...existingGroup,
name: newGroupName,
interval: groupInterval,
});
// if group name was changed, delete old group
if (newGroupName !== groupName) {
Alerting: Add support to distinguish Prometheus datasource subtypes (Mimir, Cortex and Vanilla Prometheus) (#46771) * Add basic UI for custom ruler URL * Add build info fetching for alerting data sources * Add keeping data sources build info in the store * Use data source build info to construct data source urls * Remove unused code * Add custom ruler support in prometheus api calls * Migrate actions * Use thunk condition to prevent multiple data source buildinfo fetches * Unify prom and ruler rules loading * Upgrade RuleEditor tests * Upgrade RuleList tests * Upgrade PanelAlertTab tests * Upgrade actions tests * Build info refactoring * Get rid of lotex ruler support action * Add prom ruler availability checking when the buildinfo is not available * Add rulerUrlBuilder tests * Improve prometheus data source validation, small build info refactoring * Change prefix based on Prometheus subtype * Use the correct path * Revert config routing * Add deprecation notice for /api/prom prefix * Add tests to the datasource subtype * Remove custom ruler support * Remove deprecation notice * Prevent fetching ruler rules when ruler api is not available * Add build info tests * Unify naming of ruler methods * Fix test * Change buildinfo data source validation * Use strings for subtype params and unveil mimir * organise imports * frontend changes and wordsmithing * fix test suite * add a nicer verbose message for prometheus datasources * detect Mimir datasource * fix test * fix buildinfo test for Mimir * shrink vectors * add some code documentation * DRY prepareRulesFilterQueryParams * clarify that Prometheus does not support managing rules * Improve buildinfo error handling Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gillesdemey <gilles.de.mey@gmail.com>
2022-04-04 12:30:17 -05:00
await deleteRulerRulesGroup(rulerConfig, namespaceName, groupName);
}
}
// refetch all rules
await thunkAPI.dispatch(fetchRulerRulesAction({ rulesSourceName }));
})()
),
{
errorMessage: 'Failed to update namespace / group',
successMessage: 'Update successful',
}
);
}
);
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
interface UpdateRulesOrderOptions {
rulesSourceName: string;
namespaceName: string;
groupName: string;
newRules: RulerRuleDTO[];
}
export const updateRulesOrder = createAsyncThunk(
'unifiedalerting/updateRulesOrderForGroup',
async (options: UpdateRulesOrderOptions, thunkAPI): Promise<void> => {
return withAppEvents(
withSerializedError(
(async () => {
const { rulesSourceName, namespaceName, groupName, newRules } = options;
const rulerConfig = getDataSourceRulerConfig(thunkAPI.getState, rulesSourceName);
const rulesResult = await fetchRulerRules(rulerConfig);
const existingGroup = rulesResult[namespaceName].find((group) => group.name === groupName);
if (!existingGroup) {
throw new Error(`Group "${groupName}" not found.`);
}
const payload: PostableRulerRuleGroupDTO = {
name: existingGroup.name,
interval: existingGroup.interval,
rules: newRules,
};
await setRulerRuleGroup(rulerConfig, namespaceName, payload);
await thunkAPI.dispatch(fetchRulerRulesAction({ rulesSourceName }));
})()
),
{
errorMessage: 'Failed to update namespace / group',
successMessage: 'Update successful',
}
);
}
);
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
export const addExternalAlertmanagersAction = createAsyncThunk(
'unifiedAlerting/addExternalAlertmanagers',
async (alertmanagerConfig: ExternalAlertmanagerConfig, thunkAPI): Promise<void> => {
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
return withAppEvents(
withSerializedError(
(async () => {
await addAlertManagers(alertmanagerConfig);
Alerting: Add external Alertmanagers (#39183) * building ui * saving alertmanager urls * add actions and api call to get external ams * add list to add modal * add validation and edit/delete * work on merging results * merging results * get color for status heart * adding tests * tests added * rename * add pollin and status * fix list sync * fix polling * add info icon with actual tooltip * fix test * Accessibility things * fix strict error * delete public/dist files * Add API tests for invalid URL * start redo admin test * Fix for empty configuration and test * remove admin test * text updates after review * suppress appevent error * fix tests * update description Co-authored-by: gotjosh <josue@grafana.com> * fix text plus go lint * updates after pr review * Adding docs * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * Update docs/sources/alerting/unified-alerting/fundamentals/alertmanager.md Co-authored-by: gotjosh <josue@grafana.com> * prettier * updates after docs feedback Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: gotjosh <josue@grafana.com>
2021-11-12 15:19:16 -06:00
thunkAPI.dispatch(fetchExternalAlertmanagersConfigAction());
})()
),
{
errorMessage: 'Failed adding alertmanagers',
successMessage: 'Alertmanagers updated',
}
);
}
);