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
98f0305e
Unverified
Commit
98f0305e
authored
Nov 30, 2017
by
Carl Bergquist
Committed by
GitHub
Nov 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9983 from mtanda/prometheus_nested
prometheus nested query support
parents
1e10fcad
98bb8bf7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
public/app/plugins/datasource/prometheus/datasource.ts
+8
-0
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
+15
-0
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
98f0305e
...
@@ -157,6 +157,7 @@ export class PrometheusDatasource {
...
@@ -157,6 +157,7 @@ export class PrometheusDatasource {
// Only replace vars in expression after having (possibly) updated interval vars
// Only replace vars in expression after having (possibly) updated interval vars
query
.
expr
=
this
.
templateSrv
.
replace
(
target
.
expr
,
scopedVars
,
this
.
interpolateQueryExpr
);
query
.
expr
=
this
.
templateSrv
.
replace
(
target
.
expr
,
scopedVars
,
this
.
interpolateQueryExpr
);
query
.
expr
=
this
.
replaceNestedQuery
(
query
.
expr
,
options
);
query
.
requestId
=
options
.
panelId
+
target
.
refId
;
query
.
requestId
=
options
.
panelId
+
target
.
refId
;
return
query
;
return
query
;
}
}
...
@@ -271,6 +272,13 @@ export class PrometheusDatasource {
...
@@ -271,6 +272,13 @@ export class PrometheusDatasource {
});
});
}
}
replaceNestedQuery
(
query
,
options
)
{
return
query
.
replace
(
/
\#([
A-Z
])
/g
,
(
match
,
g1
)
=>
{
let
replaceTarget
=
options
.
targets
.
find
((
t
)
=>
{
return
t
.
refId
===
g1
;
});
return
replaceTarget
?
replaceTarget
.
expr
:
match
;
});
}
transformMetricData
(
md
,
options
,
start
,
end
,
step
)
{
transformMetricData
(
md
,
options
,
start
,
end
,
step
)
{
var
dps
=
[],
var
dps
=
[],
metricLabel
=
null
;
metricLabel
=
null
;
...
...
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
View file @
98f0305e
...
@@ -590,4 +590,19 @@ describe('PrometheusDatasource', function() {
...
@@ -590,4 +590,19 @@ describe('PrometheusDatasource', function() {
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
expect
(
query
.
scopedVars
.
__interval_ms
.
value
).
to
.
be
(
5
*
1000
);
});
});
});
});
describe
(
'The nested query'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
let
query
=
'sum(rate(#A[1m]))'
;
let
options
=
{
targets
:
[
{
refId
:
'A'
,
expr
:
'http_requests_total'
}
]
};
let
result
=
ctx
.
ds
.
replaceNestedQuery
(
query
,
options
);
expect
(
result
).
to
.
be
(
'sum(rate(http_requests_total[1m]))'
);
});
});
});
});
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