Dashboards Migrations: V24 set defaults when no thresholds are defined (#109402)

This commit is contained in:
Ivan Ortega Alba
2025-08-11 11:55:19 +02:00
committed by GitHub
parent 58c4305d64
commit 63bab8076d
3 changed files with 25 additions and 13 deletions
@@ -514,23 +514,23 @@ func migrateDefaults(prevDefaults map[string]interface{}) map[string]interface{}
"mappings": []interface{}{},
}
// Only add default thresholds if we have prevDefaults (meaning this is a table panel being migrated)
// and no specific thresholds exist in prevDefaults
// Add default thresholds for all table panels to match frontend behavior
// The frontend applies the table panel's default field config which includes thresholds
hasThresholds := false
if prevDefaults != nil {
if thresholds, ok := prevDefaults["thresholds"].([]interface{}); ok && len(thresholds) > 0 {
hasThresholds = true
}
}
// Only add default thresholds for table panels (when prevDefaults exists) without existing thresholds
if !hasThresholds {
defaults["thresholds"] = map[string]interface{}{
"mode": "absolute",
"steps": []interface{}{
map[string]interface{}{"color": "green"},
map[string]interface{}{"color": "red", "value": 80},
},
}
// Add default thresholds for all table panels (when prevDefaults exists) without existing thresholds
if !hasThresholds {
defaults["thresholds"] = map[string]interface{}{
"mode": "absolute",
"steps": []interface{}{
map[string]interface{}{"color": "green"},
map[string]interface{}{"color": "red", "value": 80},
},
}
}
@@ -15,7 +15,19 @@
},
"inspect": false
},
"mappings": []
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": [
{
@@ -113,7 +113,7 @@ describe('Backend / Frontend result comparison', () => {
const jsonInputs = readdirSync(inputDir);
jsonInputs.forEach((inputFile) => {
it.skip(`should migrate ${inputFile} correctly`, async () => {
it(`should migrate ${inputFile} correctly`, async () => {
const jsonInput = JSON.parse(readFileSync(path.join(inputDir, inputFile), 'utf8'));
const backendOutput = JSON.parse(readFileSync(path.join(outputDir, inputFile), 'utf8'));