Alerting: remove error banner when Prometheus ruler is not supported (#44571)

This commit is contained in:
Roy C 2022-02-08 12:03:14 -08:00 committed by GitHub
parent 6a2255abe7
commit 3d0cff5410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 14 deletions

View File

@ -107,15 +107,8 @@ async function rulerGetRequest<T>(url: string, empty: T, params?: Record<string,
throw error;
}
const notFoundError = error.status === 404;
if (notFoundError) {
// the endpoint will return 404 but confirm that it's a Cortex endpoint
if (isCortexErrorResponse(error)) {
return empty;
}
// any other 404 should throw an exception
throw new Error('404 from rules config endpoint. Perhaps ruler API is not enabled?');
if (isCortexErrorResponse(error)) {
return empty;
} else if (isRulerNotSupported(error)) {
// assert if the endoint is not supported at all
throw {
@ -138,13 +131,17 @@ function isResponseError(error: unknown): error is FetchResponse<ErrorResponseMe
function isRulerNotSupported(error: FetchResponse<ErrorResponseMessage>) {
return (
error.status === 500 &&
error.data.message?.includes('unexpected content type from upstream. expected YAML, got text/html')
error.status === 404 ||
(error.status === 500 &&
error.data.message?.includes('unexpected content type from upstream. expected YAML, got text/html'))
);
}
function isCortexErrorResponse(error: FetchResponse<ErrorResponseMessage>) {
return error.data.message?.includes('group does not exist') || error.data.message?.includes('no rule groups found');
return (
error.status === 404 &&
(error.data.message?.includes('group does not exist') || error.data.message?.includes('no rule groups found'))
);
}
export async function deleteNamespace(dataSourceName: string, namespace: string): Promise<void> {

View File

@ -66,6 +66,7 @@ import { addDefaultsToAlertmanagerConfig, removeMuteTimingFromRoute, isFetchErro
import * as ruleId from '../utils/rule-id';
import { isEmpty } from 'lodash';
import messageFromError from 'app/plugins/datasource/grafana-azure-monitor-datasource/utils/messageFromError';
import { RULER_NOT_SUPPORTED_MSG } from '../utils/constants';
const FETCH_CONFIG_RETRY_TIMEOUT = 30 * 1000;
@ -636,7 +637,8 @@ export const checkIfLotexSupportsEditingRulesAction = createAsyncThunk<boolean,
(isFetchError(e) &&
(e.data.message?.includes('GetRuleGroup unsupported in rule local store') || // "local" rule storage
e.data.message?.includes('page not found'))) || // ruler api disabled
e.message?.includes('404 from rules config endpoint') // ruler api disabled
e.message?.includes('404 from rules config endpoint') || // ruler api disabled
e.data.message?.includes(RULER_NOT_SUPPORTED_MSG) // ruler api not supported
) {
return false;
}

View File

@ -50,7 +50,7 @@ export function alertInstanceKey(alert: Alert): string {
}
export function isRulerNotSupportedResponse(resp: AsyncRequestState<any>) {
return resp.error && resp.error?.message === RULER_NOT_SUPPORTED_MSG;
return resp.error && resp.error?.message?.includes(RULER_NOT_SUPPORTED_MSG);
}
export function isGrafanaRuleIdentifier(identifier: RuleIdentifier): identifier is GrafanaRuleIdentifier {