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
12888600
Commit
12888600
authored
Sep 10, 2018
by
Erik Sundell
Committed by
Daniel Lee
Sep 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stackdriver: Break out parse response to its own func
parent
56e8e504
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
pkg/tsdb/stackdriver/stackdriver.go
+22
-16
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
12888600
...
...
@@ -108,31 +108,19 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
return
nil
,
err
}
data
,
err
:=
e
.
parse
Response
(
res
)
data
,
err
:=
e
.
unmarshal
Response
(
res
)
if
err
!=
nil
{
return
nil
,
err
}
queryRes
:=
tsdb
.
NewQueryResult
()
queryRes
.
RefId
=
query
.
RefId
for
_
,
series
:=
range
data
.
TimeSeries
{
points
:=
make
([]
tsdb
.
TimePoint
,
0
)
for
_
,
point
:=
range
series
.
Points
{
points
=
append
(
points
,
tsdb
.
NewTimePoint
(
null
.
FloatFrom
(
point
.
Value
.
DoubleValue
),
float64
((
point
.
Interval
.
EndTime
)
.
Unix
())
*
1000
))
}
queryRes
.
Series
=
append
(
queryRes
.
Series
,
&
tsdb
.
TimeSeries
{
Name
:
series
.
Metric
.
Type
,
Points
:
points
,
})
}
queryRes
,
err
:=
e
.
parseResponse
(
data
,
query
.
RefId
)
result
.
Results
[
query
.
RefId
]
=
queryRes
}
return
result
,
nil
}
func
(
e
*
StackdriverExecutor
)
parse
Response
(
res
*
http
.
Response
)
(
StackDriverResponse
,
error
)
{
func
(
e
*
StackdriverExecutor
)
unmarshal
Response
(
res
*
http
.
Response
)
(
StackDriverResponse
,
error
)
{
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
if
err
!=
nil
{
...
...
@@ -147,13 +135,31 @@ func (e *StackdriverExecutor) parseResponse(res *http.Response) (StackDriverResp
var
data
StackDriverResponse
err
=
json
.
Unmarshal
(
body
,
&
data
)
if
err
!=
nil
{
glog
.
Info
(
"Failed to unmarshal
graphite
response"
,
"error"
,
err
,
"status"
,
res
.
Status
,
"body"
,
string
(
body
))
glog
.
Info
(
"Failed to unmarshal
Stackdriver
response"
,
"error"
,
err
,
"status"
,
res
.
Status
,
"body"
,
string
(
body
))
return
StackDriverResponse
{},
err
}
return
data
,
nil
}
func
(
e
*
StackdriverExecutor
)
parseResponse
(
data
StackDriverResponse
,
queryRefId
string
)
(
*
tsdb
.
QueryResult
,
error
)
{
queryRes
:=
tsdb
.
NewQueryResult
()
queryRes
.
RefId
=
queryRefId
for
_
,
series
:=
range
data
.
TimeSeries
{
points
:=
make
([]
tsdb
.
TimePoint
,
0
)
for
_
,
point
:=
range
series
.
Points
{
points
=
append
(
points
,
tsdb
.
NewTimePoint
(
null
.
FloatFrom
(
point
.
Value
.
DoubleValue
),
float64
((
point
.
Interval
.
EndTime
)
.
Unix
())
*
1000
))
}
queryRes
.
Series
=
append
(
queryRes
.
Series
,
&
tsdb
.
TimeSeries
{
Name
:
series
.
Metric
.
Type
,
Points
:
points
,
})
}
return
queryRes
,
nil
}
func
(
e
*
StackdriverExecutor
)
createRequest
(
ctx
context
.
Context
,
dsInfo
*
models
.
DataSource
)
(
*
http
.
Request
,
error
)
{
u
,
_
:=
url
.
Parse
(
dsInfo
.
Url
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"render"
)
...
...
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