Loki: don't send empty vector selector to /labels API (#98547)

* fix: don't send empty vector selector to /labels API
This commit is contained in:
Galen Kistler 2025-01-06 14:07:15 -06:00 committed by GitHub
parent 09c4543d11
commit 3ba0cd23c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -461,6 +461,15 @@ describe('Language completion provider', () => {
config.featureToggles.lokiLabelNamesQueryApi = lokiLabelNamesQueryApi;
});
it('should exclude empty vector selector', async () => {
const datasourceWithLabels = setup({ foo: [], bar: [], __name__: [], __stream_shard__: [] });
const instance = new LanguageProvider(datasourceWithLabels);
instance.request = jest.fn();
await instance.fetchLabels({ streamSelector: '{}' });
expect(instance.request).toBeCalledWith('labels', { end: 1560163909000, start: 1560153109000 });
});
it('should use series endpoint for request with stream selector', async () => {
const datasourceWithLabels = setup({});
datasourceWithLabels.languageProvider.request = jest.fn();

View File

@ -174,7 +174,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
const range = options?.timeRange ?? this.getDefaultTimeRange();
const { start, end } = this.datasource.getTimeRangeParams(range);
const params: Record<string, string | number> = { start, end };
if (options?.streamSelector) {
if (options?.streamSelector && options?.streamSelector !== EMPTY_SELECTOR) {
params['query'] = options.streamSelector;
}
const res = await this.request(url, params);