Dashboard: Backend always set `metricEditorMode: 0` regardless `metricQueryType` and `expression` (#111613)

- Fix metricEditorMode logic to match frontend hasOwnProperty behavior
- Fix metricQueryType to only set when property doesn't exist
- Fix statistics processing to handle all types like frontend does
- Fix null statistic handling to match frontend behavior
- Fix object string representation to match JavaScript behavior
- Add comprehensive test coverage for all CloudWatch migration scenarios
- Achieve 100% backend-frontend consistency for v34 migration

* Fix v34 CloudWatch migration backend-frontend inconsistencies

- Fix metricEditorMode logic to match frontend hasOwnProperty behavior
- Fix metricQueryType to only set when property doesn't exist
- Fix statistics processing to handle all types like frontend does
- Fix null statistic handling to match frontend behavior
- Fix object string representation to match JavaScript behavior
- Add comprehensive test coverage for all CloudWatch migration scenarios
- Achieve 100% backend-frontend consistency for v34 migration

* Improve v34 CloudWatch migration test coverage

- Add targeted tests for hasOwnProperty logic coverage
- Add comprehensive getSuffixForStat coverage (all data types)
- Add generateNextRefId double letter generation tests
- Simplify test cases while maintaining full coverage
- Achieve 93%+ coverage on all critical v34 functions
- Remove redundant test cases for better maintainability

* Clean up v34 CloudWatch migration code

- Remove unnecessary comments and documentation
- Simplify function signatures and logic
- Maintain functionality while improving readability
- Keep essential logic intact with cleaner code

* Only remove unnecessary comments
This commit is contained in:
Ivan Ortega Alba 2025-09-29 11:35:58 +02:00 committed by GitHub
parent 512c292e04
commit 6d2fa6c583
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1297 additions and 153 deletions

View File

@ -1,6 +1,9 @@
package schemaversion
import "context"
import (
"context"
"fmt"
)
// V34 migrates CloudWatch queries that use multiple statistics into separate queries.
//
@ -113,9 +116,24 @@ func migrateCloudWatchQueriesInPanel(panel map[string]interface{}) {
continue
}
// Add CloudWatch fields if missing (set to 0 if not present)
t["metricEditorMode"] = GetIntValue(t, "metricEditorMode", 0)
t["metricQueryType"] = GetIntValue(t, "metricQueryType", 0)
// Add CloudWatch fields if missing (matches frontend migrateCloudWatchQuery logic)
if _, hasMetricQueryType := t["metricQueryType"]; !hasMetricQueryType {
t["metricQueryType"] = 0 // MetricQueryType.Search
}
if _, hasMetricEditorMode := t["metricEditorMode"]; !hasMetricEditorMode {
metricQueryType := GetIntValue(t, "metricQueryType", 0)
if metricQueryType == 1 { // MetricQueryType.Insights
t["metricEditorMode"] = 1 // MetricEditorMode.Code
} else {
expression := GetStringValue(t, "expression")
if expression != "" {
t["metricEditorMode"] = 1 // MetricEditorMode.Code
} else {
t["metricEditorMode"] = 0 // MetricEditorMode.Builder
}
}
}
// Get valid statistics (including null and empty strings)
validStats, isEmpty := getValidStatistics(t["statistics"])
@ -137,19 +155,20 @@ func migrateCloudWatchQueriesInPanel(panel map[string]interface{}) {
// No valid statistics - keep query as-is
newTargets = append(newTargets, t)
case 1:
// Single statistic - set statistic field if not null
if statString := GetStringValue(map[string]interface{}{"stat": validStats[0]}, "stat"); statString != "" {
t["statistic"] = statString
// Single statistic - set statistic field
// Frontend doesn't set statistic property for null values
if validStats[0] != nil {
t["statistic"] = validStats[0]
}
newTargets = append(newTargets, t)
default:
// Multiple statistics - create separate queries
for i, stat := range validStats {
newQuery := copyMap(t)
// Set statistic field
// Frontend doesn't set statistic property for null values
if stat != nil {
if statString, ok := stat.(string); ok {
newQuery["statistic"] = statString
}
newQuery["statistic"] = stat
}
if i == 0 {
@ -210,10 +229,11 @@ func migrateCloudWatchAnnotationQueries(dashboard map[string]interface{}) {
delete(a, "statistics")
annotationsList[i] = a
case 1:
// Single statistic - set statistic field if not null
// Single statistic - set statistic field (matches frontend behavior)
delete(a, "statistics")
if statString := GetStringValue(map[string]interface{}{"stat": validStats[0]}, "stat"); statString != "" {
a["statistic"] = statString
// Frontend doesn't set statistic property for null values
if validStats[0] != nil {
a["statistic"] = validStats[0]
}
annotationsList[i] = a
default:
@ -221,11 +241,10 @@ func migrateCloudWatchAnnotationQueries(dashboard map[string]interface{}) {
delete(a, "statistics")
for j, stat := range validStats {
newAnnotation := copyMap(a)
// Set statistic field (matches frontend behavior)
// Frontend doesn't set statistic property for null values
if stat != nil {
if statString, ok := stat.(string); ok {
newAnnotation["statistic"] = statString
}
newAnnotation["statistic"] = stat
}
// Add suffix to name
@ -260,14 +279,9 @@ func getValidStatistics(statisticsField interface{}) ([]interface{}, bool) {
return nil, true // Return nil with true flag to indicate "empty array"
}
var valid []interface{}
for _, stat := range statistics {
// Include null and strings (including empty strings)
if stat == nil || isString(stat) {
valid = append(valid, stat)
}
}
return valid, false
// Frontend processes ALL values in statistics array, regardless of type
// It doesn't filter out invalid types - it processes them as-is
return statistics, false
}
// getSuffixForStat returns the appropriate suffix for annotation names
@ -281,7 +295,20 @@ func getSuffixForStat(stat interface{}) string {
}
return statString
}
return ""
// For non-string types, convert to string representation like JavaScript does
switch v := stat.(type) {
case map[string]interface{}:
return "[object Object]" // JavaScript behavior for objects
case []interface{}:
return "" // JavaScript behavior for arrays (empty string)
case bool:
if v {
return "true"
}
return "false"
default:
return fmt.Sprintf("%v", stat) // Numbers and other types
}
}
// copyMap creates a shallow copy of a map
@ -293,12 +320,6 @@ func copyMap(original map[string]interface{}) map[string]interface{} {
return copy
}
// isString checks if value is a string
func isString(value interface{}) bool {
_, ok := value.(string)
return ok
}
// isCloudWatchQuery checks if a query target is a CloudWatch query.
func isCloudWatchQuery(target map[string]interface{}) bool {
// Check for required CloudWatch query fields

View File

@ -185,7 +185,7 @@ func TestV34(t *testing.T) {
},
},
{
name: "handles invalid statistics in CloudWatch annotation queries",
name: "handles annotation with empty statistics array",
input: map[string]interface{}{
"annotations": map[string]interface{}{
"list": []interface{}{
@ -195,7 +195,7 @@ func TestV34(t *testing.T) {
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistics": []interface{}{123, "Sum", nil},
"statistics": []interface{}{},
},
},
},
@ -205,15 +205,7 @@ func TestV34(t *testing.T) {
"annotations": map[string]interface{}{
"list": []interface{}{
map[string]interface{}{
"name": "CloudWatch Annotation - Sum",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": "Sum",
},
map[string]interface{}{
"name": "CloudWatch Annotation - null",
"name": "CloudWatch Annotation",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
@ -224,7 +216,7 @@ func TestV34(t *testing.T) {
},
},
{
name: "handles multiple valid statistics mixed with invalid ones in annotation",
name: "handles annotation with single statistic",
input: map[string]interface{}{
"annotations": map[string]interface{}{
"list": []interface{}{
@ -234,7 +226,7 @@ func TestV34(t *testing.T) {
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistics": []interface{}{123, "Sum", nil, "Average"},
"statistics": []interface{}{"Average"},
},
},
},
@ -244,22 +236,7 @@ func TestV34(t *testing.T) {
"annotations": map[string]interface{}{
"list": []interface{}{
map[string]interface{}{
"name": "CloudWatch Annotation - Sum",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": "Sum",
},
map[string]interface{}{
"name": "CloudWatch Annotation - null",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
},
map[string]interface{}{
"name": "CloudWatch Annotation - Average",
"name": "CloudWatch Annotation",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
@ -271,7 +248,7 @@ func TestV34(t *testing.T) {
},
},
{
name: "handles CloudWatch annotation with all invalid statistics",
name: "handles annotation with null statistic",
input: map[string]interface{}{
"annotations": map[string]interface{}{
"list": []interface{}{
@ -281,7 +258,7 @@ func TestV34(t *testing.T) {
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistics": []interface{}{123, nil, map[string]interface{}{"invalid": "value"}},
"statistics": []interface{}{nil},
},
},
},
@ -296,6 +273,87 @@ func TestV34(t *testing.T) {
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
// No statistic property for null
},
},
},
},
},
{
name: "handles annotation with all suffix types (for getSuffixForStat coverage)",
input: map[string]interface{}{
"annotations": map[string]interface{}{
"list": []interface{}{
map[string]interface{}{
"name": "CloudWatch Annotation",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistics": []interface{}{123, true, false, map[string]interface{}{}, []interface{}{}, "", "Average"},
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"annotations": map[string]interface{}{
"list": []interface{}{
map[string]interface{}{
"name": "CloudWatch Annotation - 123",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": 123,
},
map[string]interface{}{
"name": "CloudWatch Annotation - true",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": true,
},
map[string]interface{}{
"name": "CloudWatch Annotation - false",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": false,
},
map[string]interface{}{
"name": "CloudWatch Annotation - [object Object]",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": map[string]interface{}{},
},
map[string]interface{}{
"name": "CloudWatch Annotation - ",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": []interface{}{},
},
map[string]interface{}{
"name": "CloudWatch Annotation - ",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": "",
},
map[string]interface{}{
"name": "CloudWatch Annotation - Average",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistic": "Average",
},
},
},
@ -468,94 +526,6 @@ func TestV34(t *testing.T) {
},
},
},
{
name: "handles invalid statistics values gracefully",
input: map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": []interface{}{123, nil, "Average", map[string]interface{}{"invalid": "value"}},
},
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricEditorMode": 0,
"metricQueryType": 0,
},
map[string]interface{}{
"refId": "B",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistic": "Average",
"metricEditorMode": 0,
"metricQueryType": 0,
},
},
},
},
},
},
{
name: "handles CloudWatch query with all invalid statistics",
input: map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": []interface{}{123, nil, map[string]interface{}{"invalid": "value"}},
},
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricEditorMode": 0,
"metricQueryType": 0,
},
},
},
},
},
},
{
name: "preserves other query properties during migration",
input: map[string]interface{}{
@ -768,6 +738,88 @@ func TestV34(t *testing.T) {
},
},
},
{
name: "preserves existing metricQueryType (hasOwnProperty test)",
input: map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricQueryType": 1, // Already exists - should be preserved
"statistics": []interface{}{"Average"},
},
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricQueryType": 1, // Preserved
"metricEditorMode": 1, // Set to Code due to Insights
"statistic": "Average",
},
},
},
},
},
},
{
name: "preserves existing metricEditorMode (hasOwnProperty test)",
input: map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricEditorMode": 1, // Already exists - should be preserved
"statistics": []interface{}{"Average"},
},
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{
"refId": "A",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricEditorMode": 1, // Preserved
"metricQueryType": 0, // Set to default
"statistic": "Average",
},
},
},
},
},
},
{
name: "preserves existing metricEditorMode and metricQueryType values",
input: map[string]interface{}{
@ -826,6 +878,174 @@ func TestV34(t *testing.T) {
},
},
},
{
name: "handles refId generation with existing refIds",
input: map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{"refId": "A", "expr": "prometheus"},
map[string]interface{}{"refId": "C", "expr": "prometheus"}, // Skip B to test gap filling
map[string]interface{}{
"refId": "D",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": []interface{}{"Average", "Maximum"},
},
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": []interface{}{
map[string]interface{}{"refId": "A", "expr": "prometheus"},
map[string]interface{}{"refId": "C", "expr": "prometheus"},
map[string]interface{}{
"refId": "D",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistic": "Average",
"metricEditorMode": 0,
"metricQueryType": 0,
},
map[string]interface{}{
"refId": "B", // Should use the available B
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistic": "Maximum",
"metricEditorMode": 0,
"metricQueryType": 0,
},
},
},
},
},
},
{
name: "handles non-CloudWatch annotation (skips migration)",
input: map[string]interface{}{
"annotations": map[string]interface{}{
"list": []interface{}{
map[string]interface{}{
"name": "Regular Annotation",
"datasource": "prometheus",
},
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"annotations": map[string]interface{}{
"list": []interface{}{
map[string]interface{}{
"name": "Regular Annotation",
"datasource": "prometheus",
},
},
},
},
},
{
name: "handles missing annotations list",
input: map[string]interface{}{
"annotations": map[string]interface{}{},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"annotations": map[string]interface{}{},
},
},
{
name: "handles missing annotations entirely",
input: map[string]interface{}{
"panels": []interface{}{},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{},
},
},
{
name: "tests generateNextRefId double letter generation",
input: map[string]interface{}{
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": func() []interface{} {
targets := []interface{}{}
// Create A-Z refIds
for c := 'A'; c <= 'Z'; c++ {
targets = append(targets, map[string]interface{}{
"refId": string(c),
"expr": "prometheus",
})
}
// Add CloudWatch query that will need double letter refId
targets = append(targets, map[string]interface{}{
"refId": "AA",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": []interface{}{"Average", "Maximum"},
})
return targets
}(),
},
},
},
expected: map[string]interface{}{
"schemaVersion": int(34),
"panels": []interface{}{
map[string]interface{}{
"id": 1,
"targets": func() []interface{} {
targets := []interface{}{}
// Create A-Z refIds
for c := 'A'; c <= 'Z'; c++ {
targets = append(targets, map[string]interface{}{
"refId": string(c),
"expr": "prometheus",
})
}
// Add the migrated CloudWatch queries
targets = append(targets, map[string]interface{}{
"refId": "AA",
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistic": "Average",
"metricEditorMode": 0,
"metricQueryType": 0,
})
targets = append(targets, map[string]interface{}{
"refId": "AB", // Next available double letter
"dimensions": map[string]interface{}{"InstanceId": "i-123"},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistic": "Maximum",
"metricEditorMode": 0,
"metricQueryType": 0,
})
return targets
}(),
},
},
},
},
}
runMigrationTests(t, tests, schemaversion.V34)
}

