Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - use zap in sql/metrics #6238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1949,14 +1949,14 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log) error {
if err := os.MkdirAll(dbPath, os.ModePerm); err != nil {
return fmt.Errorf("failed to create %s: %w", dbPath, err)
}
dbLog := app.addLogger(StateDbLogger, lg)
m21 := migrations.New0021Migration(dbLog.Zap(), 1_000_000)
dbLog := app.addLogger(StateDbLogger, lg).Zap()
m21 := migrations.New0021Migration(dbLog, 1_000_000)
migrations, err := sql.StateMigrations()
if err != nil {
return fmt.Errorf("failed to load migrations: %w", err)
}
dbopts := []sql.Opt{
sql.WithLogger(dbLog.Zap()),
sql.WithLogger(dbLog),
sql.WithMigrations(migrations),
sql.WithMigration(m21),
sql.WithConnections(app.Config.DatabaseConnections),
Expand Down Expand Up @@ -2010,7 +2010,7 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log) error {
return fmt.Errorf("load local migrations: %w", err)
}
localDB, err := localsql.Open("file:"+filepath.Join(dbPath, localDbFile),
sql.WithLogger(dbLog.Zap()),
sql.WithLogger(dbLog),
sql.WithMigrations(migrations),
sql.WithConnections(app.Config.DatabaseConnections),
)
Expand Down
20 changes: 10 additions & 10 deletions sql/metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"time"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/metrics"
"github.com/spacemeshos/go-spacemesh/sql"
)
Expand All @@ -20,7 +20,7 @@

// DBMetricsCollector collects metrics from db.
type DBMetricsCollector struct {
logger log.Logger
logger *zap.Logger
checkInterval time.Duration
db *sql.Database
tablesList map[string]struct{}
Expand All @@ -36,13 +36,13 @@
func NewDBMetricsCollector(
ctx context.Context,
db *sql.Database,
logger log.Logger,
logger *zap.Logger,
checkInterval time.Duration,
) *DBMetricsCollector {
ctx, cancel := context.WithCancel(ctx)
collector := &DBMetricsCollector{
checkInterval: checkInterval,
logger: logger.WithName("db_metrics"),
logger: logger.Named("db_metrics"),

Check warning on line 45 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L45

Added line #L45 was not covered by tests
db: db,
cancel: cancel,
tableSize: metrics.NewGauge("table_size", subsystem, "Size of table in bytes", []string{"name"}),
Expand All @@ -51,20 +51,20 @@
}
statEnabled, err := collector.checkCompiledWithDBStat()
if err != nil {
collector.logger.With().Error("error check compile options", log.Err(err))
collector.logger.Error("error check compile options", zap.Error(err))

Check warning on line 54 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L54

Added line #L54 was not covered by tests
return nil
}
if !statEnabled {
collector.logger.With().Info("sqlite compiled without `SQLITE_ENABLE_DBSTAT_VTAB`. Metrics will not collected")
collector.logger.Info("sqlite compiled without `SQLITE_ENABLE_DBSTAT_VTAB`. Metrics will not collected")

Check warning on line 58 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L58

Added line #L58 was not covered by tests
return nil
}

collector.tablesList, err = collector.getListOfTables()
if err != nil {
collector.logger.With().Error("error get list of tables", log.Err(err))
collector.logger.Error("error get list of tables", zap.Error(err))

Check warning on line 64 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L64

Added line #L64 was not covered by tests
return nil
}
collector.logger.With().Info("start collect stat")
collector.logger.Info("start collect stat")

Check warning on line 67 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L67

Added line #L67 was not covered by tests
collector.eg.Go(func() error {
collector.CollectMetrics(ctx)
return nil
Expand All @@ -76,7 +76,7 @@
func (d *DBMetricsCollector) Close() {
d.cancel()
if err := d.eg.Wait(); err != nil {
d.logger.With().Error("received error waiting for db metrics collector", log.Err(err))
d.logger.Error("received error waiting for db metrics collector", zap.Error(err))

Check warning on line 79 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L79

Added line #L79 was not covered by tests
}
}

Expand All @@ -89,7 +89,7 @@
case <-ticker.C:
d.logger.Debug("collect stats from db")
if err := d.collect(); err != nil {
d.logger.With().Error("error check db metrics", log.Err(err))
d.logger.Error("error collecting db metrics", zap.Error(err))

Check warning on line 92 in sql/metrics/prometheus.go

View check run for this annotation

Codecov / codecov/patch

sql/metrics/prometheus.go#L92

Added line #L92 was not covered by tests
}
case <-ctx.Done():
return
Expand Down
Loading