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
2.0 KiB
Go
61 lines
2.0 KiB
Go
package querybuilder
|
|
|
|
import (
|
|
grammar "github.com/SigNoz/signoz/pkg/parser/grammar"
|
|
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
|
|
"github.com/antlr4-go/antlr/v4"
|
|
)
|
|
|
|
// QueryStringToKeysSelectors converts a query string to a list of field key selectors
|
|
//
|
|
// e.g. "service.name="query-service" AND http.status_code=200 AND resource.k8s.namespace.name="application"" -> []*telemetrytypes.FieldKeySelector{
|
|
// {
|
|
// Name: "service.name",
|
|
// FieldContext: telemetrytypes.FieldContextUnspecified,
|
|
// FieldDataType: telemetrytypes.FieldDataTypeUnspecified,
|
|
// },
|
|
// {
|
|
// Name: "http.status_code",
|
|
// FieldContext: telemetrytypes.FieldContextUnspecified,
|
|
// FieldDataType: telemetrytypes.FieldDataTypeUnspecified,
|
|
// },
|
|
// {
|
|
// Name: "resource.k8s.namespace.name",
|
|
// FieldContext: telemetrytypes.FieldContextResource,
|
|
// FieldDataType: telemetrytypes.FieldDataTypeUnspecified,
|
|
// },
|
|
// }
|
|
func QueryStringToKeysSelectors(query string) []*telemetrytypes.FieldKeySelector {
|
|
lexer := grammar.NewFilterQueryLexer(antlr.NewInputStream(query))
|
|
keys := []*telemetrytypes.FieldKeySelector{}
|
|
for {
|
|
tok := lexer.NextToken()
|
|
if tok.GetTokenType() == antlr.TokenEOF {
|
|
break
|
|
}
|
|
|
|
if tok.GetTokenType() == grammar.FilterQueryLexerKEY {
|
|
key := telemetrytypes.GetFieldKeyFromKeyText(tok.GetText())
|
|
keys = append(keys, &telemetrytypes.FieldKeySelector{
|
|
Name: key.Name,
|
|
Signal: key.Signal,
|
|
FieldContext: key.FieldContext,
|
|
FieldDataType: key.FieldDataType,
|
|
})
|
|
|
|
if key.FieldContext != telemetrytypes.FieldContextUnspecified {
|
|
// span.kind in metrics or metric.max_count in span etc.. should get the search on span.kind
|
|
// see note in where_clause_visitor.go in VisitKey(...)
|
|
keys = append(keys, &telemetrytypes.FieldKeySelector{
|
|
Name: key.FieldContext.StringValue() + "." + key.Name,
|
|
Signal: key.Signal,
|
|
FieldContext: key.FieldContext,
|
|
FieldDataType: key.FieldDataType,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
return keys
|
|
}
|