fix(prom): return label keys from prometheus language providers (#102294)
This commit is contained in:
@@ -470,6 +470,34 @@ describe('Language completion provider', () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set `labelKeys` on language provider', async () => {
|
||||||
|
const mockQueries: PromQuery[] = [
|
||||||
|
{
|
||||||
|
refId: 'C',
|
||||||
|
expr: 'go_gc_pauses_seconds_bucket',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const fetchLabel = languageProvider.fetchLabels;
|
||||||
|
const requestSpy = jest.spyOn(languageProvider, 'request').mockResolvedValue(['foo', 'bar']);
|
||||||
|
await fetchLabel(tr, mockQueries);
|
||||||
|
expect(requestSpy).toHaveBeenCalled();
|
||||||
|
expect(languageProvider.labelKeys).toEqual(['bar', 'foo']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return labelKeys from request', async () => {
|
||||||
|
const mockQueries: PromQuery[] = [
|
||||||
|
{
|
||||||
|
refId: 'C',
|
||||||
|
expr: 'go_gc_pauses_seconds_bucket',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const fetchLabel = languageProvider.fetchLabels;
|
||||||
|
const requestSpy = jest.spyOn(languageProvider, 'request').mockResolvedValue(['foo', 'bar']);
|
||||||
|
const keys = await fetchLabel(tr, mockQueries);
|
||||||
|
expect(requestSpy).toHaveBeenCalled();
|
||||||
|
expect(keys).toEqual(['bar', 'foo']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with GET', () => {
|
describe('with GET', () => {
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
const res = await this.request(url, [], searchParams, this.getDefaultCacheHeaders());
|
const res = await this.request(url, [], searchParams, this.getDefaultCacheHeaders());
|
||||||
if (Array.isArray(res)) {
|
if (Array.isArray(res)) {
|
||||||
this.labelKeys = res.slice().sort();
|
this.labelKeys = res.slice().sort();
|
||||||
|
return res.slice().sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
Reference in New Issue
Block a user