View File

@ -71,6 +71,40 @@
"prefixMatching": false,
"statistics": ["InvalidStat", "Sum", null, "Average"]
},
{
"name": "CloudWatch Annotation with Null in Statistics",
"enable": true,
"iconColor": "orange",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistics": [null, "Average", ""]
},
{
"name": "CloudWatch Annotation Only Invalid Statistics",
"enable": true,
"iconColor": "pink",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"prefixMatching": false,
"statistics": [123, true, {}]
},
{
"name": "Non-CloudWatch Annotation",
"enable": true,
@ -348,6 +382,143 @@
{
"id": 10,
"type": "timeseries",
"title": "CloudWatch Query Missing Editor Fields",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"targets": [
{
"refId": "A",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-missing-fields"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": ["Average"]
}
]
},
{
"id": 11,
"type": "timeseries",
"title": "CloudWatch Query with Expression (Code Mode)",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"targets": [
{
"refId": "A",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-with-expression"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"expression": "SEARCH('{AWS/EC2,InstanceId} MetricName=\"CPUUtilization\"', 'Average', 300)",
"statistics": ["Average", "Maximum"]
}
]
},
{
"id": 12,
"type": "timeseries",
"title": "CloudWatch Insights Query Missing Editor Mode",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"targets": [
{
"refId": "A",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-insights"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"metricQueryType": 1,
"statistics": ["Average"]
}
]
},
{
"id": 13,
"type": "timeseries",
"title": "CloudWatch Query with Null Statistics",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"targets": [
{
"refId": "A",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": [null, "Average", "", "Maximum"]
}
]
},
{
"id": 14,
"type": "timeseries",
"title": "CloudWatch Query with Only Invalid Statistics",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"targets": [
{
"refId": "A",
"datasource": {
"uid": "default-ds-uid",
"type": "prometheus",
"apiVersion": "v1"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"namespace": "AWS/EC2",
"region": "us-east-1",
"metricName": "CPUUtilization",
"statistics": [123, true, {}, []]
}
]
},
{
"id": 15,
"type": "timeseries",
"title": "Non-CloudWatch Panel",
"datasource": {
"uid": "prometheus"

View File

@ -80,6 +80,39 @@
"region": "us-east-1",
"statistic": "InvalidStat"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"enable": true,
"iconColor": "orange",
"name": "CloudWatch Annotation with Null in Statistics - null",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"enable": true,
"iconColor": "pink",
"name": "CloudWatch Annotation Only Invalid Statistics - 123",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": 123
},
{
"datasource": {
"uid": "prometheus"
@ -171,6 +204,74 @@
"prefixMatching": false,
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"enable": true,
"iconColor": "orange",
"name": "CloudWatch Annotation with Null in Statistics - Average",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"enable": true,
"iconColor": "orange",
"name": "CloudWatch Annotation with Null in Statistics - ",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": ""
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"enable": true,
"iconColor": "pink",
"name": "CloudWatch Annotation Only Invalid Statistics - true",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": true
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"enable": true,
"iconColor": "pink",
"name": "CloudWatch Annotation Only Invalid Statistics - [object Object]",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": {}
}
]
},
@ -631,9 +732,274 @@
},
{
"datasource": {
"uid": "prometheus"
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 10,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-missing-fields"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": "Average"
}
],
"title": "CloudWatch Query Missing Editor Fields",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 11,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-with-expression"
},
"expression": "SEARCH('{AWS/EC2,InstanceId} MetricName=\"CPUUtilization\"', 'Average', 300)",
"metricEditorMode": 1,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-with-expression"
},
"expression": "SEARCH('{AWS/EC2,InstanceId} MetricName=\"CPUUtilization\"', 'Average', 300)",
"metricEditorMode": 1,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "B",
"region": "us-east-1",
"statistic": "Maximum"
}
],
"title": "CloudWatch Query with Expression (Code Mode)",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 12,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-insights"
},
"metricEditorMode": 1,
"metricName": "CPUUtilization",
"metricQueryType": 1,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": "Average"
}
],
"title": "CloudWatch Insights Query Missing Editor Mode",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 13,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "B",
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "C",
"region": "us-east-1",
"statistic": ""
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "D",
"region": "us-east-1",
"statistic": "Maximum"
}
],
"title": "CloudWatch Query with Null Statistics",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 14,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": 123
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "B",
"region": "us-east-1",
"statistic": true
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "C",
"region": "us-east-1",
"statistic": {}
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "D",
"region": "us-east-1",
"statistic": []
}
],
"title": "CloudWatch Query with Only Invalid Statistics",
"type": "timeseries"
},
{
"datasource": {
"uid": "prometheus"
},
"id": 15,
"targets": [
{
"datasource": {

View File

@ -80,6 +80,39 @@
"region": "us-east-1",
"statistic": "InvalidStat"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"enable": true,
"iconColor": "orange",
"name": "CloudWatch Annotation with Null in Statistics - null",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"enable": true,
"iconColor": "pink",
"name": "CloudWatch Annotation Only Invalid Statistics - 123",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": 123
},
{
"datasource": {
"uid": "prometheus"
@ -171,6 +204,74 @@
"prefixMatching": false,
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"enable": true,
"iconColor": "orange",
"name": "CloudWatch Annotation with Null in Statistics - Average",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-annotation"
},
"enable": true,
"iconColor": "orange",
"name": "CloudWatch Annotation with Null in Statistics - ",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": ""
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"enable": true,
"iconColor": "pink",
"name": "CloudWatch Annotation Only Invalid Statistics - true",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": true
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-annotation"
},
"enable": true,
"iconColor": "pink",
"name": "CloudWatch Annotation Only Invalid Statistics - [object Object]",
"namespace": "AWS/EC2",
"prefixMatching": false,
"region": "us-east-1",
"statistic": {}
}
]
},
@ -631,9 +732,274 @@
},
{
"datasource": {
"uid": "prometheus"
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 10,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-missing-fields"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": "Average"
}
],
"title": "CloudWatch Query Missing Editor Fields",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 11,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-with-expression"
},
"expression": "SEARCH('{AWS/EC2,InstanceId} MetricName=\"CPUUtilization\"', 'Average', 300)",
"metricEditorMode": 1,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-with-expression"
},
"expression": "SEARCH('{AWS/EC2,InstanceId} MetricName=\"CPUUtilization\"', 'Average', 300)",
"metricEditorMode": 1,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "B",
"region": "us-east-1",
"statistic": "Maximum"
}
],
"title": "CloudWatch Query with Expression (Code Mode)",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 12,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-insights"
},
"metricEditorMode": 1,
"metricName": "CPUUtilization",
"metricQueryType": 1,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": "Average"
}
],
"title": "CloudWatch Insights Query Missing Editor Mode",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 13,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "B",
"region": "us-east-1",
"statistic": "Average"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "C",
"region": "us-east-1",
"statistic": ""
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-null-stats"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "D",
"region": "us-east-1",
"statistic": "Maximum"
}
],
"title": "CloudWatch Query with Null Statistics",
"type": "timeseries"
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"id": 14,
"targets": [
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "A",
"region": "us-east-1",
"statistic": 123
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "B",
"region": "us-east-1",
"statistic": true
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "C",
"region": "us-east-1",
"statistic": {}
},
{
"datasource": {
"apiVersion": "v1",
"type": "prometheus",
"uid": "default-ds-uid"
},
"dimensions": {
"InstanceId": "i-invalid-only"
},
"metricEditorMode": 0,
"metricName": "CPUUtilization",
"metricQueryType": 0,
"namespace": "AWS/EC2",
"refId": "D",
"region": "us-east-1",
"statistic": []
}
],
"title": "CloudWatch Query with Only Invalid Statistics",
"type": "timeseries"
},
{
"datasource": {
"uid": "prometheus"
},
"id": 15,
"targets": [
{
"datasource": {