Dashboard migration: Implement v2 to v0 conversions (#114812)
* Update docs * Remove 406 response since now it is converted * fix linter --------- Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Stephanie Hingtgen
parent
dcd2086212
commit
c8853f50cf
@@ -8,12 +8,13 @@ This document describes the Grafana dashboard migration system, focusing on conv
|
||||
- [Conversion Flow](#conversion-flow-v0--v1--v2)
|
||||
- [v0 to v1 Conversion](#v0-to-v1-conversion)
|
||||
- [v1 to v2 Conversion](#v1-to-v2-conversion)
|
||||
- [v2 to v0/v1 Conversion](#v2-to-v0v1-conversion)
|
||||
- [Conversion Matrix](#conversion-matrix)
|
||||
- [API Versions](#api-versions)
|
||||
- [Schema Versions](#schema-versions)
|
||||
- [Testing](#testing)
|
||||
- [Backend conversion tests](#backend-conversion-tests)
|
||||
- [Frontend migration comparison tests](#frontend-migration-comparison-tests)
|
||||
- [Backend and frontend conversion parity tests](#backend-and-frontend-conversion-parity-tests)
|
||||
- [Monitoring Migrations](#monitoring-migrations)
|
||||
- [Metrics](#metrics)
|
||||
- [Dashboard conversion success metric](#1-dashboard-conversion-success-metric)
|
||||
@@ -54,6 +55,12 @@ v0alpha1 (Legacy JSON) → v1beta1 (Migrated JSON) → v2alpha1/v2beta1 (Structu
|
||||
- Handles modern dashboard features and Kubernetes-native storage
|
||||
- See [V2 to V1 Layout Conversion](./conversion/v2_to_v1_layout_conversion.md) for details on how V2 layouts are converted back to V1 panel arrays
|
||||
|
||||
#### v2 to v0/v1 Conversion:
|
||||
- Converts structured v2 dashboards back to JSON format (v0alpha1 or v1beta1)
|
||||
- Chains through intermediate versions: v2 → v1beta1 → v0alpha1
|
||||
- v0alpha1 and v1beta1 share the same spec structure (only API version differs)
|
||||
- Enables backward compatibility when storing v2 dashboards in legacy format
|
||||
|
||||
## Conversion Matrix
|
||||
|
||||
The system supports conversions between all dashboard API versions:
|
||||
@@ -113,25 +120,51 @@ go test ./apps/dashboard/pkg/migration/conversion/... -v
|
||||
go test ./apps/dashboard/pkg/migration/... -run TestSchemaMigrationMetrics
|
||||
```
|
||||
|
||||
### Frontend migration comparison tests
|
||||
### Backend and frontend conversion parity tests
|
||||
|
||||
The frontend migration comparison tests validate that backend and frontend conversion logic produce consistent results:
|
||||
These tests ensure that backend (Go) and frontend (TypeScript) conversions produce identical outputs. This is critical because:
|
||||
|
||||
- **Test methodology**: Compares backend vs frontend conversion outputs through DashboardModel integration
|
||||
- **Dataset coverage**: Tests run against curated test files covering various conversion scenarios
|
||||
- **Test location**: `public/app/features/dashboard/state/DashboardMigratorToBackend.test.ts`
|
||||
- **Test data**: Located in `apps/dashboard/pkg/migration/testdata/input/` and `testdata/output/`
|
||||
- **Dual implementation**: Both backend and frontend implement dashboard version conversions
|
||||
- **Consistency requirement**: Users should see the same dashboard regardless of which path is used
|
||||
- **API flexibility**: The API may return dashboards in different versions depending on context
|
||||
|
||||
**Why normalize through Scene?**
|
||||
|
||||
Both backend and frontend outputs are passed through the same Scene load/save cycle before comparison. This normalization:
|
||||
- Eliminates differences from default values added by Scene
|
||||
- Handles field ordering variations
|
||||
- Simulates the real-world flow: dashboard loaded → edited → saved
|
||||
|
||||
**Test locations:**
|
||||
|
||||
| Test File | Purpose |
|
||||
|-----------|---------|
|
||||
| `public/app/features/dashboard-scene/serialization/transformSaveModelV1ToV2.test.ts` | v1beta1 → v2beta1 conversion parity |
|
||||
| `public/app/features/dashboard-scene/serialization/transformSaveModelV2ToV1.test.ts` | v2beta1 → v1beta1/v0alpha1 conversion parity |
|
||||
| `public/app/features/dashboard/state/DashboardMigratorToBackend.test.ts` | Schema version migration parity |
|
||||
|
||||
**Test execution:**
|
||||
```bash
|
||||
# Frontend migration comparison tests
|
||||
# V1 to V2 conversion parity tests
|
||||
yarn test transformSaveModelV1ToV2.test.ts
|
||||
|
||||
# V2 to V1 conversion parity tests
|
||||
yarn test transformSaveModelV2ToV1.test.ts
|
||||
|
||||
# Schema migration parity tests
|
||||
yarn test DashboardMigratorToBackend.test.ts
|
||||
```
|
||||
|
||||
**Test approach:**
|
||||
- **Frontend path**: `jsonInput → DashboardModel → DashboardMigrator → getSaveModelClone()`
|
||||
- **Backend path**: `jsonInput → Backend Conversion → backendOutput → DashboardModel → getSaveModelClone()`
|
||||
- **Comparison**: Direct comparison of final converted states from both paths
|
||||
**Test approach (v1 → v2):**
|
||||
- **Backend path**: `v1beta1 → Go conversion → v2beta1 → Scene → normalized output`
|
||||
- **Frontend path**: `v1beta1 → Scene → v2beta1 → Scene → normalized output`
|
||||
- **Test data**: Uses files from `apps/dashboard/pkg/migration/conversion/testdata/` and migrated dashboards
|
||||
|
||||
**Test approach (v2 → v1/v0):**
|
||||
- **Backend path**: `v2beta1 → Go conversion → v1beta1/v0alpha1 → Scene → normalized output`
|
||||
- **Frontend path**: `v2beta1 → Scene → v1beta1 → Scene → normalized output`
|
||||
- **Target versions**: Tests both v0alpha1 and v1beta1 (they share the same spec structure)
|
||||
- **Test data**: Uses files from `apps/dashboard/pkg/migration/conversion/testdata/`
|
||||
|
||||
For schema version migration testing details, see the [SchemaVersion Migration Guide](./schemaversion/README.md).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user