mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user