mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
Address PromQL autocomplete review feedback
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
This commit is contained in:
parent
7c6bab8c58
commit
0254e010b3
2 changed files with 8 additions and 3 deletions
|
|
@ -1569,11 +1569,13 @@ describe('autocomplete promQL test', () => {
|
|||
type: 'text',
|
||||
},
|
||||
{
|
||||
label: '\\\\x2d',
|
||||
label: '\\x2d',
|
||||
apply: '\\\\x2d',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
label: 'quoted\\"value',
|
||||
label: 'quoted"value',
|
||||
apply: 'quoted\\"value',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -169,6 +169,9 @@ function arrayToCompletionResult(data: Completion[], from: number, to: number, i
|
|||
}
|
||||
|
||||
function escapePromQLString(str: string): string {
|
||||
// PromQL only evaluates escape sequences in single- and double-quoted strings.
|
||||
// Backtick-quoted string completions are not handled separately today, so keep
|
||||
// the inserted value escaped unconditionally.
|
||||
return str.replace(/([\\"])/g, '\\$1');
|
||||
}
|
||||
|
||||
|
|
@ -798,7 +801,7 @@ export class HybridComplete implements CompleteStrategy {
|
|||
return result;
|
||||
}
|
||||
return this.prometheusClient.labelValues(context.labelName, context.metricName, context.matchers).then((labelValues: string[]) => {
|
||||
return result.concat(labelValues.map((value) => ({ label: escapePromQLString(value), type: 'text' })));
|
||||
return result.concat(labelValues.map((value) => ({ label: value, apply: escapePromQLString(value), type: 'text' })));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue