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
0ec4491a
Commit
0ec4491a
authored
Nov 19, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: reimplementing service variable query type
parent
795af5de
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
9 deletions
+27
-9
public/app/features/templating/query_variable.ts
+1
-0
public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts
+13
-0
public/app/plugins/datasource/stackdriver/components/SimpleSelect.tsx
+1
-1
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.tsx
+8
-8
public/app/plugins/datasource/stackdriver/functions.ts
+3
-0
public/app/plugins/datasource/stackdriver/types.ts
+1
-0
No files found.
public/app/features/templating/query_variable.ts
View file @
0ec4491a
...
...
@@ -23,6 +23,7 @@ export class QueryVariable implements Variable {
tagValuesQuery
:
string
;
tags
:
any
[];
skipUrlSync
:
boolean
;
definition
:
string
;
defaults
=
{
type
:
'query'
,
...
...
public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts
View file @
0ec4491a
...
...
@@ -5,6 +5,7 @@ import {
getMetricTypesByService
,
getAlignmentOptionsByMetric
,
getAggregationOptionsByMetric
,
extractServicesFromMetricDescriptors
,
getLabelKeys
,
}
from
'./functions'
;
...
...
@@ -14,6 +15,8 @@ export default class StackdriverMetricFindQuery {
async
execute
(
query
:
any
)
{
try
{
switch
(
query
.
selectedQueryType
)
{
case
MetricFindQueryTypes
.
Services
:
return
this
.
handleServiceQuery
();
case
MetricFindQueryTypes
.
MetricTypes
:
return
this
.
handleMetricTypesQuery
(
query
);
case
MetricFindQueryTypes
.
LabelKeys
:
...
...
@@ -37,6 +40,16 @@ export default class StackdriverMetricFindQuery {
}
}
async
handleServiceQuery
()
{
const
metricDescriptors
=
await
this
.
datasource
.
getMetricTypes
(
this
.
datasource
.
projectName
);
const
services
=
extractServicesFromMetricDescriptors
(
metricDescriptors
);
return
services
.
map
(
s
=>
({
text
:
s
.
serviceShortName
,
value
:
s
.
service
,
expandable
:
true
,
}));
}
async
handleMetricTypesQuery
({
selectedService
})
{
if
(
!
selectedService
)
{
return
[];
...
...
public/app/plugins/datasource/stackdriver/components/SimpleSelect.tsx
View file @
0ec4491a
...
...
@@ -12,7 +12,7 @@ const SimpleSelect: SFC<Props> = props => {
return
(
<
div
className=
"gf-form max-width-21"
>
<
span
className=
"gf-form-label width-10"
>
{
label
}
</
span
>
<
div
className=
"gf-form-select-wrapper max-width-1
0
"
>
<
div
className=
"gf-form-select-wrapper max-width-1
2
"
>
<
select
className=
"gf-form-input"
required
onChange=
{
onValueChange
}
value=
{
value
}
>
{
options
.
map
(({
value
,
name
},
i
)
=>
(
<
option
key=
{
i
}
value=
{
value
}
>
...
...
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.tsx
View file @
0ec4491a
import
React
,
{
PureComponent
}
from
'react'
;
import
uniqBy
from
'lodash/uniqBy'
;
import
{
VariableQueryProps
}
from
'app/types/plugins'
;
import
SimpleSelect
from
'./SimpleSelect'
;
import
{
getMetricTypes
,
getLabelKeys
}
from
'../functions'
;
import
{
getMetricTypes
,
getLabelKeys
,
extractServicesFromMetricDescriptors
}
from
'../functions'
;
import
{
MetricFindQueryTypes
,
VariableQueryData
}
from
'../types'
;
export
class
StackdriverVariableQueryEditor
extends
PureComponent
<
VariableQueryProps
,
VariableQueryData
>
{
queryTypes
:
Array
<
{
value
:
string
;
name
:
string
}
>
=
[
{
value
:
MetricFindQueryTypes
.
Services
,
name
:
'Services'
},
{
value
:
MetricFindQueryTypes
.
MetricTypes
,
name
:
'Metric Types'
},
{
value
:
MetricFindQueryTypes
.
LabelKeys
,
name
:
'Label Keys'
},
{
value
:
MetricFindQueryTypes
.
LabelValues
,
name
:
'Label Values'
},
...
...
@@ -34,7 +34,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
async
componentDidMount
()
{
const
metricDescriptors
=
await
this
.
props
.
datasource
.
getMetricTypes
(
this
.
props
.
datasource
.
projectName
);
const
services
=
uniqBy
(
metricDescriptors
,
'service'
).
map
(
m
=>
({
const
services
=
extractServicesFromMetricDescriptors
(
metricDescriptors
).
map
(
m
=>
({
value
:
m
.
service
,
name
:
m
.
serviceShortName
,
}));
...
...
@@ -50,7 +50,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
metricDescriptors
,
this
.
state
.
selectedMetricType
,
this
.
props
.
templateSrv
.
replace
(
this
.
state
.
selectedMetricType
),
selectedService
this
.
props
.
templateSrv
.
replace
(
selectedService
)
);
const
state
:
any
=
{
services
,
...
...
@@ -76,7 +76,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
this
.
state
.
metricDescriptors
,
this
.
state
.
selectedMetricType
,
this
.
props
.
templateSrv
.
replace
(
this
.
state
.
selectedMetricType
),
event
.
target
.
value
this
.
props
.
templateSrv
.
replace
(
event
.
target
.
value
)
);
const
state
:
any
=
{
selectedService
:
event
.
target
.
value
,
...
...
@@ -125,7 +125,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
return
(
<
SimpleSelect
value=
{
this
.
state
.
selectedService
}
options=
{
this
.
state
.
services
}
options=
{
this
.
insertTemplateVariables
(
this
.
state
.
services
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
label=
"Services"
/>
...
...
@@ -137,7 +137,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
<
React
.
Fragment
>
<
SimpleSelect
value=
{
this
.
state
.
selectedService
}
options=
{
this
.
state
.
services
}
options=
{
this
.
insertTemplateVariables
(
this
.
state
.
services
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
label=
"Services"
/>
...
...
@@ -163,7 +163,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
<
React
.
Fragment
>
<
SimpleSelect
value=
{
this
.
state
.
selectedService
}
options=
{
this
.
state
.
services
}
options=
{
this
.
insertTemplateVariables
(
this
.
state
.
services
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
label=
"Services"
/>
...
...
public/app/plugins/datasource/stackdriver/functions.ts
View file @
0ec4491a
import
uniqBy
from
'lodash/uniqBy'
;
import
{
alignOptions
,
aggOptions
}
from
'./constants'
;
export
const
extractServicesFromMetricDescriptors
=
metricDescriptors
=>
uniqBy
(
metricDescriptors
,
'service'
);
export
const
getMetricTypesByService
=
(
metricDescriptors
,
service
)
=>
metricDescriptors
.
filter
(
m
=>
m
.
service
===
service
);
...
...
public/app/plugins/datasource/stackdriver/types.ts
View file @
0ec4491a
export
enum
MetricFindQueryTypes
{
Services
=
'services'
,
MetricTypes
=
'metricTypes'
,
LabelKeys
=
'labelKeys'
,
LabelValues
=
'labelValues'
,
...
...
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