CloudWatch: Add macro for resolving period in SEARCH expressions (#60435)

* interpolate macro in the backend

* refactor logger in cloudwatch query

* revert added metrics

* add docs

* apply pr feedback

* fix broken test

* fix spelling
This commit is contained in:
Erik Sundell
2023-01-02 09:08:31 +01:00
committed by GitHub
parent 09c759b36c
commit 6e89421544
8 changed files with 159 additions and 56 deletions

View File

@@ -66,7 +66,9 @@ describe('MetricMath: CompletionItemProvider', () => {
it('returns a suggestion for every period if the third arg of a search function', async () => {
const { query, position } = MetricMathTestData.thirdArgAfterSearchQuery;
const suggestions = await getSuggestions(query, position);
expect(suggestions.length).toEqual(METRIC_MATH_PERIODS.length);
// +1 because one suggestion is also added for the $__period_auto macro
const expectedSuggestionsLength = METRIC_MATH_PERIODS.length + 1;
expect(suggestions.length).toEqual(expectedSuggestionsLength);
});
});
});

View File

@@ -99,6 +99,11 @@ export class MetricMathCompletionItemProvider extends CompletionItemProvider {
break;
case SuggestionKind.Period:
addSuggestion('$__period_auto', {
kind: monaco.languages.CompletionItemKind.Variable,
sortText: 'a',
detail: 'Sets period dynamically to adjust to selected time range.',
});
METRIC_MATH_PERIODS.map((s, idx) =>
addSuggestion(s.toString(), {
kind: monaco.languages.CompletionItemKind.Value,

View File

@@ -77,6 +77,7 @@ export const language: monacoType.languages.IMonarchLanguage = {
root: [{ include: '@nonNestableStates' }, { include: '@strings' }],
nonNestableStates: [
{ include: '@variables' },
{ include: '@macros' },
{ include: '@whitespace' },
{ include: '@numbers' },
{ include: '@assignment' },
@@ -92,6 +93,7 @@ export const language: monacoType.languages.IMonarchLanguage = {
variables: [
[/\$[a-zA-Z0-9-_]+/, 'variable'], // $ followed by any letter/number we assume could be grafana template variable
],
macros: [[/\$__[a-zA-Z0-9-_]+/, 'type']], // example: $__period_auto
whitespace: [[/\s+/, 'white']],
assignment: [[/=/, 'tag']],
numbers: [