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
bfd05ba6
Unverified
Commit
bfd05ba6
authored
Jul 18, 2018
by
David
Committed by
GitHub
Jul 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12617 from grafana/davkal/prometheus-value-formatting
Make prometheus value formatting more robust
parents
e413f026
1f74b298
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
22 deletions
+31
-22
public/app/features/panel/metrics_panel_ctrl.ts
+1
-1
public/app/plugins/datasource/prometheus/datasource.ts
+9
-3
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
+3
-0
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
+18
-18
No files found.
public/app/features/panel/metrics_panel_ctrl.ts
View file @
bfd05ba6
...
...
@@ -222,7 +222,7 @@ class MetricsPanelCtrl extends PanelCtrl {
// and add built in variables interval and interval_ms
var
scopedVars
=
Object
.
assign
({},
this
.
panel
.
scopedVars
,
{
__interval
:
{
text
:
this
.
interval
,
value
:
this
.
interval
},
__interval_ms
:
{
text
:
String
(
this
.
intervalMs
),
value
:
String
(
this
.
intervalMs
)
},
__interval_ms
:
{
text
:
this
.
intervalMs
,
value
:
this
.
intervalMs
},
});
var
metricsQuery
=
{
...
...
public/app/plugins/datasource/prometheus/datasource.ts
View file @
bfd05ba6
...
...
@@ -17,11 +17,17 @@ export function alignRange(start, end, step) {
}
export
function
prometheusRegularEscape
(
value
)
{
return
value
.
replace
(
/'/g
,
"
\\\\
'"
);
if
(
typeof
value
===
'string'
)
{
return
value
.
replace
(
/'/g
,
"
\\\\
'"
);
}
return
value
;
}
export
function
prometheusSpecialRegexEscape
(
value
)
{
return
prometheusRegularEscape
(
value
.
replace
(
/
\\
/g
,
'
\\\\\\\
\'
).replace(/[$^*{}
\
[
\
]+?.()]/g, '
\\\\
$
&
'));
if
(
typeof
value
===
'string'
)
{
return
prometheusRegularEscape
(
value
.
replace
(
/
\\
/g
,
'
\\\\\\\
\'
).replace(/[$^*{}
\
[
\
]+?.()]/g, '
\\\\
$
&
'));
}
return value;
}
export class PrometheusDatasource {
...
...
@@ -196,7 +202,7 @@ export class PrometheusDatasource {
interval = adjustedInterval;
scopedVars = Object.assign({}, options.scopedVars, {
__interval: { text: interval + '
s
', value: interval + '
s
' },
__interval_ms: { text:
String(interval * 1000), value: String(interval * 1000)
},
__interval_ms: { text:
interval * 1000, value: interval * 1000
},
});
}
query.step = interval;
...
...
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
View file @
bfd05ba6
...
...
@@ -166,6 +166,9 @@ describe('PrometheusDatasource', () => {
});
describe
(
'Prometheus regular escaping'
,
function
()
{
it
(
'should not escape non-string'
,
function
()
{
expect
(
prometheusRegularEscape
(
12
)).
toEqual
(
12
);
});
it
(
'should not escape simple string'
,
function
()
{
expect
(
prometheusRegularEscape
(
'cryptodepression'
)).
toEqual
(
'cryptodepression'
);
});
...
...
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
View file @
bfd05ba6
...
...
@@ -452,7 +452,7 @@ describe('PrometheusDatasource', function() {
interval
:
'10s'
,
scopedVars
:
{
__interval
:
{
text
:
'10s'
,
value
:
'10s'
},
__interval_ms
:
{
text
:
String
(
10
*
1000
),
value
:
String
(
10
*
1000
)
},
__interval_ms
:
{
text
:
10
*
1000
,
value
:
10
*
1000
},
},
};
var
urlExpected
=
...
...
@@ -463,8 +463,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
String
(
10
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
10
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
10
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
10
*
1000
);
});
it
(
'should be min interval when it is greater than auto interval'
,
function
()
{
var
query
=
{
...
...
@@ -479,7 +479,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__interval_ms
:
{
text
:
String
(
5
*
1000
),
value
:
String
(
5
*
1000
)
},
__interval_ms
:
{
text
:
5
*
1000
,
value
:
5
*
1000
},
},
};
var
urlExpected
=
...
...
@@ -490,8 +490,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
it
(
'should account for intervalFactor'
,
function
()
{
var
query
=
{
...
...
@@ -507,7 +507,7 @@ describe('PrometheusDatasource', function() {
interval
:
'10s'
,
scopedVars
:
{
__interval
:
{
text
:
'10s'
,
value
:
'10s'
},
__interval_ms
:
{
text
:
String
(
10
*
1000
),
value
:
String
(
10
*
1000
)
},
__interval_ms
:
{
text
:
10
*
1000
,
value
:
10
*
1000
},
},
};
var
urlExpected
=
...
...
@@ -518,8 +518,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
String
(
10
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
10
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
10
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
10
*
1000
);
});
it
(
'should be interval * intervalFactor when greater than min interval'
,
function
()
{
var
query
=
{
...
...
@@ -535,7 +535,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__interval_ms
:
{
text
:
String
(
5
*
1000
),
value
:
String
(
5
*
1000
)
},
__interval_ms
:
{
text
:
5
*
1000
,
value
:
5
*
1000
},
},
};
var
urlExpected
=
...
...
@@ -546,8 +546,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
it
(
'should be min interval when greater than interval * intervalFactor'
,
function
()
{
var
query
=
{
...
...
@@ -563,7 +563,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__interval_ms
:
{
text
:
String
(
5
*
1000
),
value
:
String
(
5
*
1000
)
},
__interval_ms
:
{
text
:
5
*
1000
,
value
:
5
*
1000
},
},
};
var
urlExpected
=
...
...
@@ -574,8 +574,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
it
(
'should be determined by the 11000 data points limit, accounting for intervalFactor'
,
function
()
{
var
query
=
{
...
...
@@ -590,7 +590,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__interval_ms
:
{
text
:
String
(
5
*
1000
),
value
:
String
(
5
*
1000
)
},
__interval_ms
:
{
text
:
5
*
1000
,
value
:
5
*
1000
},
},
};
var
end
=
7
*
24
*
60
*
60
;
...
...
@@ -609,8 +609,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
});
});
...
...
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