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
6f811095
Commit
6f811095
authored
Sep 07, 2017
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(prometheus) support instant query for table format, use checkbox to switch query type
parent
56cb16ff
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
5 deletions
+53
-5
public/app/plugins/datasource/prometheus/datasource.ts
+5
-2
public/app/plugins/datasource/prometheus/partials/query.editor.html
+2
-0
public/app/plugins/datasource/prometheus/query_ctrl.ts
+3
-1
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
+43
-2
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
6f811095
...
...
@@ -100,7 +100,7 @@ export class PrometheusDatasource {
var
query
:
any
=
{};
query
.
expr
=
this
.
templateSrv
.
replace
(
target
.
expr
,
options
.
scopedVars
,
self
.
interpolateQueryExpr
);
query
.
requestId
=
options
.
panelId
+
target
.
refId
;
query
.
format
=
target
.
forma
t
;
query
.
instant
=
target
.
instan
t
;
var
interval
=
this
.
templateSrv
.
replace
(
target
.
interval
,
options
.
scopedVars
)
||
options
.
interval
;
var
intervalFactor
=
target
.
intervalFactor
||
1
;
...
...
@@ -116,7 +116,7 @@ export class PrometheusDatasource {
}
var
allQueryPromise
=
_
.
map
(
queries
,
query
=>
{
if
(
query
.
format
===
'time_series'
)
{
if
(
!
query
.
instant
)
{
return
this
.
performTimeSeriesQuery
(
query
,
start
,
end
);
}
else
{
return
this
.
performInstantQuery
(
query
,
end
);
...
...
@@ -333,6 +333,9 @@ export class PrometheusDatasource {
// Populate rows, set value to empty string when label not present.
_
.
each
(
md
,
function
(
series
)
{
if
(
series
.
value
)
{
series
.
values
=
[
series
.
value
];
}
if
(
series
.
values
)
{
for
(
i
=
0
;
i
<
series
.
values
.
length
;
i
++
)
{
var
values
=
series
.
values
[
i
];
...
...
public/app/plugins/datasource/prometheus/partials/query.editor.html
View file @
6f811095
...
...
@@ -45,6 +45,8 @@
<div
class=
"gf-form-select-wrapper width-8"
>
<select
class=
"gf-form-input gf-size-auto"
ng-model=
"ctrl.target.format"
ng-options=
"f.value as f.text for f in ctrl.formats"
ng-change=
"ctrl.refresh()"
></select>
</div>
<gf-form-switch
class=
"gf-form"
label=
"Instant"
label-class=
"width-5"
checked=
"ctrl.target.instant"
on-change=
"ctrl.refresh()"
>
</gf-form-switch>
<label
class=
"gf-form-label"
>
<a
href=
"{{ctrl.linkToPrometheus}}"
target=
"_blank"
bs-tooltip=
"'Link to Graph in Prometheus'"
>
<i
class=
"fa fa-share-square-o"
></i>
...
...
public/app/plugins/datasource/prometheus/query_ctrl.ts
View file @
6f811095
...
...
@@ -14,6 +14,7 @@ class PrometheusQueryCtrl extends QueryCtrl {
metric
:
any
;
resolutions
:
any
;
formats
:
any
;
instant
:
any
;
oldTarget
:
any
;
suggestMetrics
:
any
;
getMetricsAutocomplete
:
any
;
...
...
@@ -36,9 +37,10 @@ class PrometheusQueryCtrl extends QueryCtrl {
this
.
formats
=
[
{
text
:
'Time series'
,
value
:
'time_series'
},
{
text
:
'Table'
,
value
:
'table'
},
{
text
:
'Instant'
,
value
:
'instant'
},
];
this
.
instant
=
false
;
this
.
updateLink
();
}
...
...
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
View file @
6f811095
...
...
@@ -119,14 +119,14 @@ describe('PrometheusDatasource', function() {
expect
(
results
.
data
[
1
].
datapoints
[
3
][
0
]).
to
.
be
(
null
);
});
});
describe
(
'When querying prometheus with one target and
format = instant
'
,
function
()
{
describe
(
'When querying prometheus with one target and
instant = true
'
,
function
()
{
var
results
;
var
urlExpected
=
'proxied/api/v1/query?query='
+
encodeURIComponent
(
'test{job="testjob"}'
)
+
'&time=1443460275'
;
var
query
=
{
range
:
{
from
:
moment
(
1443438674760
),
to
:
moment
(
1443460274760
)
},
targets
:
[{
expr
:
'test{job="testjob"}'
,
format
:
'
instant'
}],
targets
:
[{
expr
:
'test{job="testjob"}'
,
format
:
'
time_series'
,
instant
:
true
}],
interval
:
'60s'
};
var
response
=
{
...
...
@@ -228,4 +228,45 @@ describe('PrometheusDatasource', function() {
);
});
});
describe
(
'When resultFormat is table and instant = true'
,
function
()
{
var
results
;
var
urlExpected
=
'proxied/api/v1/query?query='
+
encodeURIComponent
(
'test{job="testjob"}'
)
+
'&time=1443460275'
;
var
query
=
{
range
:
{
from
:
moment
(
1443438674760
),
to
:
moment
(
1443460274760
)
},
targets
:
[{
expr
:
'test{job="testjob"}'
,
format
:
'time_series'
,
instant
:
true
}],
interval
:
'60s'
};
var
response
=
{
status
:
"success"
,
data
:
{
resultType
:
"vector"
,
result
:
[{
metric
:
{
"__name__"
:
"test"
,
job
:
"testjob"
},
value
:
[
1443454528
,
"3846"
]
}]
}
};
beforeEach
(
function
()
{
ctx
.
$httpBackend
.
expect
(
'GET'
,
urlExpected
).
respond
(
response
);
ctx
.
ds
.
query
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
});
it
(
'should return table model'
,
function
()
{
var
table
=
ctx
.
ds
.
transformMetricDataToTable
(
response
.
data
.
result
);
expect
(
table
.
type
).
to
.
be
(
'table'
);
expect
(
table
.
rows
).
to
.
eql
(
[
[
1443454528000
,
'test'
,
'testjob'
,
3846
]
]);
expect
(
table
.
columns
).
to
.
eql
(
[
{
text
:
'Time'
,
type
:
'time'
},
{
text
:
'__name__'
},
{
text
:
'job'
},
{
text
:
'Value'
}
]
);
});
});
});
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