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
3f731483
Commit
3f731483
authored
Sep 25, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: wip: split metric dropdown into two parts - resource and metric
parent
a41c5f7b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
6 deletions
+74
-6
public/app/plugins/datasource/stackdriver/datasource.ts
+1
-1
public/app/plugins/datasource/stackdriver/partials/query.editor.html
+21
-1
public/app/plugins/datasource/stackdriver/query_ctrl.ts
+52
-4
No files found.
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
3f731483
...
...
@@ -159,7 +159,7 @@ export default class StackdriverDatasource {
try
{
const
metricsApiPath
=
`v3/projects/
${
projectId
}
/metricDescriptors`
;
const
{
data
}
=
await
this
.
doRequest
(
`
${
this
.
baseUrl
}${
metricsApiPath
}
`
);
return
data
.
metricDescriptors
.
map
(
m
=>
({
id
:
m
.
type
,
name
:
m
.
displayName
}))
;
return
data
.
metricDescriptors
;
}
catch
(
error
)
{
console
.
log
(
error
);
}
...
...
public/app/plugins/datasource/stackdriver/partials/query.editor.html
View file @
3f731483
<query-editor-row
query-ctrl=
"ctrl"
has-text-edit-mode=
"false"
>
<div
class=
"gf-form-inline"
>
<
!-- <
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"
...
...
@@ -8,6 +8,26 @@
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div> -->
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-9"
>
Resource type
</span>
<gf-form-dropdown
model=
"ctrl.target.metricService"
get-options=
"ctrl.getMetricServices()"
class=
"min-width-20"
disabled
type=
"text"
allow-custom=
"true"
lookup-text=
"true"
css-class=
"min-width-12"
on-change=
"ctrl.onResourceTypeChange(ctrl.target.metricService)"
></gf-form-dropdown>
</div>
<div
class=
"gf-form gf-form--grow"
>
<div
class=
"gf-form-label gf-form-label--grow"
></div>
</div>
</div>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-9"
>
Metric
</span>
<gf-form-dropdown
model=
"ctrl.target.metricType"
title=
"Tooltip"
get-options=
"ctrl.metrics"
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>
</div>
</div>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
...
...
public/app/plugins/datasource/stackdriver/query_ctrl.ts
View file @
3f731483
...
...
@@ -19,6 +19,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
name
:
string
;
};
metricType
:
string
;
metricService
:
string
;
refId
:
string
;
aggregation
:
{
crossSeriesReducer
:
string
;
...
...
@@ -32,6 +33,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
valueType
:
any
;
};
defaultDropdownValue
=
'select metric'
;
defaultMetricResourcesValue
=
'all'
;
defaultRemoveGroupByValue
=
'-- remove group by --'
;
loadLabelsPromise
:
Promise
<
any
>
;
stackdriverConstants
;
...
...
@@ -42,6 +44,8 @@ export class StackdriverQueryCtrl extends QueryCtrl {
name
:
'loading project...'
,
},
metricType
:
this
.
defaultDropdownValue
,
metricService
:
this
.
defaultMetricResourcesValue
,
metric
:
''
,
aggregation
:
{
crossSeriesReducer
:
'REDUCE_MEAN'
,
alignmentPeriod
:
'auto'
,
...
...
@@ -55,6 +59,8 @@ export class StackdriverQueryCtrl extends QueryCtrl {
valueType
:
''
,
};
metricDescriptors
:
any
[];
metrics
:
any
[];
groupBySegments
:
any
[];
removeSegment
:
any
;
showHelp
:
boolean
;
...
...
@@ -69,10 +75,10 @@ export class StackdriverQueryCtrl extends QueryCtrl {
constructor
(
$scope
,
$injector
,
private
uiSegmentSrv
,
private
templateSrv
)
{
super
(
$scope
,
$injector
);
_
.
defaultsDeep
(
this
.
target
,
this
.
defaults
);
this
.
metricDescriptors
=
[];
this
.
metrics
=
[];
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
))
.
then
(
this
.
getLabels
.
bind
(
this
));
...
...
@@ -118,18 +124,60 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}
async
getMetricTypes
()
{
//projects/your-project-name/metricDescriptors/agent.googleapis.com/agent/api_request_count
if
(
this
.
target
.
project
.
id
!==
'default'
)
{
const
metricTypes
=
await
this
.
datasource
.
getMetricTypes
(
this
.
target
.
project
.
id
);
this
.
metricDescriptors
=
metricTypes
;
if
(
this
.
target
.
metricType
===
this
.
defaultDropdownValue
&&
metricTypes
.
length
>
0
)
{
this
.
$scope
.
$apply
(()
=>
(
this
.
target
.
metricType
=
metricTypes
[
0
].
id
));
}
return
metricTypes
.
map
(
mt
=>
({
value
:
mt
.
id
,
text
:
mt
.
id
}));
return
metricTypes
.
map
(
mt
=>
({
value
:
mt
.
type
,
text
:
mt
.
type
}));
}
else
{
return
[];
}
}
getMetricServices
()
{
const
defaultValue
=
{
value
:
this
.
defaultMetricResourcesValue
,
text
:
this
.
defaultMetricResourcesValue
};
const
resources
=
this
.
metricDescriptors
.
map
(
m
=>
{
const
[
resource
]
=
m
.
type
.
split
(
'/'
);
const
[
service
]
=
resource
.
split
(
'.'
);
return
{
value
:
resource
,
text
:
service
,
};
});
return
resources
.
length
>
0
?
[
defaultValue
,
...
_
.
uniqBy
(
resources
,
'value'
)]
:
[];
}
getMetrics
()
{
const
metrics
=
this
.
metricDescriptors
.
map
(
m
=>
{
const
[
resource
]
=
m
.
type
.
split
(
'/'
);
const
[
service
]
=
resource
.
split
(
'.'
);
return
{
resource
,
value
:
m
.
type
,
service
,
text
:
m
.
displayName
,
title
:
m
.
description
,
};
});
if
(
this
.
target
.
metricService
===
this
.
defaultMetricResourcesValue
)
{
return
metrics
.
map
(
m
=>
({
...
m
,
text
:
`
${
m
.
service
}
-
${
m
.
text
}
`
}));
}
else
{
return
metrics
.
filter
(
m
=>
m
.
resource
===
this
.
target
.
metricService
);
}
}
onResourceTypeChange
(
resource
)
{
this
.
metrics
=
this
.
getMetrics
();
if
(
!
this
.
metrics
.
find
(
m
=>
m
.
value
===
this
.
target
.
metricType
))
{
this
.
target
.
metricType
=
this
.
defaultDropdownValue
;
}
else
{
this
.
refresh
();
}
}
async
getLabels
()
{
this
.
loadLabelsPromise
=
new
Promise
(
async
resolve
=>
{
try
{
...
...
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