Commit 6abbf5b3 by Erik Sundell

stackdriver: refactoring request builder

parent 1756e82d
...@@ -283,7 +283,7 @@ func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) { ...@@ -283,7 +283,7 @@ func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) {
func (e *StackdriverExecutor) executeQuery(ctx context.Context, query *StackdriverQuery, tsdbQuery *tsdb.TsdbQuery) (*tsdb.QueryResult, StackdriverResponse, error) { func (e *StackdriverExecutor) executeQuery(ctx context.Context, query *StackdriverQuery, tsdbQuery *tsdb.TsdbQuery) (*tsdb.QueryResult, StackdriverResponse, error) {
queryResult := &tsdb.QueryResult{Meta: simplejson.New(), RefId: query.RefID} queryResult := &tsdb.QueryResult{Meta: simplejson.New(), RefId: query.RefID}
req, err := e.createRequest(ctx, e.dsInfo, "timeSeries") req, err := e.createRequest(ctx, e.dsInfo)
if err != nil { if err != nil {
queryResult.Error = err queryResult.Error = err
return queryResult, StackdriverResponse{}, nil return queryResult, StackdriverResponse{}, nil
...@@ -550,7 +550,7 @@ func calcBucketBound(bucketOptions StackdriverBucketOptions, n int) string { ...@@ -550,7 +550,7 @@ func calcBucketBound(bucketOptions StackdriverBucketOptions, n int) string {
return bucketBound return bucketBound
} }
func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.DataSource, endpointName string) (*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")
...@@ -578,7 +578,7 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models. ...@@ -578,7 +578,7 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
} }
projectName := dsInfo.JsonData.Get("defaultProject").MustString() projectName := dsInfo.JsonData.Get("defaultProject").MustString()
proxyPass := fmt.Sprintf("stackdriver%s", "v3/projects/"+projectName+"/"+endpointName) proxyPass := fmt.Sprintf("stackdriver%s", "v3/projects/"+projectName+"/timeSeries")
pluginproxy.ApplyRoute(ctx, req, proxyPass, stackdriverRoute, dsInfo) pluginproxy.ApplyRoute(ctx, req, proxyPass, stackdriverRoute, dsInfo)
...@@ -591,10 +591,8 @@ func (e *StackdriverExecutor) getDefaultProject(ctx context.Context) (string, er ...@@ -591,10 +591,8 @@ func (e *StackdriverExecutor) getDefaultProject(ctx context.Context) (string, er
defaultCredentials, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/monitoring.read") defaultCredentials, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/monitoring.read")
if err != nil { if err != nil {
return "", fmt.Errorf("Failed to retrieve default project from GCE metadata server. error: %v", err) return "", fmt.Errorf("Failed to retrieve default project from GCE metadata server. error: %v", err)
} else { }
return defaultCredentials.ProjectID, nil return defaultCredentials.ProjectID, nil
} }
} else {
return e.dsInfo.JsonData.Get("defaultProject").MustString(), nil return e.dsInfo.JsonData.Get("defaultProject").MustString(), nil
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment