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
5763d3ca
Commit
5763d3ca
authored
Sep 13, 2018
by
Erik Sundell
Committed by
Daniel Lee
Sep 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: make sure distinct labels are returned. also added test
parent
37fe488b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
pkg/tsdb/stackdriver/stackdriver.go
+19
-3
pkg/tsdb/stackdriver/stackdriver_test.go
+16
-2
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
5763d3ca
...
@@ -212,7 +212,7 @@ func (e *StackdriverExecutor) unmarshalResponse(res *http.Response) (StackDriver
...
@@ -212,7 +212,7 @@ func (e *StackdriverExecutor) unmarshalResponse(res *http.Response) (StackDriver
func
(
e
*
StackdriverExecutor
)
parseResponse
(
queryRes
*
tsdb
.
QueryResult
,
data
StackDriverResponse
)
error
{
func
(
e
*
StackdriverExecutor
)
parseResponse
(
queryRes
*
tsdb
.
QueryResult
,
data
StackDriverResponse
)
error
{
metricLabels
:=
make
(
map
[
string
][]
string
)
metricLabels
:=
make
(
map
[
string
][]
string
)
//
resourceLabels := make(map[string][]string)
resourceLabels
:=
make
(
map
[
string
][]
string
)
for
_
,
series
:=
range
data
.
TimeSeries
{
for
_
,
series
:=
range
data
.
TimeSeries
{
points
:=
make
([]
tsdb
.
TimePoint
,
0
)
points
:=
make
([]
tsdb
.
TimePoint
,
0
)
...
@@ -225,11 +225,17 @@ func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data Sta
...
@@ -225,11 +225,17 @@ func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data Sta
metricName
:=
series
.
Metric
.
Type
metricName
:=
series
.
Metric
.
Type
for
key
,
value
:=
range
series
.
Metric
.
Labels
{
for
key
,
value
:=
range
series
.
Metric
.
Labels
{
metricLabels
[
key
]
=
append
(
metricLabels
[
key
],
value
)
if
!
containsLabel
(
metricLabels
[
key
],
value
)
{
metricLabels
[
key
]
=
append
(
metricLabels
[
key
],
value
)
}
metricName
+=
" "
+
value
metricName
+=
" "
+
value
}
}
// queryRes.Meta.Set("resourceLabels", series.Resource.Labels)
for
key
,
value
:=
range
series
.
Resource
.
Labels
{
if
!
containsLabel
(
resourceLabels
[
key
],
value
)
{
resourceLabels
[
key
]
=
append
(
resourceLabels
[
key
],
value
)
}
}
queryRes
.
Series
=
append
(
queryRes
.
Series
,
&
tsdb
.
TimeSeries
{
queryRes
.
Series
=
append
(
queryRes
.
Series
,
&
tsdb
.
TimeSeries
{
Name
:
metricName
,
Name
:
metricName
,
...
@@ -237,11 +243,21 @@ func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data Sta
...
@@ -237,11 +243,21 @@ func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data Sta
})
})
}
}
queryRes
.
Meta
.
Set
(
"resourceLabels"
,
resourceLabels
)
queryRes
.
Meta
.
Set
(
"metricLabels"
,
metricLabels
)
queryRes
.
Meta
.
Set
(
"metricLabels"
,
metricLabels
)
return
nil
return
nil
}
}
func
containsLabel
(
labels
[]
string
,
newLabel
string
)
bool
{
for
_
,
val
:=
range
labels
{
if
val
==
newLabel
{
return
true
}
}
return
false
}
func
(
e
*
StackdriverExecutor
)
createRequest
(
ctx
context
.
Context
,
dsInfo
*
models
.
DataSource
)
(
*
http
.
Request
,
error
)
{
func
(
e
*
StackdriverExecutor
)
createRequest
(
ctx
context
.
Context
,
dsInfo
*
models
.
DataSource
)
(
*
http
.
Request
,
error
)
{
u
,
_
:=
url
.
Parse
(
dsInfo
.
Url
)
u
,
_
:=
url
.
Parse
(
dsInfo
.
Url
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"render"
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"render"
)
...
...
pkg/tsdb/stackdriver/stackdriver_test.go
View file @
5763d3ca
...
@@ -152,8 +152,22 @@ func TestStackdriver(t *testing.T) {
...
@@ -152,8 +152,22 @@ func TestStackdriver(t *testing.T) {
})
})
Convey
(
"Should add meta for labels to the response"
,
func
()
{
Convey
(
"Should add meta for labels to the response"
,
func
()
{
instanceName
:=
res
.
Meta
.
Get
(
"metricLabels"
)
.
MustMap
()[
"instance_name"
]
metricLabels
:=
res
.
Meta
.
Get
(
"metricLabels"
)
.
Interface
()
.
(
map
[
string
][]
string
)
So
(
instanceName
,
ShouldNotBeNil
)
So
(
metricLabels
,
ShouldNotBeNil
)
So
(
len
(
metricLabels
[
"instance_name"
]),
ShouldEqual
,
3
)
So
(
metricLabels
[
"instance_name"
][
0
],
ShouldEqual
,
"collector-asia-east-1"
)
So
(
metricLabels
[
"instance_name"
][
1
],
ShouldEqual
,
"collector-europe-west-1"
)
So
(
metricLabels
[
"instance_name"
][
2
],
ShouldEqual
,
"collector-us-east-1"
)
resourceLabels
:=
res
.
Meta
.
Get
(
"resourceLabels"
)
.
Interface
()
.
(
map
[
string
][]
string
)
So
(
resourceLabels
,
ShouldNotBeNil
)
So
(
len
(
resourceLabels
[
"zone"
]),
ShouldEqual
,
3
)
So
(
resourceLabels
[
"zone"
][
0
],
ShouldEqual
,
"asia-east1-a"
)
So
(
resourceLabels
[
"zone"
][
1
],
ShouldEqual
,
"europe-west1-b"
)
So
(
resourceLabels
[
"zone"
][
2
],
ShouldEqual
,
"us-east1-b"
)
So
(
len
(
resourceLabels
[
"project_id"
]),
ShouldEqual
,
1
)
So
(
resourceLabels
[
"project_id"
][
0
],
ShouldEqual
,
"grafana-prod"
)
})
})
})
})
})
})
...
...
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