mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #9664 from mtanda/prometheus_on_by
(prometheus) show label name in paren after by/without/on/ignoring/group_left/group_right
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user