mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: use constant instead of variable
This commit is contained in:
@@ -31,10 +31,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
slog log.Logger
|
slog log.Logger
|
||||||
legendKeyFormat *regexp.Regexp
|
legendKeyFormat *regexp.Regexp
|
||||||
metricNameFormat *regexp.Regexp
|
metricNameFormat *regexp.Regexp
|
||||||
gceAuthentication string
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
gceAuthentication string = "gce"
|
||||||
|
jwtAuthentication string = "jwt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StackdriverExecutor executes queries for the Stackdriver datasource
|
// StackdriverExecutor executes queries for the Stackdriver datasource
|
||||||
@@ -61,7 +65,6 @@ func init() {
|
|||||||
tsdb.RegisterTsdbQueryEndpoint("stackdriver", NewStackdriverExecutor)
|
tsdb.RegisterTsdbQueryEndpoint("stackdriver", NewStackdriverExecutor)
|
||||||
legendKeyFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`)
|
legendKeyFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`)
|
||||||
metricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/(.+)`)
|
metricNameFormat = regexp.MustCompile(`([\w\d_]+)\.googleapis\.com/(.+)`)
|
||||||
gceAuthentication = "gce"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query takes in the frontend queries, parses them into the Stackdriver query format
|
// Query takes in the frontend queries, parses them into the Stackdriver query format
|
||||||
@@ -93,7 +96,7 @@ func (e *StackdriverExecutor) executeTimeSeriesQuery(ctx context.Context, tsdbQu
|
|||||||
Results: make(map[string]*tsdb.QueryResult),
|
Results: make(map[string]*tsdb.QueryResult),
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticationType := e.dsInfo.JsonData.Get("authenticationType").MustString("jwt")
|
authenticationType := e.dsInfo.JsonData.Get("authenticationType").MustString(jwtAuthentication)
|
||||||
if authenticationType == gceAuthentication {
|
if authenticationType == gceAuthentication {
|
||||||
defaultProject, err := e.getDefaultProject(ctx)
|
defaultProject, err := e.getDefaultProject(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -586,7 +589,7 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *StackdriverExecutor) getDefaultProject(ctx context.Context) (string, error) {
|
func (e *StackdriverExecutor) getDefaultProject(ctx context.Context) (string, error) {
|
||||||
authenticationType := e.dsInfo.JsonData.Get("authenticationType").MustString("jwt")
|
authenticationType := e.dsInfo.JsonData.Get("authenticationType").MustString(jwtAuthentication)
|
||||||
if authenticationType == gceAuthentication {
|
if authenticationType == gceAuthentication {
|
||||||
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 {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (e *StackdriverExecutor) executeTestDataSource(ctx context.Context, tsdbQue
|
|||||||
Results: make(map[string]*tsdb.QueryResult),
|
Results: make(map[string]*tsdb.QueryResult),
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticationType := e.dsInfo.JsonData.Get("authenticationType").MustString("jwt")
|
authenticationType := e.dsInfo.JsonData.Get("authenticationType").MustString(jwtAuthentication)
|
||||||
if authenticationType == gceAuthentication {
|
if authenticationType == gceAuthentication {
|
||||||
defaultProject, err := e.getDefaultProject(ctx)
|
defaultProject, err := e.getDefaultProject(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user