Skip to content

Commit

Permalink
fix: add autovacuum_vacuum_cost_limit to the reports table [PIPE-512] (
Browse files Browse the repository at this point in the history
  • Loading branch information
BonapartePC committed Nov 17, 2023
1 parent 1621628 commit 690aeb0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions enterprise/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ func (r *DefaultReporter) DatabaseSyncer(c types.SyncerConfig) types.ReportingSy
if err != nil {
panic(fmt.Errorf("could not run reports migrations: %w", err))
}

m = &migrator.Migrator{
Handle: dbHandle,
MigrationsTable: "reports_runalways_migrations",
RunAlways: true,
}
templateData := map[string]interface{}{
"config": config.Default,
}
if err := m.MigrateFromTemplates("reports_always", templateData); err != nil {
panic(fmt.Errorf("could not run reports_always migrations: %w", err))
}
r.syncers[c.ConnInfo] = &types.SyncSource{SyncerConfig: c, DbHandle: dbHandle}

if !config.GetBool("Reporting.syncer.enabled", true) {
Expand Down
30 changes: 28 additions & 2 deletions services/sql-migrator/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"

"github.com/rudderlabs/rudder-go-kit/config"
"github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource"
migrator "github.com/rudderlabs/rudder-server/services/sql-migrator"
"github.com/rudderlabs/rudder-server/sql/migrations"
Expand Down Expand Up @@ -42,9 +43,34 @@ func TestMigrate(t *testing.T) {
MigrationsTable: fmt.Sprintf("migrations_%s", dir),
Handle: postgre.DB,
}

err := m.Migrate(dir)
var err error
if strings.HasPrefix(dir, "reports_always") {
err = m.MigrateFromTemplates("reports_always", map[string]interface{}{
"config": config.Default,
})
} else {
err = m.Migrate(dir)
}
require.NoError(t, err)
})
}

t.Run("validate if autovacuum_vacuum_cost_limit is being set", func(t *testing.T) {
query := "select reloptions from pg_class where relname = 'reports';"
var value interface{}
require.NoError(t, postgre.DB.QueryRow(query).Scan(&value))
require.Nil(t, value) // value should be nil if config is not set
config.Set("Reporting.autoVacuumCostLimit", 300)
m := migrator.Migrator{
MigrationsTable: "migrations_reports_always",
Handle: postgre.DB,
RunAlways: true,
}
require.NoError(t, m.MigrateFromTemplates("reports_always", map[string]interface{}{
"config": config.Default,
}))
var costLimit string
require.NoError(t, postgre.DB.QueryRow(query).Scan(&costLimit))
require.Equal(t, "{autovacuum_vacuum_cost_limit=300}", costLimit) // value should be set to 300
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ if .config.IsSet "Reporting.autoVacuumCostLimit" }}
ALTER TABLE reports SET (autovacuum_vacuum_cost_limit = {{ .config.MustGetInt "Reporting.autoVacuumCostLimit" }});
{{ end }}

0 comments on commit 690aeb0

Please sign in to comment.