mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
5644555833
commit
565430f297
@ -213,7 +213,7 @@ export class PrometheusDatasource
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use this for tab completion features, wont publish response to other components
|
// 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 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))) {
|
if (GET_AND_POST_METADATA_ENDPOINTS.some((endpoint) => url.includes(endpoint))) {
|
||||||
try {
|
try {
|
||||||
@ -222,6 +222,7 @@ export class PrometheusDatasource
|
|||||||
method: this.httpMethod,
|
method: this.httpMethod,
|
||||||
hideFromInspector: true,
|
hideFromInspector: true,
|
||||||
showErrorAlert: false,
|
showErrorAlert: false,
|
||||||
|
...options,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -238,6 +239,7 @@ export class PrometheusDatasource
|
|||||||
this._request<T>(`/api/datasources/${this.id}/resources${url}`, params, {
|
this._request<T>(`/api/datasources/${this.id}/resources${url}`, params, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
hideFromInspector: true,
|
hideFromInspector: true,
|
||||||
|
...options,
|
||||||
})
|
})
|
||||||
); // toPromise until we change getTagValues, getTagKeys to Observable
|
); // toPromise until we change getTagValues, getTagKeys to Observable
|
||||||
}
|
}
|
||||||
@ -1003,7 +1005,7 @@ export class PrometheusDatasource
|
|||||||
|
|
||||||
async loadRules() {
|
async loadRules() {
|
||||||
try {
|
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;
|
const groups = res.data?.data?.groups;
|
||||||
|
|
||||||
if (groups) {
|
if (groups) {
|
||||||
@ -1017,11 +1019,18 @@ export class PrometheusDatasource
|
|||||||
|
|
||||||
async areExemplarsAvailable() {
|
async areExemplarsAvailable() {
|
||||||
try {
|
try {
|
||||||
const res = await this.getResource('/api/v1/query_exemplars', {
|
const res = await this.metadataRequest(
|
||||||
query: 'test',
|
'/api/v1/query_exemplars',
|
||||||
start: dateTime().subtract(30, 'minutes').valueOf(),
|
{
|
||||||
end: dateTime().valueOf(),
|
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') {
|
if (res.data.status === 'success') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
HistoryItem,
|
HistoryItem,
|
||||||
LanguageProvider,
|
LanguageProvider,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
import { BackendSrvRequest } from '@grafana/runtime';
|
||||||
import { CompletionItem, CompletionItemGroup, SearchFunctionType, TypeaheadInput, TypeaheadOutput } from '@grafana/ui';
|
import { CompletionItem, CompletionItemGroup, SearchFunctionType, TypeaheadInput, TypeaheadOutput } from '@grafana/ui';
|
||||||
|
|
||||||
import { PrometheusDatasource } from './datasource';
|
import { PrometheusDatasource } from './datasource';
|
||||||
@ -120,9 +121,9 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
return PromqlSyntax;
|
return PromqlSyntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
request = async (url: string, defaultValue: any, params = {}): Promise<any> => {
|
request = async (url: string, defaultValue: any, params = {}, options?: Partial<BackendSrvRequest>): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
const res = await this.datasource.metadataRequest(url, params);
|
const res = await this.datasource.metadataRequest(url, params, options);
|
||||||
return res.data.data;
|
return res.data.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -145,7 +146,9 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async loadMetricsMetadata() {
|
async loadMetricsMetadata() {
|
||||||
this.metricsMetadata = fixSummariesMetadata(await this.request('/api/v1/metadata', {}));
|
this.metricsMetadata = fixSummariesMetadata(
|
||||||
|
await this.request('/api/v1/metadata', {}, {}, { showErrorAlert: false })
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLabelKeys(): string[] {
|
getLabelKeys(): string[] {
|
||||||
|
Loading…
Reference in New Issue
Block a user