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

feat(logging): Add startup logging for shard counts #25378

Open
wants to merge 13 commits into
base: master-1.x
Choose a base branch
from
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