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
102f531c
Commit
102f531c
authored
Oct 08, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: break out project name resolving into its own function in the stackdriver.go file
parent
3f9ed2ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
pkg/tsdb/stackdriver/stackdriver.go
+26
-3
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
102f531c
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/oauth2/google"
"github.com/grafana/grafana/pkg/api/pluginproxy"
"github.com/grafana/grafana/pkg/api/pluginproxy"
"github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/null"
...
@@ -518,6 +519,23 @@ func replaceWithMetricPart(metaPartName string, metricType string) []byte {
...
@@ -518,6 +519,23 @@ func replaceWithMetricPart(metaPartName string, metricType string) []byte {
return
nil
return
nil
}
}
func
getProjectName
(
ctx
context
.
Context
,
dsInfo
*
models
.
DataSource
,
route
*
plugins
.
AppPluginRoute
)
(
string
,
error
)
{
var
projectName
string
gceAutoAuthentication
:=
dsInfo
.
JsonData
.
Get
(
"gceAutoAuthentication"
)
.
MustBool
()
if
gceAutoAuthentication
{
defaultCredentials
,
err
:=
google
.
FindDefaultCredentials
(
ctx
,
route
.
JwtTokenAuth
.
Scopes
...
)
if
err
!=
nil
{
return
""
,
err
}
else
{
projectName
=
defaultCredentials
.
ProjectID
}
}
else
{
projectName
=
dsInfo
.
JsonData
.
Get
(
"defaultProject"
)
.
MustString
()
}
logger
.
Info
(
"projectName"
,
"projectName"
,
projectName
)
return
projectName
,
nil
}
func
calcBucketBound
(
bucketOptions
StackdriverBucketOptions
,
n
int
)
string
{
func
calcBucketBound
(
bucketOptions
StackdriverBucketOptions
,
n
int
)
string
{
bucketBound
:=
"0"
bucketBound
:=
"0"
if
n
==
0
{
if
n
==
0
{
...
@@ -552,9 +570,6 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
...
@@ -552,9 +570,6 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
if
!
ok
{
if
!
ok
{
return
nil
,
errors
.
New
(
"Unable to find datasource plugin Stackdriver"
)
return
nil
,
errors
.
New
(
"Unable to find datasource plugin Stackdriver"
)
}
}
projectName
:=
dsInfo
.
JsonData
.
Get
(
"defaultProject"
)
.
MustString
()
logger
.
Info
(
"projectName"
,
"projectName"
,
projectName
)
proxyPass
:=
fmt
.
Sprintf
(
"stackdriver%s"
,
"v3/projects/"
+
projectName
+
"/timeSeries"
)
var
stackdriverRoute
*
plugins
.
AppPluginRoute
var
stackdriverRoute
*
plugins
.
AppPluginRoute
for
_
,
route
:=
range
plugin
.
Routes
{
for
_
,
route
:=
range
plugin
.
Routes
{
...
@@ -564,6 +579,14 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
...
@@ -564,6 +579,14 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
}
}
}
}
// projectName := dsInfo.JsonData.Get("defaultProject").MustString()
// logger.Info("projectName", "projectName", projectName)
projectName
,
err
:=
getProjectName
(
ctx
,
dsInfo
,
stackdriverRoute
)
if
err
!=
nil
{
return
nil
,
err
}
proxyPass
:=
fmt
.
Sprintf
(
"stackdriver%s"
,
"v3/projects/"
+
projectName
+
"/timeSeries"
)
pluginproxy
.
ApplyRoute
(
ctx
,
req
,
proxyPass
,
stackdriverRoute
,
dsInfo
)
pluginproxy
.
ApplyRoute
(
ctx
,
req
,
proxyPass
,
stackdriverRoute
,
dsInfo
)
return
req
,
nil
return
req
,
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