Prometheus: Don't use match[] parameter if there is no metric (#89352)

don't use match[] parameter if there is no metric
This commit is contained in:
ismail simsek 2024-06-19 08:19:49 +02:00 committed by GitHub
parent a5e02f033a
commit 76047d9365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -505,6 +505,20 @@ describe('Language completion provider', () => {
)
);
});
it('should dont send match[] parameter if there is no metric', async () => {
const mockQueries: PromQuery[] = [
{
refId: 'A',
expr: '',
},
];
const fetchLabel = languageProvider.fetchLabels;
const requestSpy = jest.spyOn(languageProvider, 'request');
await fetchLabel(tr, mockQueries);
expect(requestSpy).toHaveBeenCalled();
expect(requestSpy.mock.calls[0][0].indexOf('match[]')).toEqual(-1);
});
});
});

View File

@ -219,12 +219,14 @@ export default class PromQlLanguageProvider extends LanguageProvider {
const searchParams = new URLSearchParams({ ...timeParams });
queries?.forEach((q) => {
const visualQuery = buildVisualQueryFromString(q.expr);
if (visualQuery.query.metric !== '') {
searchParams.append('match[]', visualQuery.query.metric);
if (visualQuery.query.binaryQueries) {
visualQuery.query.binaryQueries.forEach((bq) => {
searchParams.append('match[]', bq.query.metric);
});
}
}
});
if (this.datasource.httpMethod === 'GET') {