Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
c1919944
Unverified
Commit
c1919944
authored
May 12, 2020
by
kay delaney
Committed by
GitHub
May 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Datasource/CloudWatch: Fixes various autocomplete issues (#24583)
parent
a50cb6aa
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
24 deletions
+19
-24
packages/grafana-ui/src/slate-plugins/suggestions.tsx
+2
-2
public/app/plugins/datasource/cloudwatch/language_provider.test.ts
+6
-7
public/app/plugins/datasource/cloudwatch/language_provider.ts
+8
-10
public/app/plugins/datasource/cloudwatch/syntax.ts
+3
-5
No files found.
packages/grafana-ui/src/slate-plugins/suggestions.tsx
View file @
c1919944
...
...
@@ -295,8 +295,8 @@ const handleTypeahead = async (
}
}
// Filter out the already typed value (prefix) unless it inserts custom text
newGroup
.
items
=
newGroup
.
items
.
filter
(
c
=>
c
.
insertText
||
(
c
.
filterText
||
c
.
label
)
!==
prefix
);
// Filter out the already typed value (prefix) unless it inserts custom text
not matching the prefix
newGroup
.
items
=
newGroup
.
items
.
filter
(
c
=>
!
(
c
.
insertText
===
prefix
||
(
c
.
filterText
??
c
.
label
)
===
prefix
)
);
}
if
(
!
group
.
skipSort
)
{
...
...
public/app/plugins/datasource/cloudwatch/language_provider.test.ts
View file @
c1919944
...
...
@@ -8,11 +8,11 @@ import {
AGGREGATION_FUNCTIONS_STATS
,
BOOLEAN_FUNCTIONS
,
DATETIME_FUNCTIONS
,
FUNCTIONS
,
IP_FUNCTIONS
,
NUMERIC_OPERATORS
,
QUERY_COMMANDS
,
STRING_FUNCTIONS
,
FIELD_AND_FILTER_FUNCTIONS
,
}
from
'./syntax'
;
const
fields
=
[
'field1'
,
'@message'
];
...
...
@@ -33,19 +33,19 @@ describe('CloudWatchLanguageProvider', () => {
});
it('
should
suggest
fields
and
functions
after
field
command
', async () => {
await runSuggestionTest('
fields
\\
', [fields, FUNCTIONS.map(v => v.label)]);
await runSuggestionTest('
fields
\\
', [fields, F
IELD_AND_FILTER_F
UNCTIONS.map(v => v.label)]);
});
it('
should
suggest
fields
and
functions
after
comma
', async () => {
await runSuggestionTest('
fields
field1
,
\\
', [fields, FUNCTIONS.map(v => v.label)]);
await runSuggestionTest('
fields
field1
,
\\
', [fields, F
IELD_AND_FILTER_F
UNCTIONS.map(v => v.label)]);
});
it('
should
suggest
fields
and
functions
after
comma
with
prefix
', async () => {
await runSuggestionTest('
fields
field1
,
@
mess
\\
', [fields, FUNCTIONS.map(v => v.label)]);
await runSuggestionTest('
fields
field1
,
@
mess
\\
', [fields, F
IELD_AND_FILTER_F
UNCTIONS.map(v => v.label)]);
});
it('
should
suggest
fields
and
functions
after
display
command
', async () => {
await runSuggestionTest('
display
\\
', [fields, FUNCTIONS.map(v => v.label)]);
await runSuggestionTest('
display
\\
', [fields, F
IELD_AND_FILTER_F
UNCTIONS.map(v => v.label)]);
});
it('
should
suggest
functions
after
stats
command
', async () => {
...
...
@@ -62,8 +62,7 @@ describe('CloudWatchLanguageProvider', () => {
it('
should
suggest
fields
and
some
functions
after
comparison
operator
', async () => {
await runSuggestionTest('
filter
field1
>=
\\
', [
fields,
BOOLEAN_FUNCTIONS.map(v => v.label),
NUMERIC_OPERATORS.map(v => v.label),
[...NUMERIC_OPERATORS.map(v => v.label), ...BOOLEAN_FUNCTIONS.map(v => v.label)],
]);
});
...
...
public/app/plugins/datasource/cloudwatch/language_provider.ts
View file @
c1919944
...
...
@@ -4,13 +4,13 @@ import _ from 'lodash';
// Services & Utils
import
syntax
,
{
QUERY_COMMANDS
,
FUNCTIONS
,
AGGREGATION_FUNCTIONS_STATS
,
STRING_FUNCTIONS
,
DATETIME_FUNCTIONS
,
IP_FUNCTIONS
,
BOOLEAN_FUNCTIONS
,
NUMERIC_OPERATORS
,
FIELD_AND_FILTER_FUNCTIONS
,
}
from
'./syntax'
;
// Types
...
...
@@ -210,7 +210,7 @@ export class CloudWatchLanguageProvider extends LanguageProvider {
if
([
'display'
,
'fields'
].
includes
(
queryCommand
))
{
const
typeaheadOutput
=
await
this
.
getFieldCompletionItems
(
context
.
logGroupNames
??
[]);
typeaheadOutput
.
suggestions
.
push
(...
this
.
getFunctionCompletionItems
().
suggestions
);
typeaheadOutput
.
suggestions
.
push
(...
this
.
getF
ieldAndFilterF
unctionCompletionItems
().
suggestions
);
return
typeaheadOutput
;
}
...
...
@@ -264,10 +264,8 @@ export class CloudWatchLanguageProvider extends LanguageProvider {
private
handleComparison
=
async
(
context
?:
TypeaheadContext
)
=>
{
const
fieldsSuggestions
=
await
this
.
getFieldCompletionItems
(
context
?.
logGroupNames
??
[]);
const
boolFuncSuggestions
=
this
.
getBoolFuncCompletionItems
();
const
numFuncSuggestions
=
this
.
getNumericFuncCompletionItems
();
fieldsSuggestions
.
suggestions
.
push
(...
boolFuncSuggestions
.
suggestions
,
...
numFuncSuggestions
.
suggestions
);
const
comparisonSuggestions
=
this
.
getComparisonCompletionItems
();
fieldsSuggestions
.
suggestions
.
push
(...
comparisonSuggestions
.
suggestions
);
return
fieldsSuggestions
;
};
...
...
@@ -275,8 +273,8 @@ export class CloudWatchLanguageProvider extends LanguageProvider {
return
{
suggestions
:
[{
prefixMatch
:
true
,
label
:
'Commands'
,
items
:
QUERY_COMMANDS
}]
};
};
private
getFunctionCompletionItems
=
():
TypeaheadOutput
=>
{
return
{
suggestions
:
[{
prefixMatch
:
true
,
label
:
'Functions'
,
items
:
FUNCTIONS
}]
};
private
getF
ieldAndFilterF
unctionCompletionItems
=
():
TypeaheadOutput
=>
{
return
{
suggestions
:
[{
prefixMatch
:
true
,
label
:
'Functions'
,
items
:
F
IELD_AND_FILTER_F
UNCTIONS
}]
};
};
private
getStatsAggCompletionItems
=
():
TypeaheadOutput
=>
{
...
...
@@ -295,13 +293,13 @@ export class CloudWatchLanguageProvider extends LanguageProvider {
};
};
private
get
NumericFunc
CompletionItems
=
():
TypeaheadOutput
=>
{
private
get
Comparison
CompletionItems
=
():
TypeaheadOutput
=>
{
return
{
suggestions
:
[
{
prefixMatch
:
true
,
label
:
'Functions'
,
items
:
NUMERIC_OPERATORS
,
items
:
NUMERIC_OPERATORS
.
concat
(
BOOLEAN_FUNCTIONS
)
,
},
],
};
...
...
public/app/plugins/datasource/cloudwatch/syntax.ts
View file @
c1919944
...
...
@@ -9,12 +9,10 @@ export const QUERY_COMMANDS: CompletionItem[] = [
{
label
:
'display'
,
documentation
:
'Specifies which fields to display in the query results'
},
{
label
:
'filter'
,
insertText
:
'filter'
,
documentation
:
'Filters the results of a query based on one or more conditions'
,
},
{
label
:
'stats'
,
insertText
:
'stats'
,
documentation
:
'Calculates aggregate statistics based on the values of log fields'
,
},
{
label
:
'sort'
,
documentation
:
'Sorts the retrieved log events'
},
...
...
@@ -205,7 +203,6 @@ export const IP_FUNCTIONS = [
},
{
label
:
'isIpv6InSubnet'
,
insertText
:
'isIpv6InSubnet'
,
detail
:
'isIpv6InSubnet(fieldname, string)'
,
documentation
:
'Returns true if the field is a valid v6 IP address within the specified v6 subnet.'
,
},
...
...
@@ -306,15 +303,16 @@ export const NON_AGGREGATION_FUNCS_STATS = [
export
const
STATS_FUNCS
=
[...
AGGREGATION_FUNCTIONS_STATS
,
...
NON_AGGREGATION_FUNCS_STATS
];
export
const
KEYWORDS
=
[
'as'
,
'like'
,
'by'
,
'in'
,
'desc'
,
'asc'
];
export
const
FUNCTIONS
=
[
export
const
F
IELD_AND_FILTER_F
UNCTIONS
=
[
...
NUMERIC_OPERATORS
,
...
GENERAL_FUNCTIONS
,
...
STRING_FUNCTIONS
,
...
DATETIME_FUNCTIONS
,
...
IP_FUNCTIONS
,
...
STATS_FUNCS
,
];
export
const
FUNCTIONS
=
[...
FIELD_AND_FILTER_FUNCTIONS
,
...
STATS_FUNCS
];
const
tokenizer
:
Grammar
=
{
comment
:
{
pattern
:
/^#.*/
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment