Skip to content

Commit

Permalink
feat(logging): Add startup logging for shard counts (#25378) (#25507)
Browse files Browse the repository at this point in the history
* feat(logging): Add startup logging for shard counts (#25378)
This PR adds a check to see how many shards are remaining
vs how many shards are opened. This change displays the percent
completed too.

closes influxdata/feature-requests#476

(cherry picked from commit 3c87f52)

closes #25506

(cherry picked from commit 2ffb108)
  • Loading branch information
devanbenz committed Nov 1, 2024
1 parent f3d5325 commit 153a1fe
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 108 deletions.
32 changes: 32 additions & 0 deletions cmd/influxd/run/startup_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package run

import (
"fmt"
"sync/atomic"

"go.uber.org/zap"
)

type StartupProgressLogger struct {
shardsCompleted atomic.Uint64
shardsTotal atomic.Uint64
logger *zap.Logger
}

func NewStartupProgressLogger(logger *zap.Logger) *StartupProgressLogger {
return &StartupProgressLogger{
logger: logger,
}
}

func (s *StartupProgressLogger) AddShard() {
s.shardsTotal.Add(1)
}

func (s *StartupProgressLogger) CompletedShard() {
shardsCompleted := s.shardsCompleted.Add(1)
totalShards := s.shardsTotal.Load()

percentShards := float64(shardsCompleted) / float64(totalShards) * 100
s.logger.Info(fmt.Sprintf("Finished loading shard, current progress %.1f%% shards (%d / %d).", percentShards, shardsCompleted, totalShards))
}
4 changes: 4 additions & 0 deletions storage/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/cmd/influxd/run"
"github.com/influxdata/influxdb/v2/influxql/query"
"github.com/influxdata/influxdb/v2/kit/platform"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
Expand Down Expand Up @@ -167,6 +168,9 @@ func (e *Engine) WithLogger(log *zap.Logger) {
if e.precreatorService != nil {
e.precreatorService.WithLogger(log)
}

sl := run.NewStartupProgressLogger(e.logger)
e.tsdbStore.WithStartupMetrics(sl)
}

// PrometheusCollectors returns all the prometheus collectors associated with
Expand Down
Loading

0 comments on commit 153a1fe

Please sign in to comment.