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
26b1cc5d
Commit
26b1cc5d
authored
Nov 19, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: join resource and metric labels. split them in values and keys
parent
69137e67
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
34 deletions
+43
-34
public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts
+26
-9
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.test.tsx
+2
-2
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.tsx
+13
-21
public/app/plugins/datasource/stackdriver/types.ts
+2
-2
No files found.
public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts
View file @
26b1cc5d
import
has
from
'lodash/has'
;
import
isString
from
'lodash/isString'
;
import
{
alignmentPeriods
}
from
'./constants'
;
import
{
MetricFindQueryTypes
}
from
'./types'
;
...
...
@@ -12,9 +11,10 @@ export default class StackdriverMetricFindQuery {
switch
(
query
.
selectedQueryType
)
{
case
MetricFindQueryTypes
.
MetricTypes
:
return
this
.
handleMetricTypesQuery
(
query
);
case
MetricFindQueryTypes
.
MetricLabels
:
case
MetricFindQueryTypes
.
ResourceLabels
:
return
this
.
handleLabelQuery
(
query
);
case
MetricFindQueryTypes
.
LabelKeys
:
return
this
.
handleLabelKeysQuery
(
query
);
case
MetricFindQueryTypes
.
LabelValues
:
return
this
.
handleLabelValuesQuery
(
query
);
case
MetricFindQueryTypes
.
ResourceTypes
:
return
this
.
handleResourceTypeQuery
(
query
);
case
MetricFindQueryTypes
.
Aligners
:
...
...
@@ -44,16 +44,33 @@ export default class StackdriverMetricFindQuery {
}));
}
async
handleLabelQuery
({
selectedQueryType
,
selectedMetricType
,
labelKey
})
{
async
handleLabel
Keys
Query
({
selectedQueryType
,
selectedMetricType
,
labelKey
})
{
if
(
!
selectedMetricType
)
{
return
[];
}
const
refId
=
'handleLabel
sQueryType
'
;
const
refId
=
'handleLabel
KeysQuery
'
;
const
response
=
await
this
.
datasource
.
getLabels
(
selectedMetricType
,
refId
);
if
(
!
has
(
response
,
`meta.
${
selectedQueryType
}
.
${
labelKey
}
`
))
{
const
labelKeys
=
response
.
meta
?
[...
Object
.
keys
(
response
.
meta
.
resourceLabels
),
...
Object
.
keys
(
response
.
meta
.
metricLabels
)]
:
[];
return
labelKeys
.
map
(
this
.
toFindQueryResult
);
}
async
handleLabelValuesQuery
({
selectedQueryType
,
selectedMetricType
,
labelKey
})
{
if
(
!
selectedMetricType
)
{
return
[];
}
return
response
.
meta
[
selectedQueryType
][
labelKey
].
map
(
this
.
toFindQueryResult
);
const
refId
=
'handleLabelValuesQuery'
;
const
response
=
await
this
.
datasource
.
getLabels
(
selectedMetricType
,
refId
);
let
values
=
[];
if
(
response
.
meta
&&
response
.
meta
.
metricLabels
&&
response
.
meta
.
metricLabels
.
hasOwnProperty
(
labelKey
))
{
values
=
response
.
meta
.
metricLabels
[
labelKey
];
}
else
if
(
response
.
meta
&&
response
.
meta
.
resourceLabels
&&
response
.
meta
.
resourceLabels
.
hasOwnProperty
(
labelKey
))
{
values
=
response
.
meta
.
resourceLabels
[
labelKey
];
}
return
values
.
map
(
this
.
toFindQueryResult
);
}
async
handleResourceTypeQuery
({
selectedMetricType
})
{
...
...
@@ -62,7 +79,7 @@ export default class StackdriverMetricFindQuery {
}
const
refId
=
'handleResourceTypeQueryQueryType'
;
const
response
=
await
this
.
datasource
.
getLabels
(
selectedMetricType
,
refId
);
return
response
.
meta
.
resourceTypes
.
map
(
this
.
toFindQueryResult
)
;
return
response
.
meta
.
resourceTypes
?
response
.
meta
.
resourceTypes
.
map
(
this
.
toFindQueryResult
)
:
[]
;
}
async
handleAlignersQuery
({
selectedMetricType
})
{
...
...
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.test.tsx
View file @
26b1cc5d
...
...
@@ -34,9 +34,9 @@ describe('VariableQueryEditor', () => {
describe
(
'and an existing variable is edited'
,
()
=>
{
it
(
'should trigger new query using the saved query type'
,
done
=>
{
props
.
query
=
{
selectedQueryType
:
MetricFindQueryTypes
.
MetricLabel
s
};
props
.
query
=
{
selectedQueryType
:
MetricFindQueryTypes
.
LabelKey
s
};
props
.
onChange
=
(
query
,
definition
)
=>
{
expect
(
definition
).
toBe
(
'Stackdriver -
Metric Label
s'
);
expect
(
definition
).
toBe
(
'Stackdriver -
Labels Key
s'
);
done
();
};
renderer
.
create
(<
StackdriverVariableQueryEditor
{
...
props
}
/>).
toJSON
();
...
...
public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.tsx
View file @
26b1cc5d
...
...
@@ -8,8 +8,8 @@ import { MetricFindQueryTypes, VariableQueryData } from '../types';
export
class
StackdriverVariableQueryEditor
extends
PureComponent
<
VariableQueryProps
,
VariableQueryData
>
{
queryTypes
:
Array
<
{
value
:
string
;
name
:
string
}
>
=
[
{
value
:
MetricFindQueryTypes
.
MetricTypes
,
name
:
'Metric Types'
},
{
value
:
MetricFindQueryTypes
.
MetricLabels
,
name
:
'Metric Label
s'
},
{
value
:
MetricFindQueryTypes
.
ResourceLabels
,
name
:
'Resource Label
s'
},
{
value
:
MetricFindQueryTypes
.
LabelKeys
,
name
:
'Label Key
s'
},
{
value
:
MetricFindQueryTypes
.
LabelValues
,
name
:
'Label Value
s'
},
{
value
:
MetricFindQueryTypes
.
ResourceTypes
,
name
:
'Resource Types'
},
{
value
:
MetricFindQueryTypes
.
Aggregations
,
name
:
'Aggregations'
},
{
value
:
MetricFindQueryTypes
.
Aligners
,
name
:
'Aligners'
},
...
...
@@ -57,7 +57,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
metricTypes
,
selectedMetricType
,
metricDescriptors
,
...
await
this
.
getLabels
(
selectedMetricType
),
...
await
this
.
getLabel
Value
s
(
selectedMetricType
),
};
this
.
setState
(
state
);
}
...
...
@@ -65,7 +65,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
async
handleQueryTypeChange
(
event
)
{
const
state
:
any
=
{
selectedQueryType
:
event
.
target
.
value
,
...
await
this
.
getLabels
(
this
.
state
.
selectedMetricType
,
event
.
target
.
value
),
...
await
this
.
getLabel
Value
s
(
this
.
state
.
selectedMetricType
,
event
.
target
.
value
),
};
this
.
setState
(
state
);
}
...
...
@@ -80,13 +80,13 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
selectedService
:
event
.
target
.
value
,
metricTypes
,
selectedMetricType
,
...
await
this
.
getLabels
(
selectedMetricType
),
...
await
this
.
getLabel
Value
s
(
selectedMetricType
),
};
this
.
setState
(
state
);
}
async
onMetricTypeChange
(
event
)
{
const
state
:
any
=
{
selectedMetricType
:
event
.
target
.
value
,
...
await
this
.
getLabels
(
event
.
target
.
value
)
};
const
state
:
any
=
{
selectedMetricType
:
event
.
target
.
value
,
...
await
this
.
getLabel
Value
s
(
event
.
target
.
value
)
};
this
.
setState
(
state
);
}
...
...
@@ -100,16 +100,12 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
this
.
props
.
onChange
(
queryModel
,
`Stackdriver -
${
query
.
name
}
`
);
}
isLabelQuery
(
queryType
)
{
return
[
MetricFindQueryTypes
.
MetricLabels
,
MetricFindQueryTypes
.
ResourceLabels
].
indexOf
(
queryType
)
!==
-
1
;
}
async
getLabels
(
selectedMetricType
,
selectedQueryType
=
this
.
state
.
selectedQueryType
)
{
async
getLabelValues
(
selectedMetricType
,
selectedQueryType
=
this
.
state
.
selectedQueryType
)
{
let
result
=
{
labels
:
this
.
state
.
labels
,
labelKey
:
this
.
state
.
labelKey
};
if
(
selectedMetricType
&&
this
.
isLabelQuery
(
selectedQueryType
)
)
{
if
(
selectedMetricType
&&
selectedQueryType
===
MetricFindQueryTypes
.
LabelValues
)
{
const
refId
=
'StackdriverVariableQueryEditor'
;
const
response
=
await
this
.
props
.
datasource
.
getLabels
(
selectedMetricType
,
refId
);
const
labels
=
Object
.
keys
(
response
.
meta
[
selectedQueryType
])
;
const
labels
=
[...
Object
.
keys
(
response
.
meta
.
resourceLabels
),
...
Object
.
keys
(
response
.
meta
.
metricLabels
)]
;
const
labelKey
=
labels
.
some
(
l
=>
l
===
this
.
state
.
labelKey
)
?
this
.
state
.
labelKey
:
labels
[
0
];
result
=
{
labels
,
labelKey
};
}
...
...
@@ -127,8 +123,8 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
label=
"Services"
/>
);
case
MetricFindQueryTypes
.
MetricLabel
s
:
case
MetricFindQueryTypes
.
ResourceLabel
s
:
case
MetricFindQueryTypes
.
LabelKey
s
:
case
MetricFindQueryTypes
.
LabelValue
s
:
case
MetricFindQueryTypes
.
ResourceTypes
:
return
(
<
React
.
Fragment
>
...
...
@@ -144,16 +140,12 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
onValueChange=
{
e
=>
this
.
onMetricTypeChange
(
e
)
}
label=
"Metric Types"
/>
{
queryType
!==
MetricFindQueryTypes
.
ResourceTyp
es
&&
(
{
queryType
===
MetricFindQueryTypes
.
LabelValu
es
&&
(
<
SimpleSelect
value=
{
this
.
state
.
labelKey
}
options=
{
this
.
state
.
labels
.
map
(
l
=>
({
value
:
l
,
name
:
l
}))
}
onValueChange=
{
e
=>
this
.
onLabelKeyChange
(
e
)
}
label=
{
this
.
state
.
selectedQueryType
===
MetricFindQueryTypes
.
ResourceLabels
?
'Resource Label Key'
:
'Metric Label Key'
}
label=
"Label Keys"
/>
)
}
</
React
.
Fragment
>
...
...
public/app/plugins/datasource/stackdriver/types.ts
View file @
26b1cc5d
export
enum
MetricFindQueryTypes
{
MetricTypes
=
'metricTypes'
,
MetricLabels
=
'metricLabel
s'
,
ResourceLabels
=
'resourceLabel
s'
,
LabelKeys
=
'labelKey
s'
,
LabelValues
=
'labelValue
s'
,
ResourceTypes
=
'resourceTypes'
,
Aggregations
=
'aggregations'
,
Aligners
=
'aligners'
,
...
...
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