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
9872ea7d
Commit
9872ea7d
authored
Oct 31, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: extract common function
parent
c993a4d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
31 deletions
+38
-31
public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx
+25
-31
public/app/plugins/datasource/stackdriver/functions.ts
+13
-0
No files found.
public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx
View file @
9872ea7d
import
React
,
{
PureComponent
}
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
SimpleDropdown
from
'./SimpleDropdown'
;
import
SimpleDropdown
from
'./SimpleDropdown'
;
import
{
TemplateQueryProps
}
from
'app/types/plugins'
;
import
{
TemplateQueryProps
}
from
'app/types/plugins'
;
import
{
getMetricTypes
ByService
,
extractServicesFromMetricDescriptors
}
from
'../functions'
;
import
{
getMetricTypes
,
extractServicesFromMetricDescriptors
}
from
'../functions'
;
import
defaultsDeep
from
'lodash/defaultsDeep'
;
import
defaultsDeep
from
'lodash/defaultsDeep'
;
import
{
MetricFindQueryTypes
}
from
'../types'
;
import
{
MetricFindQueryTypes
}
from
'../types'
;
...
@@ -43,12 +43,8 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
...
@@ -43,12 +43,8 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
value
:
m
.
service
,
value
:
m
.
service
,
name
:
m
.
serviceShortName
,
name
:
m
.
serviceShortName
,
}));
}));
const
service
=
this
.
state
.
service
||
services
[
0
].
value
;
const
service
=
services
.
some
(
s
=>
s
.
value
===
this
.
state
.
service
)
?
this
.
state
.
service
:
services
[
0
].
value
;
const
metricTypes
=
getMetricTypesByService
(
metricDescriptors
,
service
).
map
(
m
=>
({
const
{
metricTypes
,
metricType
}
=
getMetricTypes
(
metricDescriptors
,
this
.
state
.
metricType
,
service
);
value
:
m
.
type
,
name
:
m
.
displayName
,
}));
const
metricType
=
this
.
state
.
metricType
||
metricTypes
[
0
].
value
;
const
state
:
any
=
{
const
state
:
any
=
{
services
,
services
,
service
,
service
,
...
@@ -66,13 +62,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
...
@@ -66,13 +62,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
}
}
async
onServiceChange
(
event
)
{
async
onServiceChange
(
event
)
{
const
metricTypes
=
getMetricTypesByService
(
this
.
state
.
metricDescriptors
,
event
.
target
.
value
).
map
(
m
=>
({
const
{
metricTypes
,
metricType
}
=
getMetricTypes
(
value
:
m
.
type
,
this
.
state
.
metricDescriptors
,
name
:
m
.
displayName
,
this
.
state
.
metricType
,
}));
event
.
target
.
value
const
metricTypeExistInArray
=
metricTypes
.
find
(
m
=>
m
.
value
===
this
.
state
.
metricType
);
);
const
metricType
=
metricTypeExistInArray
?
metricTypeExistInArray
.
value
:
metricTypes
[
0
].
value
;
const
state
:
any
=
{
const
state
:
any
=
{
service
:
event
.
target
.
value
,
metricTypes
,
metricType
,
...
await
this
.
getLabels
(
metricType
)
};
service
:
event
.
target
.
value
,
metricTypes
,
metricType
,
...
await
this
.
getLabels
(
metricType
),
};
this
.
setState
(
state
);
this
.
setState
(
state
);
}
}
...
@@ -81,10 +81,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
...
@@ -81,10 +81,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this
.
setState
(
state
);
this
.
setState
(
state
);
}
}
async
getLabelKeys
(
metricType
,
type
=
this
.
state
.
type
)
{
onLabelKeyChange
(
event
)
{
const
refId
=
'StackdriverTemplateQueryComponent'
;
this
.
setState
({
labelKey
:
event
.
target
.
value
});
const
response
=
await
this
.
props
.
datasource
.
getLabels
(
metricType
,
refId
);
}
return
Object
.
keys
(
response
.
meta
[
type
]);
componentDidUpdate
()
{
const
{
metricDescriptors
,
metricLabels
,
resourceLabels
,
...
queryModel
}
=
this
.
state
;
this
.
props
.
onChange
(
queryModel
);
}
isLabelQuery
(
queryType
)
{
return
[
MetricFindQueryTypes
.
MetricLabels
,
MetricFindQueryTypes
.
ResourceLabels
].
indexOf
(
queryType
)
!==
-
1
;
}
}
async
getLabels
(
metricType
,
type
=
this
.
state
.
type
)
{
async
getLabels
(
metricType
,
type
=
this
.
state
.
type
)
{
...
@@ -99,19 +106,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
...
@@ -99,19 +106,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
return
result
;
return
result
;
}
}
onLabelKeyChange
(
event
)
{
this
.
setState
({
labelKey
:
event
.
target
.
value
});
}
componentDidUpdate
()
{
const
{
metricDescriptors
,
metricLabels
,
resourceLabels
,
...
queryModel
}
=
this
.
state
;
this
.
props
.
onChange
(
queryModel
);
}
isLabelQuery
(
queryType
)
{
return
[
MetricFindQueryTypes
.
MetricLabels
,
MetricFindQueryTypes
.
ResourceLabels
].
indexOf
(
queryType
)
!==
-
1
;
}
renderQueryTypeSwitch
(
queryType
)
{
renderQueryTypeSwitch
(
queryType
)
{
switch
(
queryType
)
{
switch
(
queryType
)
{
case
MetricFindQueryTypes
.
MetricTypes
:
case
MetricFindQueryTypes
.
MetricTypes
:
...
...
public/app/plugins/datasource/stackdriver/functions.ts
View file @
9872ea7d
...
@@ -6,6 +6,19 @@ export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(
...
@@ -6,6 +6,19 @@ export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(
export
const
getMetricTypesByService
=
(
metricDescriptors
,
service
)
=>
export
const
getMetricTypesByService
=
(
metricDescriptors
,
service
)
=>
metricDescriptors
.
filter
(
m
=>
m
.
service
===
service
);
metricDescriptors
.
filter
(
m
=>
m
.
service
===
service
);
export
const
getMetricTypes
=
(
metricDescriptors
,
selectedMetricType
,
service
)
=>
{
const
metricTypes
=
getMetricTypesByService
(
metricDescriptors
,
service
).
map
(
m
=>
({
value
:
m
.
type
,
name
:
m
.
displayName
,
}));
const
metricTypeExistInArray
=
metricTypes
.
some
(
m
=>
m
.
value
===
selectedMetricType
);
const
metricType
=
metricTypeExistInArray
?
metricTypeExistInArray
.
value
:
metricTypes
[
0
].
value
;
return
{
metricTypes
,
metricType
,
};
};
export
const
getAlignmentOptionsByMetric
=
(
metricValueType
,
metricKind
)
=>
{
export
const
getAlignmentOptionsByMetric
=
(
metricValueType
,
metricKind
)
=>
{
return
!
metricValueType
return
!
metricValueType
?
[]
?
[]
...
...
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