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
5 changed files with 1297 additions and 153 deletions
@@ -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"