mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
## 📄 Summary
To reliably migrate the alerts and dashboards, we need access to the telemetrystore to fetch some metadata and while doing migration, I need to log some stuff to fix stuff later.
Key changes:
- Modified the migration to include telemetrystore and a logging provider (open to using a standard logger instead)
- To avoid the previous issues with imported dashboards failing during migration, I've ensured that imported JSON files are automatically transformed when migration is active
- Implemented detailed logic to handle dashboard migration cleanly and prevent unnecessary errors
- Separated the core migration logic from SQL migration code, as users from the dot metrics migration requested shareable code snippets for local migrations. This modular approach allows others to easily reuse the migration functionality.
Known: I didn't register the migration yet in this PR, and will not merge this yet, so please review with that in mid.
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// nolint
|
|
package transition
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
type savedViewMigrateV5 struct {
|
|
migrateCommon
|
|
}
|
|
|
|
func NewSavedViewMigrateV5(logger *slog.Logger, logsDuplicateKeys []string, tracesDuplicateKeys []string) *savedViewMigrateV5 {
|
|
return &savedViewMigrateV5{
|
|
migrateCommon: migrateCommon{ambiguity: make(map[string][]string), logger: logger},
|
|
}
|
|
}
|
|
|
|
func (m *savedViewMigrateV5) Migrate(ctx context.Context, data map[string]any) bool {
|
|
updated := false
|
|
|
|
var version string
|
|
if _, ok := data["version"].(string); ok {
|
|
version = data["version"].(string)
|
|
}
|
|
|
|
if version == "v5" {
|
|
m.logger.InfoContext(ctx, "saved view is already migrated to v5, skipping")
|
|
return false
|
|
}
|
|
|
|
data["queries"] = make([]any, 0)
|
|
|
|
if builderQueries, ok := data["builderQueries"].(map[string]any); ok {
|
|
for name, query := range builderQueries {
|
|
if queryMap, ok := query.(map[string]any); ok {
|
|
var panelType string
|
|
if _, ok := data["panelType"].(string); ok {
|
|
panelType = data["panelType"].(string)
|
|
}
|
|
if m.updateQueryData(ctx, queryMap, "v4", panelType) {
|
|
updated = true
|
|
}
|
|
|
|
m.logger.InfoContext(ctx, "migrated querymap")
|
|
|
|
// wrap it in the v5 envelope
|
|
envelope := m.wrapInV5Envelope(name, queryMap, "builder_query")
|
|
m.logger.InfoContext(ctx, "envelope after wrap", "envelope", envelope)
|
|
data["queries"] = append(data["queries"].([]any), envelope)
|
|
}
|
|
}
|
|
}
|
|
delete(data, "builderQueries")
|
|
|
|
data["version"] = "v5"
|
|
|
|
return updated
|
|
}
|