feat: provides MT Dashboard service (#110447)

This commit is contained in:
Costa Alexoglou
2025-09-03 20:41:37 +00:00
committed by GitHub
parent 7d32640179
commit 3d2cef5f07
43 changed files with 284 additions and 69 deletions
+8 -7
View File
@@ -2,6 +2,7 @@ package migration_test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log/slog"
@@ -29,7 +30,7 @@ func TestMigrate(t *testing.T) {
migration.Initialize(migrationtestutil.GetTestDataSourceProvider(), migrationtestutil.GetTestPanelProvider())
t.Run("minimum version check", func(t *testing.T) {
err := migration.Migrate(map[string]interface{}{
err := migration.Migrate(context.Background(), map[string]interface{}{
"schemaVersion": schemaversion.MIN_VERSION - 1,
}, schemaversion.MIN_VERSION)
@@ -52,7 +53,7 @@ func TestMigrate(t *testing.T) {
t.Run("input check "+f.Name(), func(t *testing.T) {
// use input version as the target version to ensure there are no changes
require.NoError(t, migration.Migrate(inputDash, inputVersion), "input check migration failed")
require.NoError(t, migration.Migrate(context.Background(), inputDash, inputVersion), "input check migration failed")
outBytes, err := json.MarshalIndent(inputDash, "", " ")
require.NoError(t, err, "failed to marshal migrated dashboard")
// We can ignore gosec G304 here since it's a test
@@ -71,7 +72,7 @@ func TestMigrate(t *testing.T) {
func testMigration(t *testing.T, dash map[string]interface{}, inputFileName string, targetVersion int) {
t.Helper()
require.NoError(t, migration.Migrate(dash, targetVersion), "%d migration failed", targetVersion)
require.NoError(t, migration.Migrate(context.Background(), dash, targetVersion), "%d migration failed", targetVersion)
outPath := filepath.Join(OUTPUT_DIR, inputFileName)
outBytes, err := json.MarshalIndent(dash, "", " ")
@@ -191,7 +192,7 @@ func TestSchemaMigrationMetrics(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Execute migration
err := migration.Migrate(tt.dashboard, tt.targetVersion)
err := migration.Migrate(context.Background(), tt.dashboard, tt.targetVersion)
// Check error expectation
if tt.expectSuccess {
@@ -261,7 +262,7 @@ func TestSchemaMigrationLogging(t *testing.T) {
// and check that the migration behaves correctly (logs are called internally)
// Execute migration
err := migration.Migrate(tt.dashboard, tt.targetVersion)
err := migration.Migrate(context.Background(), tt.dashboard, tt.targetVersion)
// Check error expectation
if tt.expectSuccess {
@@ -295,7 +296,7 @@ func TestLogMessageStructure(t *testing.T) {
}
// Successful migration - should trigger debug log
err := migration.Migrate(dashboard, schemaversion.LATEST_VERSION)
err := migration.Migrate(context.Background(), dashboard, schemaversion.LATEST_VERSION)
require.NoError(t, err, "migration should succeed")
// Failed migration - should trigger error log
@@ -303,7 +304,7 @@ func TestLogMessageStructure(t *testing.T) {
"schemaVersion": schemaversion.MIN_VERSION - 1,
"title": "old dashboard",
}
err = migration.Migrate(oldDashboard, schemaversion.LATEST_VERSION)
err = migration.Migrate(context.Background(), oldDashboard, schemaversion.LATEST_VERSION)
require.Error(t, err, "migration should fail")
// Both cases above execute the logging code in reportMigrationMetrics