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
7f99a14c
Commit
7f99a14c
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: Parsed url params
parent
c8ec3a34
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
22 deletions
+44
-22
pkg/tsdb/stackdriver/stackdriver.go
+44
-22
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
7f99a14c
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"path"
"path"
"regexp"
"regexp"
"strings"
"strings"
"time"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/context/ctxhttp"
...
@@ -38,35 +39,57 @@ func init() {
...
@@ -38,35 +39,57 @@ func init() {
}
}
func
(
e
*
StackdriverExecutor
)
Query
(
ctx
context
.
Context
,
dsInfo
*
models
.
DataSource
,
tsdbQuery
*
tsdb
.
TsdbQuery
)
(
*
tsdb
.
Response
,
error
)
{
func
(
e
*
StackdriverExecutor
)
Query
(
ctx
context
.
Context
,
dsInfo
*
models
.
DataSource
,
tsdbQuery
*
tsdb
.
TsdbQuery
)
(
*
tsdb
.
Response
,
error
)
{
result
:=
&
tsdb
.
Response
{}
result
:=
&
tsdb
.
Response
{
logger
.
Info
(
"tsdbQuery"
,
"tsdbQuery"
,
tsdbQuery
)
Results
:
make
(
map
[
string
]
*
tsdb
.
QueryResult
),
from
:=
"-"
+
formatTimeRange
(
tsdbQuery
.
TimeRange
.
From
)
}
until
:=
formatTimeRange
(
tsdbQuery
.
TimeRange
.
To
)
// from := "-" + formatTimeRange(tsdbQuery.TimeRange.From)
// until := formatTimeRange(tsdbQuery.TimeRange.To)
var
target
string
var
target
string
startTime
,
err
:=
tsdbQuery
.
TimeRange
.
ParseFrom
()
if
err
!=
nil
{
return
nil
,
err
}
endTime
,
err
:=
tsdbQuery
.
TimeRange
.
ParseTo
()
if
err
!=
nil
{
return
nil
,
err
}
logger
.
Info
(
"tsdbQuery"
,
"req.URL.RawQuery"
,
tsdbQuery
.
TimeRange
.
From
)
formData
:=
url
.
Values
{
formData
:=
url
.
Values
{
"from"
:
[]
string
{
from
},
"interval.startTime"
:
[]
string
{
startTime
.
String
()},
"until"
:
[]
string
{
until
},
"interval.endTime"
:
[]
string
{
endTime
.
String
()},
"format"
:
[]
string
{
"json"
},
"aggregation.perSeriesAligner"
:
[]
string
{
"ALIGN_NONE"
},
"maxDataPoints"
:
[]
string
{
"500"
},
}
}
for
_
,
query
:=
range
tsdbQuery
.
Queries
{
for
i
,
query
:=
range
tsdbQuery
.
Queries
{
glog
.
Info
(
"stackdriver"
,
"query"
,
query
.
Model
)
if
fullTarget
,
err
:=
query
.
Model
.
Get
(
"targetFull"
)
.
String
();
err
==
nil
{
if
fullTarget
,
err
:=
query
.
Model
.
Get
(
"targetFull"
)
.
String
();
err
==
nil
{
target
=
fixIntervalFormat
(
fullTarget
)
target
=
fixIntervalFormat
(
fullTarget
)
}
else
{
}
else
{
target
=
fixIntervalFormat
(
query
.
Model
.
Get
(
"target"
)
.
MustString
())
target
=
fixIntervalFormat
(
query
.
Model
.
Get
(
"target"
)
.
MustString
())
}
}
}
formData
[
"target"
]
=
[]
string
{
target
}
if
setting
.
Env
==
setting
.
DEV
{
if
setting
.
Env
==
setting
.
DEV
{
glog
.
Debug
(
"Graphite
request"
,
"params"
,
formData
)
glog
.
Debug
(
"Stackdriver
request"
,
"params"
,
formData
)
}
}
req
,
err
:=
e
.
createRequest
(
dsInfo
,
formData
)
req
,
err
:=
e
.
createRequest
(
dsInfo
,
formData
)
RefId
:=
tsdbQuery
.
Queries
[
i
]
.
RefId
metricType
:=
query
.
Model
.
Get
(
"metricType"
)
.
MustString
()
// formData["metric.type"] = []string{metricType}
q
:=
req
.
URL
.
Query
()
q
.
Add
(
"interval.startTime"
,
startTime
.
UTC
()
.
Format
(
time
.
RFC3339
))
q
.
Add
(
"interval.endTime"
,
endTime
.
UTC
()
.
Format
(
time
.
RFC3339
))
q
.
Add
(
"aggregation.perSeriesAligner"
,
"ALIGN_NONE"
)
q
.
Add
(
"filter"
,
metricType
)
req
.
URL
.
RawQuery
=
q
.
Encode
()
logger
.
Info
(
"tsdbQuery"
,
"req.URL.RawQuery"
,
req
.
URL
.
RawQuery
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -78,8 +101,8 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
...
@@ -78,8 +101,8 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
span
,
ctx
:=
opentracing
.
StartSpanFromContext
(
ctx
,
"stackdriver query"
)
span
,
ctx
:=
opentracing
.
StartSpanFromContext
(
ctx
,
"stackdriver query"
)
span
.
SetTag
(
"target"
,
target
)
span
.
SetTag
(
"target"
,
target
)
span
.
SetTag
(
"from"
,
f
rom
)
span
.
SetTag
(
"from"
,
tsdbQuery
.
TimeRange
.
F
rom
)
span
.
SetTag
(
"until"
,
until
)
span
.
SetTag
(
"until"
,
tsdbQuery
.
TimeRange
.
To
)
span
.
SetTag
(
"datasource_id"
,
dsInfo
.
Id
)
span
.
SetTag
(
"datasource_id"
,
dsInfo
.
Id
)
span
.
SetTag
(
"org_id"
,
dsInfo
.
OrgId
)
span
.
SetTag
(
"org_id"
,
dsInfo
.
OrgId
)
...
@@ -100,8 +123,9 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
...
@@ -100,8 +123,9 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
return
nil
,
err
return
nil
,
err
}
}
result
.
Results
=
make
(
map
[
string
]
*
tsdb
.
QueryResult
)
//
result.Results = make(map[string]*tsdb.QueryResult)
queryRes
:=
tsdb
.
NewQueryResult
()
queryRes
:=
tsdb
.
NewQueryResult
()
queryRes
.
RefId
=
RefId
for
_
,
series
:=
range
data
.
TimeSeries
{
for
_
,
series
:=
range
data
.
TimeSeries
{
points
:=
make
([]
tsdb
.
TimePoint
,
0
)
points
:=
make
([]
tsdb
.
TimePoint
,
0
)
...
@@ -112,13 +136,10 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
...
@@ -112,13 +136,10 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
Name
:
series
.
Metric
.
Type
,
Name
:
series
.
Metric
.
Type
,
Points
:
points
,
Points
:
points
,
})
})
if
setting
.
Env
==
setting
.
DEV
{
glog
.
Debug
(
"Stackdriver response"
,
"target"
,
points
,
"datapoints"
,
len
(
points
))
}
}
result
.
Results
[
queryRes
.
RefId
]
=
queryRes
}
}
result
.
Results
[
"A"
]
=
queryRes
return
result
,
nil
return
result
,
nil
}
}
...
@@ -148,7 +169,8 @@ func (e *StackdriverExecutor) createRequest(dsInfo *models.DataSource, data url.
...
@@ -148,7 +169,8 @@ func (e *StackdriverExecutor) createRequest(dsInfo *models.DataSource, data url.
u
,
_
:=
url
.
Parse
(
dsInfo
.
Url
)
u
,
_
:=
url
.
Parse
(
dsInfo
.
Url
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"render"
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"render"
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"https://monitoring.googleapis.com/v3/projects/raintank-production/timeSeries?&filter=metric.type%20%3D%20%22compute.googleapis.com%2Finstance%2Fcpu%2Fusage_time%22&aggregation.perSeriesAligner=ALIGN_NONE&interval.startTime=2018-09-04T11%3A14%3A02.383Z&interval.endTime=2018-09-04T11%3A16%3A02.383Z"
,
nil
)
//?&filter=metric.type%20%3D%20%22compute.googleapis.com%2Finstance%2Fcpu%2Fusage_time%22&aggregation.perSeriesAligner=ALIGN_NONE&interval.startTime=2018-09-04T11%3A14%3A02.383Z&interval.endTime=2018-09-04T11%3A16%3A02.383Z
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"https://monitoring.googleapis.com/v3/projects/raintank-production/timeSeries"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Info
(
"Failed to create request"
,
"error"
,
err
)
glog
.
Info
(
"Failed to create request"
,
"error"
,
err
)
return
nil
,
fmt
.
Errorf
(
"Failed to create request. error: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"Failed to create request. error: %v"
,
err
)
...
...
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