Skip to content

Commit

Permalink
feat(logging): Add startup logging for shard counts (#25378)
Browse files Browse the repository at this point in the history
* feat(tsdb): Adds shard opening progress checks to startup
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
  • Loading branch information
devanbenz authored Oct 16, 2024
1 parent 860a74f commit 3c87f52
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 178 deletions.
4 changes: 4 additions & 0 deletions cmd/influxd/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (cmd *Command) Run(args ...string) error {
s.Logger = cmd.Logger
s.CPUProfile = options.CPUProfile
s.MemProfile = options.MemProfile

sl := NewStartupProgressLogger(s.Logger)
s.SetStartupMetrics(sl)

if err := s.Open(); err != nil {
return fmt.Errorf("open server: %s", err)
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ type BuildInfo struct {
Time string
}

type StartupProgress interface {
AddShard()
CompletedShard()
}

// Server represents a container for the metadata and storage data and services.
// It is built using a Config and it manages the startup and shutdown of all
// services in the proper order.
Expand Down Expand Up @@ -96,6 +101,8 @@ type Server struct {

Monitor *monitor.Monitor

StartupProgressMetrics StartupProgress

// Server reporting and registration
reportingDisabled bool

Expand Down Expand Up @@ -279,6 +286,10 @@ func (s *Server) SetLogOutput(w io.Writer) {
s.MuxLogger = tcp.MuxLogger(w)
}

func (s *Server) SetStartupMetrics(sp StartupProgress) {
s.StartupProgressMetrics = sp
}

func (s *Server) appendMonitorService() {
s.Services = append(s.Services, s.Monitor)
}
Expand Down Expand Up @@ -465,6 +476,9 @@ func (s *Server) Open() error {
s.MetaClient.WithLogger(s.Logger)
}
s.TSDBStore.WithLogger(s.Logger)

s.TSDBStore.WithStartupMetrics(s.StartupProgressMetrics)

if s.config.Data.QueryLogEnabled {
s.QueryExecutor.WithLogger(s.Logger)
} else if s.config.Coordinator.LogQueriesAfter > 0 || s.config.Coordinator.LogTimedOutQueries {
Expand Down
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))
}
Loading

0 comments on commit 3c87f52

Please sign in to comment.