fix(kv): log migration events at debug level to avoid spam (#20572)

pull/20598/head
Daniel Moran 2021-01-25 10:34:59 -08:00 committed by GitHub
parent f6669f7512
commit ebd37c8b9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 3 deletions

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"time" "time"
influxdb "github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kv" "github.com/influxdata/influxdb/v2/kv"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -148,6 +148,11 @@ func (m *Migrator) Up(ctx context.Context) error {
return wrapErr(err) return wrapErr(err)
} }
migrationsToDo := len(m.Specs[lastMigration:])
if migrationsToDo > 0 {
m.logger.Info("Bringing up metadata migrations", zap.Int("migration_count", migrationsToDo))
}
for idx, spec := range m.Specs[lastMigration:] { for idx, spec := range m.Specs[lastMigration:] {
startedAt := m.now() startedAt := m.now()
migration := Migration{ migration := Migration{
@ -218,7 +223,12 @@ func (m *Migrator) Down(ctx context.Context) (err error) {
return wrapErr(err) return wrapErr(err)
} }
for i := len(migrations) - 1; i >= 0; i-- { migrationsToDo := len(migrations)
if migrationsToDo > 0 {
m.logger.Info("Tearing down metadata migrations", zap.Int("migration_count", migrationsToDo))
}
for i := migrationsToDo - 1; i >= 0; i-- {
migration := migrations[i] migration := migrations[i]
m.logMigrationEvent(DownMigrationState, migration.Migration, "started") m.logMigrationEvent(DownMigrationState, migration.Migration, "started")
@ -238,7 +248,12 @@ func (m *Migrator) Down(ctx context.Context) (err error) {
} }
func (m *Migrator) logMigrationEvent(state MigrationState, mig Migration, event string) { func (m *Migrator) logMigrationEvent(state MigrationState, mig Migration, event string) {
m.logger.Info(fmt.Sprintf("Migration %q %s (%s)", mig.Name, event, state)) m.logger.Debug(
"Executing metadata migration",
zap.String("migration_name", mig.Name),
zap.String("target_state", state.String()),
zap.String("migration_event", event),
)
} }
func (m *Migrator) walk(ctx context.Context, store kv.Store, fn func(id influxdb.ID, m Migration)) error { func (m *Migrator) walk(ctx context.Context, store kv.Store, fn func(id influxdb.ID, m Migration)) error {