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
Show 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 {
...
@@ -23,6 +23,7 @@ export class QueryVariable implements Variable {
tagValuesQuery
:
string
;
tagValuesQuery
:
string
;
tags
:
any
[];
tags
:
any
[];
skipUrlSync
:
boolean
;
skipUrlSync
:
boolean
;
definition
:
string
;
defaults
=
{
defaults
=
{
type
:
'query'
,
type
:
'query'
,
...
...
public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts
View file @
0ec4491a
...
@@ -5,6 +5,7 @@ import {
...
@@ -5,6 +5,7 @@ import {
getMetricTypesByService
,
getMetricTypesByService
,
getAlignmentOptionsByMetric
,
getAlignmentOptionsByMetric
,
getAggregationOptionsByMetric
,
getAggregationOptionsByMetric
,
extractServicesFromMetricDescriptors
,
getLabelKeys
,
getLabelKeys
,
}
from
'./functions'
;
}
from
'./functions'
;
...
@@ -14,6 +15,8 @@ export default class StackdriverMetricFindQuery {
...
@@ -14,6 +15,8 @@ export default class StackdriverMetricFindQuery {
async
execute
(
query
:
any
)
{
async
execute
(
query
:
any
)
{
try
{
try
{
switch
(
query
.
selectedQueryType
)
{
switch
(
query
.
selectedQueryType
)
{
case
MetricFindQueryTypes
.
Services
:
return
this
.
handleServiceQuery
();
case
MetricFindQueryTypes
.
MetricTypes
:
case
MetricFindQueryTypes
.
MetricTypes
:
return
this
.
handleMetricTypesQuery
(
query
);
return
this
.
handleMetricTypesQuery
(
query
);
case
MetricFindQueryTypes
.
LabelKeys
:
case
MetricFindQueryTypes
.
LabelKeys
:
...
@@ -37,6 +40,16 @@ export default class StackdriverMetricFindQuery {
...
@@ -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
})
{
async
handleMetricTypesQuery
({
selectedService
})
{
if
(
!
selectedService
)
{
if
(
!
selectedService
)
{
return
[];
return
[];
...
...
public/app/plugins/datasource/stackdriver/components/SimpleSelect.tsx
View file @
0ec4491a
...
@@ -12,7 +12,7 @@ const SimpleSelect: SFC<Props> = props => {
...
@@ -12,7 +12,7 @@ const SimpleSelect: SFC<Props> = props => {
return
(
return
(
<
div
className=
"gf-form max-width-21"
>
<
div
className=
"gf-form max-width-21"
>
<
span
className=
"gf-form-label width-10"
>
{
label
}
</
span
>
<
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
}
>
<
select
className=
"gf-form-input"
required
onChange=
{
onValueChange
}
value=
{
value
}
>
{
options
.
map
(({
value
,
name
},
i
)
=>
(
{
options
.
map
(({
value
,
name
},
i
)
=>
(
<
option
key=
{
i
}
value=
{
value
}
>
<
option
key=
{
i
}
value=
{
value
}
>
...
...
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.tsx
View file @
0ec4491a
import
React
,
{
PureComponent
}
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
uniqBy
from
'lodash/uniqBy'
;
import
{
VariableQueryProps
}
from
'app/types/plugins'
;
import
{
VariableQueryProps
}
from
'app/types/plugins'
;
import
SimpleSelect
from
'./SimpleSelect'
;
import
SimpleSelect
from
'./SimpleSelect'
;
import
{
getMetricTypes
,
getLabelKeys
}
from
'../functions'
;
import
{
getMetricTypes
,
getLabelKeys
,
extractServicesFromMetricDescriptors
}
from
'../functions'
;
import
{
MetricFindQueryTypes
,
VariableQueryData
}
from
'../types'
;
import
{
MetricFindQueryTypes
,
VariableQueryData
}
from
'../types'
;
export
class
StackdriverVariableQueryEditor
extends
PureComponent
<
VariableQueryProps
,
VariableQueryData
>
{
export
class
StackdriverVariableQueryEditor
extends
PureComponent
<
VariableQueryProps
,
VariableQueryData
>
{
queryTypes
:
Array
<
{
value
:
string
;
name
:
string
}
>
=
[
queryTypes
:
Array
<
{
value
:
string
;
name
:
string
}
>
=
[
{
value
:
MetricFindQueryTypes
.
Services
,
name
:
'Services'
},
{
value
:
MetricFindQueryTypes
.
MetricTypes
,
name
:
'Metric Types'
},
{
value
:
MetricFindQueryTypes
.
MetricTypes
,
name
:
'Metric Types'
},
{
value
:
MetricFindQueryTypes
.
LabelKeys
,
name
:
'Label Keys'
},
{
value
:
MetricFindQueryTypes
.
LabelKeys
,
name
:
'Label Keys'
},
{
value
:
MetricFindQueryTypes
.
LabelValues
,
name
:
'Label Values'
},
{
value
:
MetricFindQueryTypes
.
LabelValues
,
name
:
'Label Values'
},
...
@@ -34,7 +34,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
...
@@ -34,7 +34,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
async
componentDidMount
()
{
async
componentDidMount
()
{
const
metricDescriptors
=
await
this
.
props
.
datasource
.
getMetricTypes
(
this
.
props
.
datasource
.
projectName
);
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
,
value
:
m
.
service
,
name
:
m
.
serviceShortName
,
name
:
m
.
serviceShortName
,
}));
}));
...
@@ -50,7 +50,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
...
@@ -50,7 +50,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
metricDescriptors
,
metricDescriptors
,
this
.
state
.
selectedMetricType
,
this
.
state
.
selectedMetricType
,
this
.
props
.
templateSrv
.
replace
(
this
.
state
.
selectedMetricType
),
this
.
props
.
templateSrv
.
replace
(
this
.
state
.
selectedMetricType
),
selectedService
this
.
props
.
templateSrv
.
replace
(
selectedService
)
);
);
const
state
:
any
=
{
const
state
:
any
=
{
services
,
services
,
...
@@ -76,7 +76,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
...
@@ -76,7 +76,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
this
.
state
.
metricDescriptors
,
this
.
state
.
metricDescriptors
,
this
.
state
.
selectedMetricType
,
this
.
state
.
selectedMetricType
,
this
.
props
.
templateSrv
.
replace
(
this
.
state
.
selectedMetricType
),
this
.
props
.
templateSrv
.
replace
(
this
.
state
.
selectedMetricType
),
event
.
target
.
value
this
.
props
.
templateSrv
.
replace
(
event
.
target
.
value
)
);
);
const
state
:
any
=
{
const
state
:
any
=
{
selectedService
:
event
.
target
.
value
,
selectedService
:
event
.
target
.
value
,
...
@@ -125,7 +125,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
...
@@ -125,7 +125,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
return
(
return
(
<
SimpleSelect
<
SimpleSelect
value=
{
this
.
state
.
selectedService
}
value=
{
this
.
state
.
selectedService
}
options=
{
this
.
state
.
services
}
options=
{
this
.
insertTemplateVariables
(
this
.
state
.
services
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
label=
"Services"
label=
"Services"
/>
/>
...
@@ -137,7 +137,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
...
@@ -137,7 +137,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
<
React
.
Fragment
>
<
React
.
Fragment
>
<
SimpleSelect
<
SimpleSelect
value=
{
this
.
state
.
selectedService
}
value=
{
this
.
state
.
selectedService
}
options=
{
this
.
state
.
services
}
options=
{
this
.
insertTemplateVariables
(
this
.
state
.
services
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
label=
"Services"
label=
"Services"
/>
/>
...
@@ -163,7 +163,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
...
@@ -163,7 +163,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
<
React
.
Fragment
>
<
React
.
Fragment
>
<
SimpleSelect
<
SimpleSelect
value=
{
this
.
state
.
selectedService
}
value=
{
this
.
state
.
selectedService
}
options=
{
this
.
state
.
services
}
options=
{
this
.
insertTemplateVariables
(
this
.
state
.
services
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
onValueChange=
{
e
=>
this
.
onServiceChange
(
e
)
}
label=
"Services"
label=
"Services"
/>
/>
...
...
public/app/plugins/datasource/stackdriver/functions.ts
View file @
0ec4491a
import
uniqBy
from
'lodash/uniqBy'
;
import
{
alignOptions
,
aggOptions
}
from
'./constants'
;
import
{
alignOptions
,
aggOptions
}
from
'./constants'
;
export
const
extractServicesFromMetricDescriptors
=
metricDescriptors
=>
uniqBy
(
metricDescriptors
,
'service'
);
export
const
getMetricTypesByService
=
(
metricDescriptors
,
service
)
=>
export
const
getMetricTypesByService
=
(
metricDescriptors
,
service
)
=>
metricDescriptors
.
filter
(
m
=>
m
.
service
===
service
);
metricDescriptors
.
filter
(
m
=>
m
.
service
===
service
);
...
...
public/app/plugins/datasource/stackdriver/types.ts
View file @
0ec4491a
export
enum
MetricFindQueryTypes
{
export
enum
MetricFindQueryTypes
{
Services
=
'services'
,
MetricTypes
=
'metricTypes'
,
MetricTypes
=
'metricTypes'
,
LabelKeys
=
'labelKeys'
,
LabelKeys
=
'labelKeys'
,
LabelValues
=
'labelValues'
,
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