Dashboard Migrations: Add observability logging to dashboard conversion process (#109368)

This commit is contained in:
Ivan Ortega Alba
2025-08-11 13:27:54 +02:00
committed by GitHub
parent 6ca3d8a27a
commit f3182a3838
4 changed files with 88 additions and 1 deletions
@@ -8,8 +8,11 @@ import (
dashv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
dashv2alpha1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2alpha1"
dashv2beta1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v2beta1"
"github.com/grafana/grafana/pkg/infra/log"
)
var logger = log.New("dashboard.conversion")
func RegisterConversions(s *runtime.Scheme) error {
// v0 conversions
if err := s.AddConversionFunc((*dashv0.Dashboard)(nil), (*dashv1.Dashboard)(nil), func(a, b interface{}, scope conversion.Scope) error {
@@ -1,6 +1,9 @@
package conversion
import (
"errors"
"fmt"
"k8s.io/apimachinery/pkg/conversion"
dashv0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
@@ -25,8 +28,45 @@ func Convert_V0_to_V1(in *dashv0.Dashboard, out *dashv1.Dashboard, scope convers
if err := migration.Migrate(out.Spec.Object, schemaversion.LATEST_VERSION); err != nil {
out.Status.Conversion.Failed = true
out.Status.Conversion.Error = err.Error()
// Classify error type for metrics
errorType := "conversion_error"
var migrationErr *schemaversion.MigrationError
var minVersionErr *schemaversion.MinimumVersionError
if errors.As(err, &migrationErr) {
errorType = "schema_version_migration_error"
} else if errors.As(err, &minVersionErr) {
errorType = "schema_minimum_version_error"
}
// Record failure metrics
migration.MDashboardConversionFailureTotal.WithLabelValues(
dashv0.APIVERSION,
dashv1.APIVERSION,
fmt.Sprintf("%v", in.Spec.Object["schemaVersion"]),
fmt.Sprintf("%d", schemaversion.LATEST_VERSION),
errorType,
).Inc()
logger.Error("Dashboard conversion failed",
"sourceVersionAPI", dashv0.APIVERSION,
"targetVersionAPI", dashv1.APIVERSION,
"dashboardUID", in.UID,
"sourceSchemaVersion", in.Spec.Object["schemaVersion"],
"targetSchemaVersion", schemaversion.LATEST_VERSION,
"errorType", errorType,
"error", err)
return nil
}
migration.MDashboardConversionSuccessTotal.WithLabelValues(
dashv0.APIVERSION,
dashv1.APIVERSION,
fmt.Sprintf("%v", in.Spec.Object["schemaVersion"]),
fmt.Sprintf("%d", schemaversion.LATEST_VERSION),
).Inc()
return nil
}