From a975a830796aa4ff2b6b9aa688d12eb4a3a6cdf8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 22 Feb 2024 09:19:18 +0000 Subject: [PATCH] tsdb: clean up Watcher debug messages Print lastSegment after it gets initialized. Move variable declaration to first use. Signed-off-by: Bryan Boreham --- tsdb/wlog/watcher.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tsdb/wlog/watcher.go b/tsdb/wlog/watcher.go index 525515221d..bd74c1b024 100644 --- a/tsdb/wlog/watcher.go +++ b/tsdb/wlog/watcher.go @@ -262,9 +262,6 @@ func (w *Watcher) loop() { // Run the watcher, which will tail the WAL until the quit channel is closed // or an error case is hit. func (w *Watcher) Run() error { - var lastSegment int - var err error - // We want to ensure this is false across iterations since // Run will be called again if there was a failure to read the WAL. w.sendSamples = false @@ -289,19 +286,19 @@ func (w *Watcher) Run() error { return err } - level.Debug(w.logger).Log("msg", "Tailing WAL", "lastCheckpoint", lastCheckpoint, "checkpointIndex", checkpointIndex, "currentSegment", currentSegment, "lastSegment", lastSegment) + level.Debug(w.logger).Log("msg", "Tailing WAL", "lastCheckpoint", lastCheckpoint, "checkpointIndex", checkpointIndex, "currentSegment", currentSegment) for !isClosed(w.quit) { w.currentSegmentMetric.Set(float64(currentSegment)) - level.Debug(w.logger).Log("msg", "Processing segment", "currentSegment", currentSegment) // Reset the value of lastSegment each iteration, this is to avoid having to wait too long for // between reads if we're reading a segment that is not the most recent segment after startup. - _, lastSegment, err = w.firstAndLast() + _, lastSegment, err := w.firstAndLast() if err != nil { return fmt.Errorf("wal.Segments: %w", err) } tail := currentSegment >= lastSegment + level.Debug(w.logger).Log("msg", "Processing segment", "currentSegment", currentSegment, "lastSegment", lastSegment) // On start, after reading the existing WAL for series records, we have a pointer to what is the latest segment. // On subsequent calls to this function, currentSegment will have been incremented and we should open that segment. if err := w.watch(currentSegment, tail); err != nil && !errors.Is(err, ErrIgnorable) {