Compare commits

...

9 Commits

Author SHA1 Message Date
swapnil-signoz
26d2d8c0a4 Merge branch 'main' into feat/aws-regions-migration 2026-04-20 18:48:25 +05:30
swapnil-signoz
1189647e98 refactor: cleanup 2026-04-20 18:32:51 +05:30
swapnil-signoz
e122fe9f57 Merge branch 'main' into feat/aws-regions-migration 2026-04-20 17:52:01 +05:30
swapnil-signoz
167a6a4908 refactor: using updated AWS regions declaration 2026-04-20 16:26:19 +05:30
swapnil-signoz
233df5f202 Merge branch 'main' into feat/aws-regions-migration 2026-04-20 16:24:20 +05:30
swapnil-signoz
540a15bfaa refactor: using table expr for table name 2026-04-20 16:03:41 +05:30
swapnil-signoz
4b88352666 Merge branch 'main' into feat/aws-regions-migration 2026-04-20 15:28:51 +05:30
swapnil-signoz
1cf7d32c52 refactor: removing raw queries 2026-04-20 15:27:41 +05:30
swapnil-signoz
c21f165557 feat: adding migration AWS cloud integration regions config 2026-04-17 14:54:32 +05:30
2 changed files with 117 additions and 0 deletions

View File

@@ -194,6 +194,7 @@ func NewSQLMigrationProviderFactories(
sqlmigration.NewDeprecateAPIKeyFactory(sqlstore, sqlschema),
sqlmigration.NewServiceAccountAuthzactory(sqlstore),
sqlmigration.NewDropUserDeletedAtFactory(sqlstore, sqlschema),
sqlmigration.NewMigrateAWSAllRegionsFactory(sqlstore),
)
}

View File

@@ -0,0 +1,116 @@
package sqlmigration
import (
"context"
"encoding/json"
"slices"
"sort"
"github.com/SigNoz/signoz/pkg/factory"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types/cloudintegrationtypes"
"github.com/uptrace/bun"
"github.com/uptrace/bun/migrate"
)
type migrateAWSAllRegions struct {
sqlstore sqlstore.SQLStore
}
type cloudIntegrationAWSMigrationRow struct {
bun.BaseModel `bun:"table:cloud_integration"`
ID string `bun:"id"`
Config string `bun:"config"`
}
type awsConfig struct {
Regions []string `json:"regions"`
}
func NewMigrateAWSAllRegionsFactory(sqlstore sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config] {
return factory.NewProviderFactory(
factory.MustNewName("migrate_aws_all_regions"),
func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {
return &migrateAWSAllRegions{sqlstore: sqlstore}, nil
},
)
}
func (migration *migrateAWSAllRegions) Register(migrations *migrate.Migrations) error {
if err := migrations.Register(migration.Up, migration.Down); err != nil {
return err
}
return nil
}
func (migration *migrateAWSAllRegions) Up(ctx context.Context, db *bun.DB) error {
tx, err := db.BeginTx(ctx, nil)
if err != nil {
return err
}
defer func() {
_ = tx.Rollback()
}()
accounts := make([]*cloudIntegrationAWSMigrationRow, 0)
err = tx.NewSelect().
Model(&accounts).
Where("provider = ?", cloudintegrationtypes.CloudProviderTypeAWS).
Where("removed_at IS NULL").
Scan(ctx)
if err != nil {
return err
}
idsToUpdate := make([]string, 0)
for _, account := range accounts {
var cfg awsConfig
if err := json.Unmarshal([]byte(account.Config), &cfg); err != nil {
continue
}
if containsAllRegion(cfg.Regions) {
idsToUpdate = append(idsToUpdate, account.ID)
}
}
if len(idsToUpdate) == 0 {
return tx.Commit()
}
cfg := awsConfig{Regions: allValidAWSRegions()}
newBytes, err := json.Marshal(cfg)
if err != nil {
return err
}
_, err = tx.NewUpdate().
TableExpr("cloud_integration").
Set("config = ?", string(newBytes)).
Where("id IN (?)", bun.In(idsToUpdate)).
Exec(ctx)
if err != nil {
return err
}
return tx.Commit()
}
func (migration *migrateAWSAllRegions) Down(context.Context, *bun.DB) error {
return nil
}
func containsAllRegion(regions []string) bool {
return slices.Contains(regions, "all")
}
func allValidAWSRegions() []string {
awsRegions := cloudintegrationtypes.SupportedRegions[cloudintegrationtypes.CloudProviderTypeAWS]
out := make([]string, 0, len(awsRegions))
for _, r := range awsRegions {
out = append(out, r.StringValue())
}
sort.Strings(out)
return out
}