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
1a329e4e
Commit
1a329e4e
authored
Oct 11, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: remove test datasource query. use ensuredefaultproject instead
parent
b02a8127
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
98 deletions
+26
-98
pkg/tsdb/stackdriver/ensure_default_project.go
+24
-0
pkg/tsdb/stackdriver/stackdriver.go
+2
-4
pkg/tsdb/stackdriver/test_datasource_query.go
+0
-94
No files found.
pkg/tsdb/stackdriver/ensure_default_project.go
0 → 100644
View file @
1a329e4e
package
stackdriver
import
(
"context"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
)
func
(
e
*
StackdriverExecutor
)
ensureDefaultProject
(
ctx
context
.
Context
,
tsdbQuery
*
tsdb
.
TsdbQuery
)
(
*
tsdb
.
Response
,
error
)
{
queryResult
:=
&
tsdb
.
QueryResult
{
Meta
:
simplejson
.
New
(),
RefId
:
tsdbQuery
.
Queries
[
0
]
.
RefId
}
result
:=
&
tsdb
.
Response
{
Results
:
make
(
map
[
string
]
*
tsdb
.
QueryResult
),
}
defaultProject
,
err
:=
e
.
getDefaultProject
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
e
.
dsInfo
.
JsonData
.
Set
(
"defaultProject"
,
defaultProject
)
queryResult
.
Meta
.
Set
(
"defaultProject"
,
defaultProject
)
result
.
Results
[
tsdbQuery
.
Queries
[
0
]
.
RefId
]
=
queryResult
return
result
,
nil
}
pkg/tsdb/stackdriver/stackdriver.go
View file @
1a329e4e
...
@@ -77,10 +77,8 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
...
@@ -77,10 +77,8 @@ func (e *StackdriverExecutor) Query(ctx context.Context, dsInfo *models.DataSour
switch
queryType
{
switch
queryType
{
case
"annotationQuery"
:
case
"annotationQuery"
:
result
,
err
=
e
.
executeAnnotationQuery
(
ctx
,
tsdbQuery
)
result
,
err
=
e
.
executeAnnotationQuery
(
ctx
,
tsdbQuery
)
case
"testDatasource"
:
case
"ensureDefaultProjectQuery"
:
result
,
err
=
e
.
executeTestDataSource
(
ctx
,
tsdbQuery
)
result
,
err
=
e
.
ensureDefaultProject
(
ctx
,
tsdbQuery
)
case
"defaultProject"
:
result
,
err
=
e
.
getGceDefaultProject
(
ctx
,
tsdbQuery
)
case
"timeSeriesQuery"
:
case
"timeSeriesQuery"
:
fallthrough
fallthrough
default
:
default
:
...
...
pkg/tsdb/stackdriver/test_datasource_query.go
deleted
100644 → 0
View file @
b02a8127
package
stackdriver
import
(
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"github.com/grafana/grafana/pkg/components/simplejson"
"golang.org/x/net/context/ctxhttp"
"github.com/grafana/grafana/pkg/tsdb"
)
func
(
e
*
StackdriverExecutor
)
executeTestDataSource
(
ctx
context
.
Context
,
tsdbQuery
*
tsdb
.
TsdbQuery
)
(
*
tsdb
.
Response
,
error
)
{
queryResult
:=
&
tsdb
.
QueryResult
{
Meta
:
simplejson
.
New
(),
RefId
:
tsdbQuery
.
Queries
[
0
]
.
RefId
}
result
:=
&
tsdb
.
Response
{
Results
:
make
(
map
[
string
]
*
tsdb
.
QueryResult
),
}
authenticationType
:=
e
.
dsInfo
.
JsonData
.
Get
(
"authenticationType"
)
.
MustString
(
jwtAuthentication
)
if
authenticationType
==
gceAuthentication
{
defaultProject
,
err
:=
e
.
getDefaultProject
(
ctx
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Failed to retrieve default project from GCE metadata server. error: %v"
,
err
)
}
e
.
dsInfo
.
JsonData
.
Set
(
"defaultProject"
,
defaultProject
)
}
req
,
err
:=
e
.
createRequest
(
ctx
,
e
.
dsInfo
,
"metricDescriptors"
)
if
err
!=
nil
{
slog
.
Error
(
"Failed to create request"
,
"error"
,
err
)
return
nil
,
fmt
.
Errorf
(
"Failed to create request. error: %v"
,
err
)
}
res
,
err
:=
ctxhttp
.
Do
(
ctx
,
e
.
httpClient
,
req
)
if
err
!=
nil
{
return
nil
,
err
}
data
,
err
:=
e
.
unmarshalMetricDescriptors
(
res
)
if
err
!=
nil
{
return
nil
,
err
}
parts
:=
strings
.
Split
(
req
.
URL
.
Path
,
"/"
)
defaultProject
:=
parts
[
3
]
table
:=
transformMetricDescriptorResponseToTable
(
data
)
queryResult
.
Tables
=
append
(
queryResult
.
Tables
,
table
)
result
.
Results
[
tsdbQuery
.
Queries
[
0
]
.
RefId
]
=
queryResult
result
.
Results
[
tsdbQuery
.
Queries
[
0
]
.
RefId
]
.
Meta
.
Set
(
"defaultProject"
,
defaultProject
)
return
result
,
nil
}
func
transformMetricDescriptorResponseToTable
(
data
MetricDescriptorsResponse
)
*
tsdb
.
Table
{
table
:=
&
tsdb
.
Table
{
Columns
:
make
([]
tsdb
.
TableColumn
,
1
),
Rows
:
make
([]
tsdb
.
RowValues
,
0
),
}
table
.
Columns
[
0
]
.
Text
=
"metricDescriptor"
for
_
,
r
:=
range
data
.
MetricDescriptors
{
values
:=
make
([]
interface
{},
1
)
values
[
0
]
=
r
table
.
Rows
=
append
(
table
.
Rows
,
values
)
}
return
table
}
func
(
e
*
StackdriverExecutor
)
unmarshalMetricDescriptors
(
res
*
http
.
Response
)
(
MetricDescriptorsResponse
,
error
)
{
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
defer
res
.
Body
.
Close
()
if
err
!=
nil
{
return
MetricDescriptorsResponse
{},
err
}
if
res
.
StatusCode
/
100
!=
2
{
slog
.
Error
(
"Request failed"
,
"status"
,
res
.
Status
,
"body"
,
string
(
body
))
return
MetricDescriptorsResponse
{},
fmt
.
Errorf
(
`%s`
,
string
(
body
))
}
var
data
MetricDescriptorsResponse
err
=
json
.
Unmarshal
(
body
,
&
data
)
if
err
!=
nil
{
slog
.
Error
(
"Failed to unmarshal MetricDescriptorResponse"
,
"error"
,
err
,
"status"
,
res
.
Status
,
"body"
,
string
(
body
))
return
MetricDescriptorsResponse
{},
err
}
return
data
,
nil
}
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