Prometheus: Don't show errors from unsuccessful API checks like rules or exemplar checks (#52193)

The query inspector was experiencing some error pop-ups due
to errors encountered on metrics datasources configured with multiple
tenants.

e.g., team-a|team-b

This fix suppresses those errors so as to not mislead the user.
This commit is contained in:
Darren Janeczek 2022-07-21 09:45:02 -04:00 committed by GitHub
parent 5644555833
commit 565430f297
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -213,7 +213,7 @@ export class PrometheusDatasource
}
// Use this for tab completion features, wont publish response to other components
async metadataRequest<T = any>(url: string, params = {}) {
async metadataRequest<T = any>(url: string, params = {}, options?: Partial<BackendSrvRequest>) {
// If URL includes endpoint that supports POST and GET method, try to use configured method. This might fail as POST is supported only in v2.10+.
if (GET_AND_POST_METADATA_ENDPOINTS.some((endpoint) => url.includes(endpoint))) {
try {
@ -222,6 +222,7 @@ export class PrometheusDatasource
method: this.httpMethod,
hideFromInspector: true,
showErrorAlert: false,
...options,
})
);
} catch (err) {
@ -238,6 +239,7 @@ export class PrometheusDatasource
this._request<T>(`/api/datasources/${this.id}/resources${url}`, params, {
method: 'GET',
hideFromInspector: true,
...options,
})
); // toPromise until we change getTagValues, getTagKeys to Observable
}
@ -1003,7 +1005,7 @@ export class PrometheusDatasource
async loadRules() {
try {
const res = await this.metadataRequest('/api/v1/rules');
const res = await this.metadataRequest('/api/v1/rules', {}, { showErrorAlert: false });
const groups = res.data?.data?.groups;
if (groups) {
@ -1017,11 +1019,18 @@ export class PrometheusDatasource
async areExemplarsAvailable() {
try {
const res = await this.getResource('/api/v1/query_exemplars', {
query: 'test',
start: dateTime().subtract(30, 'minutes').valueOf(),
end: dateTime().valueOf(),
});
const res = await this.metadataRequest(
'/api/v1/query_exemplars',
{
query: 'test',
start: dateTime().subtract(30, 'minutes').valueOf().toString(),
end: dateTime().valueOf().toString(),
},
{
// Avoid alerting the user if this test fails
showErrorAlert: false,
}
);
if (res.data.status === 'success') {
return true;
}

View File

@ -11,6 +11,7 @@ import {
HistoryItem,
LanguageProvider,
} from '@grafana/data';
import { BackendSrvRequest } from '@grafana/runtime';
import { CompletionItem, CompletionItemGroup, SearchFunctionType, TypeaheadInput, TypeaheadOutput } from '@grafana/ui';
import { PrometheusDatasource } from './datasource';
@ -120,9 +121,9 @@ export default class PromQlLanguageProvider extends LanguageProvider {
return PromqlSyntax;
}
request = async (url: string, defaultValue: any, params = {}): Promise<any> => {
request = async (url: string, defaultValue: any, params = {}, options?: Partial<BackendSrvRequest>): Promise<any> => {
try {
const res = await this.datasource.metadataRequest(url, params);
const res = await this.datasource.metadataRequest(url, params, options);
return res.data.data;
} catch (error) {
console.error(error);
@ -145,7 +146,9 @@ export default class PromQlLanguageProvider extends LanguageProvider {
};
async loadMetricsMetadata() {
this.metricsMetadata = fixSummariesMetadata(await this.request('/api/v1/metadata', {}));
this.metricsMetadata = fixSummariesMetadata(
await this.request('/api/v1/metadata', {}, {}, { showErrorAlert: false })
);
}
getLabelKeys(): string[] {