Skip to content

Commit

Permalink
feat(tsdb): Adds shard opening progress checks to startup
Browse files Browse the repository at this point in the history
This PR adds a check to see how many shards are remaining
vs how many shards are opened as well as the percentage.

closes influxdata/feature-requests#476
  • Loading branch information
devanbenz committed Sep 25, 2024
1 parent 599e4f7 commit 26de392
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 118 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
15 changes: 15 additions & 0 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ type BuildInfo struct {
Time string
}

type StartupProgress interface {
AddShard()
RemoveShardFromCount()
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 +102,8 @@ type Server struct {

Monitor *monitor.Monitor

StartupProgressMetrics StartupProgress

// Server reporting and registration
reportingDisabled bool

Expand Down Expand Up @@ -279,6 +287,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 +477,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
39 changes: 39 additions & 0 deletions cmd/influxd/run/startup_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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) RemoveShardFromCount() {
if s.shardsTotal.Load() > 0 {
old, newUint := s.shardsTotal.Load(), s.shardsTotal.Load()-1
s.shardsTotal.CompareAndSwap(old, newUint)
}
}

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 26de392

Please sign in to comment.