* added regex check of labelKeys
- labelKeys should not contain any special characters
- added encoding of labelKeys in the URL
- don't offer autocomplete if label with special characters is detected
* removed additional regex check for labels
(cherry picked from commit d7139e75fb)
Co-authored-by: svennergr <Svennergr@gmail.com>
This commit is contained in:
co-authored by
svennergr
parent
3422f70f66
commit
afec2786fc
@@ -248,6 +248,15 @@ describe('Language completion provider', () => {
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
expect(nextLabelValues).toEqual(['label1_val1', 'label1_val2']);
|
||||
});
|
||||
|
||||
it('should encode special characters', async () => {
|
||||
const datasource = makeMockLokiDatasource({ '`\\"testkey': ['label1_val1', 'label1_val2'], label2: [] });
|
||||
const provider = await getLanguageProvider(datasource);
|
||||
const requestSpy = jest.spyOn(provider, 'request');
|
||||
await provider.fetchLabelValues('`\\"testkey');
|
||||
|
||||
expect(requestSpy).toHaveBeenCalledWith('label/%60%5C%22testkey/values', expect.any(Object));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -439,7 +439,8 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
}
|
||||
|
||||
async fetchLabelValues(key: string): Promise<string[]> {
|
||||
const interpolatedKey = this.datasource.interpolateString(key);
|
||||
const interpolatedKey = encodeURIComponent(this.datasource.interpolateString(key));
|
||||
|
||||
const url = `label/${interpolatedKey}/values`;
|
||||
const rangeParams = this.datasource.getTimeRangeParams();
|
||||
const { start, end } = rangeParams;
|
||||
|
||||
@@ -18,7 +18,8 @@ interface SeriesForSelector {
|
||||
}
|
||||
|
||||
export function makeMockLokiDatasource(labelsAndValues: Labels, series?: SeriesForSelector): LokiDatasource {
|
||||
const lokiLabelsAndValuesEndpointRegex = /^label\/(\w*)\/values/;
|
||||
// added % to allow urlencoded labelKeys. Note, that this is not confirm with Loki, as loki does not allow specialcharacters in labelKeys, but needed for tests.
|
||||
const lokiLabelsAndValuesEndpointRegex = /^label\/([%\w]*)\/values/;
|
||||
const lokiSeriesEndpointRegex = /^series/;
|
||||
|
||||
const lokiLabelsEndpoint = 'labels';
|
||||
|
||||
Reference in New Issue
Block a user