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
e3274d67
Commit
e3274d67
authored
Oct 25, 2017
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(prometheus) show label name in paren after by/without/on/ignoring/group_left/group_right
parent
24723cdb
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
30 deletions
+103
-30
public/app/plugins/datasource/prometheus/completer.ts
+0
-0
public/app/plugins/datasource/prometheus/mode-prometheus.js
+34
-12
public/app/plugins/datasource/prometheus/specs/completer_specs.ts
+69
-18
No files found.
public/app/plugins/datasource/prometheus/completer.ts
View file @
e3274d67
This diff is collapsed.
Click to expand it.
public/app/plugins/datasource/prometheus/mode-prometheus.js
View file @
e3274d67
...
...
@@ -8,7 +8,6 @@ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var
PrometheusHighlightRules
=
function
()
{
var
keywords
=
(
"by|without|keep_common|offset|bool|and|or|unless|ignoring|on|group_left|group_right|"
+
"count|count_values|min|max|avg|sum|stddev|stdvar|bottomk|topk|quantile"
);
...
...
@@ -42,44 +41,65 @@ var PrometheusHighlightRules = function() {
token
:
"constant.language"
,
// time
regex
:
"
\\
d+[smhdwy]"
},
{
token
:
"keyword.operator.binary"
,
regex
:
"
\\
+|
\\
-|
\\
*|
\\
/|%|
\\
^|==|!=|<=|>=|<|>|and|or|unless"
},
{
token
:
"keyword.other"
,
regex
:
"keep_common|offset|bool"
},
{
token
:
"keyword.control"
,
regex
:
"by|without|on|ignoring|group_left|group_right"
,
next
:
"start-label-list-matcher"
},
{
token
:
keywordMapper
,
regex
:
"[a-zA-Z_:][a-zA-Z0-9_:]*"
},
{
token
:
"keyword.operator"
,
regex
:
"
\\
+|
\\
-|
\\
*|
\\
/|%|
\\
^|==|!=|<=|>=|<|>"
},
{
token
:
"paren.lparen"
,
regex
:
"[[(]"
},
{
token
:
"paren.lparen"
,
token
:
"paren.lparen
.label-matcher
"
,
regex
:
"{"
,
next
:
"start-label-matcher"
},
{
token
:
"paren.rparen"
,
regex
:
"[
\\
])]"
},
{
token
:
"paren.rparen"
,
token
:
"paren.rparen
.label-matcher
"
,
regex
:
"}"
},
{
token
:
"text"
,
regex
:
"
\\
s+"
}
],
"start-label-matcher"
:
[
{
token
:
"entity.name.tag"
,
token
:
"entity.name.tag
.label-matcher
"
,
regex
:
'[a-zA-Z_][a-zA-Z0-9_]*'
},
{
token
:
"keyword.operator"
,
token
:
"keyword.operator
.label-matcher
"
,
regex
:
'=~|=|!~|!='
},
{
token
:
"string.quoted"
,
token
:
"string.quoted
.label-matcher
"
,
regex
:
'"[^"]*"|
\'
[^
\'
]*
\'
'
},
{
token
:
"punctuation.operator"
,
token
:
"punctuation.operator
.label-matcher
"
,
regex
:
","
},
{
token
:
"paren.rparen"
,
token
:
"paren.rparen
.label-matcher
"
,
regex
:
"}"
,
next
:
"start"
}
],
"start-label-list-matcher"
:
[
{
token
:
"paren.lparen.label-list-matcher"
,
regex
:
"[(]"
},
{
token
:
"entity.name.tag.label-list-matcher"
,
regex
:
'[a-zA-Z_][a-zA-Z0-9_]*'
},
{
token
:
"punctuation.operator.label-list-matcher"
,
regex
:
","
},
{
token
:
"paren.rparen.label-list-matcher"
,
regex
:
"[)]"
,
next
:
"start"
}
]
};
...
...
@@ -395,7 +415,9 @@ var PrometheusCompletions = function() {};
(
function
()
{
this
.
getCompletions
=
function
(
state
,
session
,
pos
,
prefix
,
callback
)
{
var
token
=
session
.
getTokenAt
(
pos
.
row
,
pos
.
column
);
if
(
token
.
type
===
'entity.name.tag'
||
token
.
type
===
'string.quoted'
)
{
if
(
token
.
type
===
'entity.name.tag.label-matcher'
||
token
.
type
===
'string.quoted.label-matcher'
||
token
.
type
===
'entity.name.tag.label-list-matcher'
)
{
return
callback
(
null
,
[]);
}
...
...
public/app/plugins/datasource/prometheus/specs/completer_specs.ts
View file @
e3274d67
...
...
@@ -61,16 +61,21 @@ describe('Prometheus editor completer', function() {
it
(
'Should return label name list'
,
()
=>
{
const
session
=
getSessionStub
({
currentToken
:
{
type
:
'entity.name.tag'
,
type
:
'entity.name.tag
.label-matcher
'
,
value
:
'j'
,
index
:
2
,
start
:
9
,
},
tokens
:
[
{
type
:
'identifier'
,
value
:
'node_cpu'
},
{
type
:
'paren.lparen'
,
value
:
'{'
},
{
type
:
'entity.name.tag'
,
value
:
'j'
,
index
:
2
,
start
:
9
},
{
type
:
'paren.rparen'
,
value
:
'}'
},
{
type
:
'paren.lparen.label-matcher'
,
value
:
'{'
},
{
type
:
'entity.name.tag.label-matcher'
,
value
:
'j'
,
index
:
2
,
start
:
9
,
},
{
type
:
'paren.rparen.label-matcher'
,
value
:
'}'
},
],
line
:
'node_cpu{j}'
,
});
...
...
@@ -85,19 +90,24 @@ describe('Prometheus editor completer', function() {
it
(
'Should return label name list'
,
()
=>
{
const
session
=
getSessionStub
({
currentToken
:
{
type
:
'entity.name.tag'
,
type
:
'entity.name.tag
.label-matcher
'
,
value
:
'j'
,
index
:
5
,
start
:
22
,
},
tokens
:
[
{
type
:
'paren.lparen'
,
value
:
'{'
},
{
type
:
'entity.name.tag'
,
value
:
'__name__'
},
{
type
:
'keyword.operator'
,
value
:
'=~'
},
{
type
:
'string.quoted'
,
value
:
'"node_cpu"'
},
{
type
:
'punctuation.operator'
,
value
:
','
},
{
type
:
'entity.name.tag'
,
value
:
'j'
,
index
:
5
,
start
:
22
},
{
type
:
'paren.rparen'
,
value
:
'}'
},
{
type
:
'paren.lparen.label-matcher'
,
value
:
'{'
},
{
type
:
'entity.name.tag.label-matcher'
,
value
:
'__name__'
},
{
type
:
'keyword.operator.label-matcher'
,
value
:
'=~'
},
{
type
:
'string.quoted.label-matcher'
,
value
:
'"node_cpu"'
},
{
type
:
'punctuation.operator.label-matcher'
,
value
:
','
},
{
type
:
'entity.name.tag.label-matcher'
,
value
:
'j'
,
index
:
5
,
start
:
22
,
},
{
type
:
'paren.rparen.label-matcher'
,
value
:
'}'
},
],
line
:
'{__name__=~"node_cpu",j}'
,
});
...
...
@@ -112,18 +122,23 @@ describe('Prometheus editor completer', function() {
it
(
'Should return label value list'
,
()
=>
{
const
session
=
getSessionStub
({
currentToken
:
{
type
:
'string.quoted'
,
type
:
'string.quoted
.label-matcher
'
,
value
:
'"n"'
,
index
:
4
,
start
:
13
,
},
tokens
:
[
{
type
:
'identifier'
,
value
:
'node_cpu'
},
{
type
:
'paren.lparen'
,
value
:
'{'
},
{
type
:
'entity.name.tag'
,
value
:
'job'
},
{
type
:
'keyword.operator'
,
value
:
'='
},
{
type
:
'string.quoted'
,
value
:
'"n"'
,
index
:
4
,
start
:
13
},
{
type
:
'paren.rparen'
,
value
:
'}'
},
{
type
:
'paren.lparen.label-matcher'
,
value
:
'{'
},
{
type
:
'entity.name.tag.label-matcher'
,
value
:
'job'
},
{
type
:
'keyword.operator.label-matcher'
,
value
:
'='
},
{
type
:
'string.quoted.label-matcher'
,
value
:
'"n"'
,
index
:
4
,
start
:
13
,
},
{
type
:
'paren.rparen.label-matcher'
,
value
:
'}'
},
],
line
:
'node_cpu{job="n"}'
,
});
...
...
@@ -133,4 +148,40 @@ describe('Prometheus editor completer', function() {
});
});
});
describe
(
'When inside by'
,
()
=>
{
it
(
'Should return label name list'
,
()
=>
{
const
session
=
getSessionStub
({
currentToken
:
{
type
:
'entity.name.tag.label-list-matcher'
,
value
:
'm'
,
index
:
9
,
start
:
22
,
},
tokens
:
[
{
type
:
'paren.lparen'
,
value
:
'('
},
{
type
:
'keyword'
,
value
:
'count'
},
{
type
:
'paren.lparen'
,
value
:
'('
},
{
type
:
'identifier'
,
value
:
'node_cpu'
},
{
type
:
'paren.rparen'
,
value
:
'))'
},
{
type
:
'text'
,
value
:
' '
},
{
type
:
'keyword.control'
,
value
:
'by'
},
{
type
:
'text'
,
value
:
' '
},
{
type
:
'paren.lparen.label-list-matcher'
,
value
:
'('
},
{
type
:
'entity.name.tag.label-list-matcher'
,
value
:
'm'
,
index
:
9
,
start
:
22
,
},
{
type
:
'paren.rparen.label-list-matcher'
,
value
:
')'
},
],
line
:
'(count(node_cpu)) by (m)'
,
});
return
completer
.
getCompletions
(
editor
,
session
,
{
row
:
0
,
column
:
23
},
'm'
,
(
s
,
res
)
=>
{
expect
(
res
[
0
].
meta
).
to
.
eql
(
'label name'
);
});
});
});
});
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