Ver Fonte

Merge pull request #2654 from Sean-Holcomb/sth/athena-tag-special-character-fix

Wrap unknown tag columns in double qotes
Sean Holcomb há 2 anos atrás
pai
commit
dc4d24fdbd
1 ficheiros alterados com 8 adições e 3 exclusões
  1. 8 3
      pkg/cloud/aws/athenaintegration.go

+ 8 - 3
pkg/cloud/aws/athenaintegration.go

@@ -94,8 +94,9 @@ func (ai *AthenaIntegration) GetCloudCost(start, end time.Time) (*opencost.Cloud
 	// of columns to query.
 	for column := range allColumns {
 		if strings.HasPrefix(column, LabelColumnPrefix) {
-			groupByColumns = append(groupByColumns, column)
-			aqi.TagColumns = append(aqi.TagColumns, column)
+			quotedTag := fmt.Sprintf(`"%s"`, column)
+			groupByColumns = append(groupByColumns, quotedTag)
+			aqi.TagColumns = append(aqi.TagColumns, quotedTag)
 		}
 	}
 	var selectColumns []string
@@ -334,7 +335,11 @@ func (ai *AthenaIntegration) RowToCloudCost(row types.Row, aqi AthenaQueryIndexe
 	labels := opencost.CloudCostLabels{}
 	labelValues := []string{}
 	for _, tagColumnName := range aqi.TagColumns {
-		labelName := strings.TrimPrefix(tagColumnName, LabelColumnPrefix)
+		// remove quotes
+		labelName := strings.TrimPrefix(tagColumnName, `"`)
+		labelName = strings.TrimSuffix(tagColumnName, `"`)
+		// remove prefix
+		labelName = strings.TrimPrefix(tagColumnName, LabelColumnPrefix)
 		value := GetAthenaRowValue(row, aqi.ColumnIndexes, tagColumnName)
 		if value != "" {
 			labels[labelName] = value