CloudWatch: Move logger to its own package and minor refactoring (#57107)
* Move log to its own package * Rename test-data to testdata * Change alias to string type * Remove parseQueries from a method of cloudWatchExecutor
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/cwlog"
|
||||
)
|
||||
|
||||
var validMetricDataID = regexp.MustCompile(`^[a-z][a-zA-Z0-9_]*$`)
|
||||
@@ -39,13 +39,13 @@ type QueryJson struct {
|
||||
TimezoneUTCOffset string `json:"timezoneUTCOffset,omitempty"`
|
||||
QueryType string `json:"type,omitempty"`
|
||||
Hide *bool `json:"hide,omitempty"`
|
||||
Alias *string `json:"alias,omitempty"`
|
||||
Alias string `json:"alias,omitempty"`
|
||||
}
|
||||
|
||||
// parseQueries parses the json queries and returns a map of cloudWatchQueries by region. The cloudWatchQuery has a 1 to 1 mapping to a query editor row
|
||||
func (e *cloudWatchExecutor) parseQueries(queries []backend.DataQuery, startTime time.Time, endTime time.Time) (map[string][]*cloudWatchQuery, error) {
|
||||
func parseQueries(queries []backend.DataQuery, startTime time.Time, endTime time.Time, dynamicLabelsEnabled bool) (map[string][]*cloudWatchQuery, error) {
|
||||
requestQueries := make(map[string][]*cloudWatchQuery)
|
||||
migratedQueries, err := migrateLegacyQuery(queries, e.features.IsEnabled(featuremgmt.FlagCloudWatchDynamicLabels))
|
||||
migratedQueries, err := migrateLegacyQuery(queries, dynamicLabelsEnabled)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -140,11 +140,10 @@ var aliasPatterns = map[string]string{
|
||||
var legacyAliasRegexp = regexp.MustCompile(`{{\s*(.+?)\s*}}`)
|
||||
|
||||
func migrateAliasToDynamicLabel(queryJson *QueryJson) {
|
||||
fullAliasField := ""
|
||||
fullAliasField := queryJson.Alias
|
||||
|
||||
if queryJson.Alias != nil && *queryJson.Alias != "" {
|
||||
matches := legacyAliasRegexp.FindAllStringSubmatch(*queryJson.Alias, -1)
|
||||
fullAliasField = *queryJson.Alias
|
||||
if fullAliasField != "" {
|
||||
matches := legacyAliasRegexp.FindAllStringSubmatch(fullAliasField, -1)
|
||||
|
||||
for _, groups := range matches {
|
||||
fullMatch := groups[0]
|
||||
@@ -160,9 +159,9 @@ func migrateAliasToDynamicLabel(queryJson *QueryJson) {
|
||||
}
|
||||
|
||||
func parseRequestQuery(model QueryJson, refId string, startTime time.Time, endTime time.Time) (*cloudWatchQuery, error) {
|
||||
plog.Debug("Parsing request query", "query", model)
|
||||
cwlog.Debug("Parsing request query", "query", model)
|
||||
cloudWatchQuery := cloudWatchQuery{
|
||||
Alias: "",
|
||||
Alias: model.Alias,
|
||||
Label: "",
|
||||
MatchExact: true,
|
||||
Statistic: "",
|
||||
@@ -256,10 +255,6 @@ func parseRequestQuery(model QueryJson, refId string, startTime time.Time, endTi
|
||||
cloudWatchQuery.MatchExact = *model.MatchExact
|
||||
}
|
||||
|
||||
if model.Alias != nil {
|
||||
cloudWatchQuery.Alias = *model.Alias
|
||||
}
|
||||
|
||||
if model.Label != nil {
|
||||
cloudWatchQuery.Label = *model.Label
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user