Skip to content

Commit 900e44d

Browse files
authored
feat(logging): Add startup logging for shard counts (#25378) (#25507) (#25509)
1 parent f3d5325 commit 900e44d

File tree

4 files changed

+359
-108
lines changed

4 files changed

+359
-108
lines changed

cmd/influxd/run/startup_logger.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package run
2+
3+
import (
4+
"fmt"
5+
"sync/atomic"
6+
7+
"go.uber.org/zap"
8+
)
9+
10+
type StartupProgressLogger struct {
11+
shardsCompleted atomic.Uint64
12+
shardsTotal atomic.Uint64
13+
logger *zap.Logger
14+
}
15+
16+
func NewStartupProgressLogger(logger *zap.Logger) *StartupProgressLogger {
17+
return &StartupProgressLogger{
18+
logger: logger,
19+
}
20+
}
21+
22+
func (s *StartupProgressLogger) AddShard() {
23+
s.shardsTotal.Add(1)
24+
}
25+
26+
func (s *StartupProgressLogger) CompletedShard() {
27+
shardsCompleted := s.shardsCompleted.Add(1)
28+
totalShards := s.shardsTotal.Load()
29+
30+
percentShards := float64(shardsCompleted) / float64(totalShards) * 100
31+
s.logger.Info(fmt.Sprintf("Finished loading shard, current progress %.1f%% shards (%d / %d).", percentShards, shardsCompleted, totalShards))
32+
}

storage/engine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/influxdata/influxdb/v2"
12+
"github.com/influxdata/influxdb/v2/cmd/influxd/run"
1213
"github.com/influxdata/influxdb/v2/influxql/query"
1314
"github.com/influxdata/influxdb/v2/kit/platform"
1415
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
@@ -167,6 +168,9 @@ func (e *Engine) WithLogger(log *zap.Logger) {
167168
if e.precreatorService != nil {
168169
e.precreatorService.WithLogger(log)
169170
}
171+
172+
sl := run.NewStartupProgressLogger(e.logger)
173+
e.tsdbStore.WithStartupMetrics(sl)
170174
}
171175

172176
// PrometheusCollectors returns all the prometheus collectors associated with

0 commit comments

Comments
 (0)