Commit b778b535 by David Kaltschmidt

Explore: swtiching to logging should keep prometheus labels in case of error

Logging's query importer drops all labels that are not common to both datasources.

- keep labels if label lookup of logging datasource came back empty
- easier to remove labels than having to add them in the first place
parent 56d95e79
...@@ -95,5 +95,14 @@ describe('Query imports', () => { ...@@ -95,5 +95,14 @@ describe('Query imports', () => {
const result = await instance.importPrometheusQuery('metric{foo="bar",baz="42"}'); const result = await instance.importPrometheusQuery('metric{foo="bar",baz="42"}');
expect(result).toEqual('{foo="bar"}'); expect(result).toEqual('{foo="bar"}');
}); });
it('returns selector query from selector query with all labels if logging label list is empty', async () => {
const datasourceWithLabels = {
metadataRequest: url => (url === '/api/prom/label' ? { data: { data: [] } } : { data: { data: [] } }),
};
const instance = new LanguageProvider(datasourceWithLabels);
const result = await instance.importPrometheusQuery('metric{foo="bar",baz="42"}');
expect(result).toEqual('{baz="42",foo="bar"}');
});
}); });
}); });
...@@ -194,17 +194,24 @@ export default class LoggingLanguageProvider extends LanguageProvider { ...@@ -194,17 +194,24 @@ export default class LoggingLanguageProvider extends LanguageProvider {
// Keep only labels that exist on origin and target datasource // Keep only labels that exist on origin and target datasource
await this.start(); // fetches all existing label keys await this.start(); // fetches all existing label keys
const commonLabels = {}; const existingKeys = this.labelKeys[EMPTY_SELECTOR];
for (const key in labels) { let labelsToKeep = {};
const existingKeys = this.labelKeys[EMPTY_SELECTOR]; if (existingKeys && existingKeys.length > 0) {
if (existingKeys && existingKeys.indexOf(key) > -1) { // Check for common labels
// Should we check for label value equality here? for (const key in labels) {
commonLabels[key] = labels[key]; if (existingKeys && existingKeys.indexOf(key) > -1) {
// Should we check for label value equality here?
labelsToKeep[key] = labels[key];
}
} }
} else {
// Keep all labels by default
labelsToKeep = labels;
} }
const labelKeys = Object.keys(commonLabels).sort();
const labelKeys = Object.keys(labelsToKeep).sort();
const cleanSelector = labelKeys const cleanSelector = labelKeys
.map(key => `${key}${commonLabels[key].operator}${commonLabels[key].value}`) .map(key => `${key}${labelsToKeep[key].operator}${labelsToKeep[key].value}`)
.join(','); .join(',');
return ['{', cleanSelector, '}'].join(''); return ['{', cleanSelector, '}'].join('');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment