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
add23d97
Commit
add23d97
authored
Sep 13, 2018
by
Erik Sundell
Committed by
Daniel Lee
Sep 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: load time series meta data for group by dropdown
parent
5763d3ca
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
16 deletions
+67
-16
pkg/tsdb/stackdriver/stackdriver.go
+1
-0
public/app/plugins/datasource/stackdriver/datasource.ts
+9
-5
public/app/plugins/datasource/stackdriver/partials/query.editor.html
+4
-4
public/app/plugins/datasource/stackdriver/query_ctrl.ts
+53
-7
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
add23d97
...
...
@@ -103,6 +103,7 @@ func (e *StackdriverExecutor) buildQueries(tsdbQuery *tsdb.TsdbQuery) ([]*Stackd
params
.
Add
(
"interval.startTime"
,
startTime
.
UTC
()
.
Format
(
time
.
RFC3339
))
params
.
Add
(
"interval.endTime"
,
endTime
.
UTC
()
.
Format
(
time
.
RFC3339
))
params
.
Add
(
"filter"
,
"metric.type=
\"
"
+
metricType
+
"
\"
"
)
params
.
Add
(
"view"
,
query
.
Model
.
Get
(
"view"
)
.
MustString
())
setAggParams
(
&
params
,
query
)
if
setting
.
Env
==
setting
.
DEV
{
...
...
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
add23d97
...
...
@@ -11,17 +11,16 @@ export default class StackdriverDatasource {
this
.
id
=
instanceSettings
.
id
;
}
async
query
(
options
)
{
async
getTimeSeries
(
options
)
{
const
queries
=
options
.
targets
.
filter
(
target
=>
!
target
.
hide
).
map
(
t
=>
({
refId
:
t
.
refId
,
datasourceId
:
this
.
id
,
metricType
:
t
.
metricType
,
primaryAggregation
:
t
.
aggregation
.
crossSeriesReducer
,
groupBys
:
t
.
aggregation
.
groupBys
,
primaryAggregation
:
'REDUCE_MEAN'
,
//t.aggregation.crossSeriesReducer,
// groupBys: t.aggregation.groupBys,
view
:
t
.
view
||
'FULL'
,
}));
const
result
=
[];
const
{
data
}
=
await
this
.
backendSrv
.
datasourceRequest
({
url
:
'/api/tsdb/query'
,
method
:
'POST'
,
...
...
@@ -31,7 +30,12 @@ export default class StackdriverDatasource {
queries
,
},
});
return
data
;
}
async
query
(
options
)
{
const
result
=
[];
const
data
=
await
this
.
getTimeSeries
(
options
);
if
(
data
.
results
)
{
Object
[
'values'
](
data
.
results
).
forEach
(
queryRes
=>
{
if
(
!
queryRes
.
series
)
{
...
...
public/app/plugins/datasource/stackdriver/partials/query.editor.html
View file @
add23d97
...
...
@@ -2,8 +2,8 @@
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-9"
>
Metric Type
</span>
<gf-form-dropdown
model=
"ctrl.target.metricType"
get-options=
"ctrl.getMetricTypes($query)"
class=
"min-width-20"
disabled
type=
"text"
allow-custom=
"true"
lookup-text=
"true"
css-class=
"min-width-12"
on-change=
"ctrl.refresh
()"
></gf-form-dropdown>
<gf-form-dropdown
model=
"ctrl.target.metricType"
get-options=
"ctrl.getMetricTypes($query)"
class=
"min-width-20"
disabled
type=
"text"
allow-custom=
"true"
lookup-text=
"true"
css-class=
"min-width-12"
on-change=
"ctrl.onMetricTypeChange
()"
></gf-form-dropdown>
</div>
<div
class=
"gf-form gf-form--grow"
>
<div
class=
"gf-form-label gf-form-label--grow"
></div>
...
...
@@ -30,8 +30,8 @@
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-9"
>
Project
</span>
<input
class=
"gf-form-input"
disabled
type=
"text"
ng-model=
'ctrl.target.project.name'
get-options=
"ctrl.getProjects()"
css-class=
"min-width-12"
/>
<input
class=
"gf-form-input"
disabled
type=
"text"
ng-model=
'ctrl.target.project.name'
get-options=
"ctrl.getProjects()"
css-class=
"min-width-12"
/>
</div>
<div
class=
"gf-form"
>
<label
class=
"gf-form-label query-keyword"
ng-click=
"ctrl.showHelp = !ctrl.showHelp"
>
...
...
public/app/plugins/datasource/stackdriver/query_ctrl.ts
View file @
add23d97
...
...
@@ -2,10 +2,16 @@ import _ from 'lodash';
import
{
QueryCtrl
}
from
'app/plugins/sdk'
;
import
appEvents
from
'app/core/app_events'
;
export
interface
LabelType
{
key
:
string
;
value
:
string
;
}
export
interface
QueryMeta
{
rawQuery
:
string
;
rawQueryString
:
string
;
metricLabels
:
any
;
metricLabels
:
LabelType
[];
resourceLabels
:
LabelType
[];
}
export
class
StackdriverQueryCtrl
extends
QueryCtrl
{
static
templateUrl
=
'partials/query.editor.html'
;
...
...
@@ -59,18 +65,22 @@ export class StackdriverQueryCtrl extends QueryCtrl {
showLastQuery
:
boolean
;
lastQueryMeta
:
QueryMeta
;
lastQueryError
?:
string
;
metricLabels
:
LabelType
[];
resourceLabels
:
LabelType
[];
/** @ngInject */
constructor
(
$scope
,
$injector
,
private
uiSegmentSrv
)
{
constructor
(
$scope
,
$injector
,
private
uiSegmentSrv
,
private
timeSrv
)
{
super
(
$scope
,
$injector
);
_
.
defaultsDeep
(
this
.
target
,
this
.
defaults
);
this
.
panelCtrl
.
events
.
on
(
'data-received'
,
this
.
onDataReceived
.
bind
(
this
),
$scope
);
this
.
panelCtrl
.
events
.
on
(
'data-error'
,
this
.
onDataError
.
bind
(
this
),
$scope
);
this
.
getCurrentProject
().
then
(
this
.
getMetricTypes
.
bind
(
this
));
this
.
getCurrentProject
()
.
then
(
this
.
getMetricTypes
.
bind
(
this
))
.
then
(
this
.
getLabels
.
bind
(
this
));
this
.
groupBySegments
=
_
.
map
(
this
.
target
.
aggregation
.
groupBys
,
groupBy
=>
{
this
.
groupBySegments
=
this
.
target
.
aggregation
.
groupBys
.
map
(
groupBy
=>
{
return
uiSegmentSrv
.
getSegmentForValue
(
groupBy
);
});
this
.
ensurePlusButton
(
this
.
groupBySegments
);
...
...
@@ -116,12 +126,47 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}
}
async
getLabels
()
{
const
data
=
await
this
.
datasource
.
getTimeSeries
({
targets
:
[
{
refId
:
this
.
target
.
refId
,
datasourceId
:
this
.
datasource
.
id
,
metricType
:
this
.
target
.
metricType
,
aggregation
:
{
crossSeriesReducer
:
'REDUCE_NONE'
,
},
view
:
'HEADERS'
,
},
],
range
:
this
.
timeSrv
.
timeRange
(),
});
this
.
metricLabels
=
data
.
results
[
this
.
target
.
refId
].
meta
.
metricLabels
;
this
.
resourceLabels
=
data
.
results
[
this
.
target
.
refId
].
meta
.
resourceLabels
;
}
async
onMetricTypeChange
()
{
this
.
refresh
();
this
.
getLabels
();
}
getGroupBys
()
{
const
segments
=
_
.
map
(
Object
.
keys
(
this
.
lastQueryMeta
.
metricLabels
),
(
label
:
string
)
=>
{
return
this
.
uiSegmentSrv
.
newSegment
({
value
:
label
,
expandable
:
false
});
const
metricLabels
=
Object
.
keys
(
this
.
metricLabels
).
map
(
l
=>
{
return
this
.
uiSegmentSrv
.
newSegment
({
value
:
`metric.label.
${
l
}
`
,
expandable
:
false
,
});
});
const
resourceLabels
=
Object
.
keys
(
this
.
resourceLabels
).
map
(
l
=>
{
return
this
.
uiSegmentSrv
.
newSegment
({
value
:
`resource.label.
${
l
}
`
,
expandable
:
false
,
});
});
return
Promise
.
resolve
(
segments
);
return
Promise
.
resolve
(
[...
metricLabels
,
...
resourceLabels
]
);
}
groupByChanged
(
segment
,
index
)
{
...
...
@@ -136,6 +181,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
[]
);
this
.
ensurePlusButton
(
this
.
groupBySegments
);
this
.
refresh
();
}
ensurePlusButton
(
segments
)
{
...
...
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