CloudWatch: Deprecate dynamic labels feature toggle, remove support for Alias in backend (#66494)
This commit is contained in:
@@ -63,7 +63,6 @@ type CloudWatchQuery struct {
|
||||
ReturnData bool
|
||||
Dimensions map[string][]string
|
||||
Period int
|
||||
Alias string
|
||||
Label string
|
||||
MatchExact bool
|
||||
UsedExpression string
|
||||
@@ -150,7 +149,7 @@ func (q *CloudWatchQuery) IsMultiValuedDimensionExpression() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (q *CloudWatchQuery) BuildDeepLink(startTime time.Time, endTime time.Time, dynamicLabelEnabled bool) (string, error) {
|
||||
func (q *CloudWatchQuery) BuildDeepLink(startTime time.Time, endTime time.Time) (string, error) {
|
||||
if q.IsMathExpression() || q.MetricQueryType == MetricQueryTypeQuery {
|
||||
return "", nil
|
||||
}
|
||||
@@ -166,9 +165,7 @@ func (q *CloudWatchQuery) BuildDeepLink(startTime time.Time, endTime time.Time,
|
||||
|
||||
if q.isSearchExpression() {
|
||||
metricExpressions := &metricExpression{Expression: q.UsedExpression}
|
||||
if dynamicLabelEnabled {
|
||||
metricExpressions.Label = q.Label
|
||||
}
|
||||
metricExpressions.Label = q.Label
|
||||
link.Metrics = []interface{}{metricExpressions}
|
||||
} else {
|
||||
metricStat := []interface{}{q.Namespace, q.MetricName}
|
||||
@@ -179,9 +176,7 @@ func (q *CloudWatchQuery) BuildDeepLink(startTime time.Time, endTime time.Time,
|
||||
Stat: q.Statistic,
|
||||
Period: q.Period,
|
||||
}
|
||||
if dynamicLabelEnabled {
|
||||
metricStatMeta.Label = q.Label
|
||||
}
|
||||
metricStatMeta.Label = q.Label
|
||||
if q.AccountId != nil {
|
||||
metricStatMeta.AccountId = *q.AccountId
|
||||
}
|
||||
@@ -221,7 +216,7 @@ type metricsDataQuery struct {
|
||||
|
||||
// ParseMetricDataQueries decodes the metric data queries json, validates, sets default values and returns an array of CloudWatchQueries.
|
||||
// The CloudWatchQuery has a 1 to 1 mapping to a query editor row
|
||||
func ParseMetricDataQueries(dataQueries []backend.DataQuery, startTime time.Time, endTime time.Time, defaultRegion string, logger log.Logger, dynamicLabelsEnabled,
|
||||
func ParseMetricDataQueries(dataQueries []backend.DataQuery, startTime time.Time, endTime time.Time, defaultRegion string, logger log.Logger,
|
||||
crossAccountQueryingEnabled bool) ([]*CloudWatchQuery, error) {
|
||||
var metricDataQueries = make(map[string]metricsDataQuery)
|
||||
for _, query := range dataQueries {
|
||||
@@ -251,10 +246,6 @@ func ParseMetricDataQueries(dataQueries []backend.DataQuery, startTime time.Time
|
||||
TimezoneUTCOffset: mdq.TimezoneUTCOffset,
|
||||
}
|
||||
|
||||
if mdq.Alias != nil {
|
||||
cwQuery.Alias = *mdq.Alias
|
||||
}
|
||||
|
||||
if mdq.MetricName != nil {
|
||||
cwQuery.MetricName = *mdq.MetricName
|
||||
}
|
||||
@@ -271,13 +262,17 @@ func ParseMetricDataQueries(dataQueries []backend.DataQuery, startTime time.Time
|
||||
cwQuery.Expression = *mdq.Expression
|
||||
}
|
||||
|
||||
if mdq.Label != nil {
|
||||
cwQuery.Label = *mdq.Label
|
||||
}
|
||||
|
||||
if err := cwQuery.validateAndSetDefaults(refId, mdq, startTime, endTime, defaultRegion, crossAccountQueryingEnabled); err != nil {
|
||||
return nil, &QueryError{Err: err, RefID: refId}
|
||||
}
|
||||
|
||||
cwQuery.applyMacros(startTime, endTime)
|
||||
|
||||
cwQuery.migrateLegacyQuery(mdq, dynamicLabelsEnabled)
|
||||
cwQuery.migrateLegacyQuery(mdq)
|
||||
|
||||
result = append(result, cwQuery)
|
||||
}
|
||||
@@ -291,9 +286,9 @@ func (q *CloudWatchQuery) applyMacros(startTime, endTime time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
func (q *CloudWatchQuery) migrateLegacyQuery(query metricsDataQuery, dynamicLabelsEnabled bool) {
|
||||
func (q *CloudWatchQuery) migrateLegacyQuery(query metricsDataQuery) {
|
||||
q.Statistic = getStatistic(query)
|
||||
q.Label = getLabel(query, dynamicLabelsEnabled)
|
||||
q.Label = getLabel(query)
|
||||
}
|
||||
|
||||
func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery metricsDataQuery, startTime, endTime time.Time,
|
||||
@@ -386,33 +381,33 @@ var aliasPatterns = map[string]string{
|
||||
|
||||
var legacyAliasRegexp = regexp.MustCompile(`{{\s*(.+?)\s*}}`)
|
||||
|
||||
func getLabel(query metricsDataQuery, dynamicLabelsEnabled bool) string {
|
||||
func getLabel(query metricsDataQuery) string {
|
||||
deprecatedAlias := query.Alias //nolint:staticcheck
|
||||
|
||||
if query.Label != nil {
|
||||
return *query.Label
|
||||
}
|
||||
if query.Alias != nil && *query.Alias == "" {
|
||||
if deprecatedAlias != nil && *deprecatedAlias == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
var result string
|
||||
if dynamicLabelsEnabled {
|
||||
fullAliasField := ""
|
||||
if query.Alias != nil {
|
||||
fullAliasField = *query.Alias
|
||||
}
|
||||
matches := legacyAliasRegexp.FindAllStringSubmatch(fullAliasField, -1)
|
||||
|
||||
for _, groups := range matches {
|
||||
fullMatch := groups[0]
|
||||
subgroup := groups[1]
|
||||
if dynamicLabel, ok := aliasPatterns[subgroup]; ok {
|
||||
fullAliasField = strings.ReplaceAll(fullAliasField, fullMatch, dynamicLabel)
|
||||
} else {
|
||||
fullAliasField = strings.ReplaceAll(fullAliasField, fullMatch, fmt.Sprintf(`${PROP('Dim.%s')}`, subgroup))
|
||||
}
|
||||
}
|
||||
result = fullAliasField
|
||||
fullAliasField := ""
|
||||
if deprecatedAlias != nil {
|
||||
fullAliasField = *deprecatedAlias
|
||||
}
|
||||
matches := legacyAliasRegexp.FindAllStringSubmatch(fullAliasField, -1)
|
||||
|
||||
for _, groups := range matches {
|
||||
fullMatch := groups[0]
|
||||
subgroup := groups[1]
|
||||
if dynamicLabel, ok := aliasPatterns[subgroup]; ok {
|
||||
fullAliasField = strings.ReplaceAll(fullAliasField, fullMatch, dynamicLabel)
|
||||
} else {
|
||||
fullAliasField = strings.ReplaceAll(fullAliasField, fullMatch, fmt.Sprintf(`${PROP('Dim.%s')}`, subgroup))
|
||||
}
|
||||
}
|
||||
result = fullAliasField
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user