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 {
...
@@ -222,7 +222,7 @@ class MetricsPanelCtrl extends PanelCtrl {
// and add built in variables interval and interval_ms
// and add built in variables interval and interval_ms
var
scopedVars
=
Object
.
assign
({},
this
.
panel
.
scopedVars
,
{
var
scopedVars
=
Object
.
assign
({},
this
.
panel
.
scopedVars
,
{
__interval
:
{
text
:
this
.
interval
,
value
:
this
.
interval
},
__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
=
{
var
metricsQuery
=
{
...
...
public/app/plugins/datasource/prometheus/datasource.ts
View file @
bfd05ba6
...
@@ -17,11 +17,17 @@ export function alignRange(start, end, step) {
...
@@ -17,11 +17,17 @@ export function alignRange(start, end, step) {
}
}
export
function
prometheusRegularEscape
(
value
)
{
export
function
prometheusRegularEscape
(
value
)
{
return
value
.
replace
(
/'/g
,
"
\\\\
'"
);
if
(
typeof
value
===
'string'
)
{
return
value
.
replace
(
/'/g
,
"
\\\\
'"
);
}
return
value
;
}
}
export
function
prometheusSpecialRegexEscape
(
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 {
export class PrometheusDatasource {
...
@@ -196,7 +202,7 @@ export class PrometheusDatasource {
...
@@ -196,7 +202,7 @@ export class PrometheusDatasource {
interval = adjustedInterval;
interval = adjustedInterval;
scopedVars = Object.assign({}, options.scopedVars, {
scopedVars = Object.assign({}, options.scopedVars, {
__interval: { text: interval + '
s
', value: interval + '
s
' },
__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;
query.step = interval;
...
...
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
View file @
bfd05ba6
...
@@ -166,6 +166,9 @@ describe('PrometheusDatasource', () => {
...
@@ -166,6 +166,9 @@ describe('PrometheusDatasource', () => {
});
});
describe
(
'Prometheus regular escaping'
,
function
()
{
describe
(
'Prometheus regular escaping'
,
function
()
{
it
(
'should not escape non-string'
,
function
()
{
expect
(
prometheusRegularEscape
(
12
)).
toEqual
(
12
);
});
it
(
'should not escape simple string'
,
function
()
{
it
(
'should not escape simple string'
,
function
()
{
expect
(
prometheusRegularEscape
(
'cryptodepression'
)).
toEqual
(
'cryptodepression'
);
expect
(
prometheusRegularEscape
(
'cryptodepression'
)).
toEqual
(
'cryptodepression'
);
});
});
...
...
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
View file @
bfd05ba6
...
@@ -452,7 +452,7 @@ describe('PrometheusDatasource', function() {
...
@@ -452,7 +452,7 @@ describe('PrometheusDatasource', function() {
interval
:
'10s'
,
interval
:
'10s'
,
scopedVars
:
{
scopedVars
:
{
__interval
:
{
text
:
'10s'
,
value
:
'10s'
},
__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
=
var
urlExpected
=
...
@@ -463,8 +463,8 @@ describe('PrometheusDatasource', function() {
...
@@ -463,8 +463,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
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
.
text
).
to
.
be
(
10
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
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
()
{
it
(
'should be min interval when it is greater than auto interval'
,
function
()
{
var
query
=
{
var
query
=
{
...
@@ -479,7 +479,7 @@ describe('PrometheusDatasource', function() {
...
@@ -479,7 +479,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
interval
:
'5s'
,
scopedVars
:
{
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__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
=
var
urlExpected
=
...
@@ -490,8 +490,8 @@ describe('PrometheusDatasource', function() {
...
@@ -490,8 +490,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
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
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
});
it
(
'should account for intervalFactor'
,
function
()
{
it
(
'should account for intervalFactor'
,
function
()
{
var
query
=
{
var
query
=
{
...
@@ -507,7 +507,7 @@ describe('PrometheusDatasource', function() {
...
@@ -507,7 +507,7 @@ describe('PrometheusDatasource', function() {
interval
:
'10s'
,
interval
:
'10s'
,
scopedVars
:
{
scopedVars
:
{
__interval
:
{
text
:
'10s'
,
value
:
'10s'
},
__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
=
var
urlExpected
=
...
@@ -518,8 +518,8 @@ describe('PrometheusDatasource', function() {
...
@@ -518,8 +518,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'10s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
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
.
text
).
to
.
be
(
10
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
10
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
10
*
1000
);
});
});
it
(
'should be interval * intervalFactor when greater than min interval'
,
function
()
{
it
(
'should be interval * intervalFactor when greater than min interval'
,
function
()
{
var
query
=
{
var
query
=
{
...
@@ -535,7 +535,7 @@ describe('PrometheusDatasource', function() {
...
@@ -535,7 +535,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
interval
:
'5s'
,
scopedVars
:
{
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__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
=
var
urlExpected
=
...
@@ -546,8 +546,8 @@ describe('PrometheusDatasource', function() {
...
@@ -546,8 +546,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
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
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
5
*
1000
)
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
});
it
(
'should be min interval when greater than interval * intervalFactor'
,
function
()
{
it
(
'should be min interval when greater than interval * intervalFactor'
,
function
()
{
var
query
=
{
var
query
=
{
...
@@ -563,7 +563,7 @@ describe('PrometheusDatasource', function() {
...
@@ -563,7 +563,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
interval
:
'5s'
,
scopedVars
:
{
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__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
=
var
urlExpected
=
...
@@ -574,8 +574,8 @@ describe('PrometheusDatasource', function() {
...
@@ -574,8 +574,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
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
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
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
()
{
it
(
'should be determined by the 11000 data points limit, accounting for intervalFactor'
,
function
()
{
var
query
=
{
var
query
=
{
...
@@ -590,7 +590,7 @@ describe('PrometheusDatasource', function() {
...
@@ -590,7 +590,7 @@ describe('PrometheusDatasource', function() {
interval
:
'5s'
,
interval
:
'5s'
,
scopedVars
:
{
scopedVars
:
{
__interval
:
{
text
:
'5s'
,
value
:
'5s'
},
__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
;
var
end
=
7
*
24
*
60
*
60
;
...
@@ -609,8 +609,8 @@ describe('PrometheusDatasource', function() {
...
@@ -609,8 +609,8 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
text
).
to
.
be
(
'5s'
);
expect
(
query
.
scopedVars
.
__interval
.
value
).
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
.
text
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
String
(
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