mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 23:19:02 +08:00
fix: changed the keys in the default quick filters to actual keys in … (#7863)
* fix: changed the keys in the default quick filters to actual keys in the v3.attributekeys * fix: changed the keys in the default quick filters to actual keys in the v3.attributekeys * fix: changed the keys in the default quick filters to actual keys in the v3.attributekeys * fix: changed the keys in the default quick filters to actual keys in the v3.attributekeys * fix: changed the keys in the default quick filters to actual keys in the v3.attributekeys
This commit is contained in:
parent
02b605d109
commit
3758ee7451
@ -75,6 +75,7 @@ func NewSQLMigrationProviderFactories(sqlstore sqlstore.SQLStore) factory.NamedM
|
|||||||
sqlmigration.NewUpdateOrganizationsFactory(sqlstore),
|
sqlmigration.NewUpdateOrganizationsFactory(sqlstore),
|
||||||
sqlmigration.NewDropGroupsFactory(sqlstore),
|
sqlmigration.NewDropGroupsFactory(sqlstore),
|
||||||
sqlmigration.NewCreateQuickFiltersFactory(sqlstore),
|
sqlmigration.NewCreateQuickFiltersFactory(sqlstore),
|
||||||
|
sqlmigration.NewUpdateQuickFiltersFactory(sqlstore),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
103
pkg/sqlmigration/031_update_quick_filters.go
Normal file
103
pkg/sqlmigration/031_update_quick_filters.go
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package sqlmigration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"github.com/SigNoz/signoz/pkg/errors"
|
||||||
|
"github.com/SigNoz/signoz/pkg/factory"
|
||||||
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
||||||
|
"github.com/SigNoz/signoz/pkg/types/quickfiltertypes"
|
||||||
|
"github.com/SigNoz/signoz/pkg/valuer"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
"github.com/uptrace/bun/migrate"
|
||||||
|
)
|
||||||
|
|
||||||
|
type updateQuickFilters struct {
|
||||||
|
store sqlstore.SQLStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateQuickFiltersFactory(store sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config] {
|
||||||
|
return factory.NewProviderFactory(factory.MustNewName("update_quick_filters"), func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {
|
||||||
|
return newUpdateQuickFilters(ctx, ps, c, store)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func newUpdateQuickFilters(_ context.Context, _ factory.ProviderSettings, _ Config, store sqlstore.SQLStore) (SQLMigration, error) {
|
||||||
|
return &updateQuickFilters{
|
||||||
|
store: store,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (migration *updateQuickFilters) Register(migrations *migrate.Migrations) error {
|
||||||
|
if err := migrations.Register(migration.Up, migration.Down); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (migration *updateQuickFilters) Up(ctx context.Context, db *bun.DB) error {
|
||||||
|
tx, err := db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer tx.Rollback()
|
||||||
|
|
||||||
|
// Delete all existing quick filters
|
||||||
|
_, err = tx.NewDelete().
|
||||||
|
Table("quick_filter").
|
||||||
|
Where("1=1"). // Delete all rows
|
||||||
|
Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all organization IDs as strings
|
||||||
|
var orgIDs []string
|
||||||
|
err = tx.NewSelect().
|
||||||
|
Table("organizations").
|
||||||
|
Column("id").
|
||||||
|
Scan(ctx, &orgIDs)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
// No organizations found, commit the transaction (deletion is done) and return
|
||||||
|
if err := tx.Commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each organization, create new quick filters with the updated NewDefaultQuickFilter function
|
||||||
|
for _, orgID := range orgIDs {
|
||||||
|
// Get the updated default quick filters
|
||||||
|
storableQuickFilters, err := quickfiltertypes.NewDefaultQuickFilter(valuer.MustNewUUID(orgID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert all filters for this organization
|
||||||
|
_, err = tx.NewInsert().
|
||||||
|
Model(&storableQuickFilters).
|
||||||
|
Exec(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if errors.Ast(migration.store.WrapAlreadyExistsErrf(err, errors.CodeAlreadyExists, "Quick Filter already exists"), errors.TypeAlreadyExists) {
|
||||||
|
// Skip if filters already exist for this org
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tx.Commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (migration *updateQuickFilters) Down(ctx context.Context, db *bun.DB) error {
|
||||||
|
return nil
|
||||||
|
}
|
@ -139,21 +139,21 @@ func NewDefaultQuickFilter(orgID valuer.UUID) ([]*StorableQuickFilter, error) {
|
|||||||
{"key": "duration_nano", "dataType": "float64", "type": "tag"},
|
{"key": "duration_nano", "dataType": "float64", "type": "tag"},
|
||||||
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
||||||
{"key": "hasError", "dataType": "bool", "type": "tag"},
|
{"key": "hasError", "dataType": "bool", "type": "tag"},
|
||||||
{"key": "serviceName", "dataType": "string", "type": "tag"},
|
{"key": "service.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "name", "dataType": "string", "type": "resource"},
|
{"key": "name", "dataType": "string", "type": "tag"},
|
||||||
{"key": "rpcMethod", "dataType": "string", "type": "tag"},
|
{"key": "rpc.method", "dataType": "string", "type": "tag"},
|
||||||
{"key": "responseStatusCode", "dataType": "string", "type": "resource"},
|
{"key": "response_status_code", "dataType": "string", "type": "tag"},
|
||||||
{"key": "httpHost", "dataType": "string", "type": "tag"},
|
{"key": "http_host", "dataType": "string", "type": "tag"},
|
||||||
{"key": "httpMethod", "dataType": "string", "type": "tag"},
|
{"key": "http.method", "dataType": "string", "type": "tag"},
|
||||||
{"key": "httpRoute", "dataType": "string", "type": "tag"},
|
{"key": "http.route", "dataType": "string", "type": "tag"},
|
||||||
{"key": "httpUrl", "dataType": "string", "type": "tag"},
|
{"key": "http_url", "dataType": "string", "type": "tag"},
|
||||||
{"key": "traceID", "dataType": "string", "type": "tag"},
|
{"key": "trace_id", "dataType": "string", "type": "tag"},
|
||||||
}
|
}
|
||||||
|
|
||||||
logsFilters := []map[string]interface{}{
|
logsFilters := []map[string]interface{}{
|
||||||
{"key": "severity_text", "dataType": "string", "type": "resource"},
|
{"key": "severity_text", "dataType": "string", "type": "resource"},
|
||||||
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
||||||
{"key": "serviceName", "dataType": "string", "type": "tag"},
|
{"key": "service.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "host.name", "dataType": "string", "type": "resource"},
|
{"key": "host.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "k8s.cluster.name", "dataType": "string", "type": "resource"},
|
{"key": "k8s.cluster.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "k8s.deployment.name", "dataType": "string", "type": "resource"},
|
{"key": "k8s.deployment.name", "dataType": "string", "type": "resource"},
|
||||||
@ -163,18 +163,18 @@ func NewDefaultQuickFilter(orgID valuer.UUID) ([]*StorableQuickFilter, error) {
|
|||||||
|
|
||||||
apiMonitoringFilters := []map[string]interface{}{
|
apiMonitoringFilters := []map[string]interface{}{
|
||||||
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
||||||
{"key": "serviceName", "dataType": "string", "type": "tag"},
|
{"key": "service.name", "dataType": "string", "type": "tag"},
|
||||||
{"key": "rpcMethod", "dataType": "string", "type": "tag"},
|
{"key": "rpc.method", "dataType": "string", "type": "tag"},
|
||||||
}
|
}
|
||||||
|
|
||||||
exceptionsFilters := []map[string]interface{}{
|
exceptionsFilters := []map[string]interface{}{
|
||||||
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
{"key": "deployment.environment", "dataType": "string", "type": "resource"},
|
||||||
{"key": "serviceName", "dataType": "string", "type": "tag"},
|
{"key": "service.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "host.name", "dataType": "string", "type": "resource"},
|
{"key": "host.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "k8s.cluster.name", "dataType": "string", "type": "tag"},
|
{"key": "k8s.cluster.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "k8s.deployment.name", "dataType": "string", "type": "resource"},
|
{"key": "k8s.deployment.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "k8s.namespace.name", "dataType": "string", "type": "tag"},
|
{"key": "k8s.namespace.name", "dataType": "string", "type": "resource"},
|
||||||
{"key": "k8s.pod.name", "dataType": "string", "type": "tag"},
|
{"key": "k8s.pod.name", "dataType": "string", "type": "resource"},
|
||||||
}
|
}
|
||||||
|
|
||||||
tracesJSON, err := json.Marshal(tracesFilters)
|
tracesJSON, err := json.Marshal(tracesFilters)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user