Skip to content

Commit

Permalink
Alerting: remove error banner when Prometheus ruler is not supported (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
roystchiang committed Feb 8, 2022
1 parent 6a2255a commit 3d0cff5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
21 changes: 9 additions & 12 deletions public/app/features/alerting/unified/api/ruler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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> {
Expand Down
4 changes: 3 additions & 1 deletion public/app/features/alerting/unified/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion public/app/features/alerting/unified/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3d0cff5

Please sign in to comment.