fix(scanner): update prometheus at the end of the scan (#4163)
* fix(scannner): use prometheus instance over noop if configured properly * Real Fix: move `WriteAfterScanMetrics` outside gofunc * refactor: remove unused artwork.CacheWarmer param from CallScan function Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
+1
-3
@@ -6,8 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/core"
|
"github.com/navidrome/navidrome/core"
|
||||||
"github.com/navidrome/navidrome/core/artwork"
|
|
||||||
"github.com/navidrome/navidrome/core/metrics"
|
|
||||||
"github.com/navidrome/navidrome/db"
|
"github.com/navidrome/navidrome/db"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/persistence"
|
"github.com/navidrome/navidrome/persistence"
|
||||||
@@ -70,7 +68,7 @@ func runScanner(ctx context.Context) {
|
|||||||
ds := persistence.New(sqlDB)
|
ds := persistence.New(sqlDB)
|
||||||
pls := core.NewPlaylists(ds)
|
pls := core.NewPlaylists(ds)
|
||||||
|
|
||||||
progress, err := scanner.CallScan(ctx, ds, artwork.NoopCacheWarmer(), pls, metrics.NewNoopInstance(), fullScan)
|
progress, err := scanner.CallScan(ctx, ds, pls, fullScan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(ctx, "Failed to scan", err)
|
log.Fatal(ctx, "Failed to scan", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,13 +63,12 @@ func (s *controller) getScanner() scanner {
|
|||||||
if conf.Server.DevExternalScanner {
|
if conf.Server.DevExternalScanner {
|
||||||
return &scannerExternal{}
|
return &scannerExternal{}
|
||||||
}
|
}
|
||||||
return &scannerImpl{ds: s.ds, cw: s.cw, pls: s.pls, metrics: s.metrics}
|
return &scannerImpl{ds: s.ds, cw: s.cw, pls: s.pls}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallScan starts an in-process scan of the music library.
|
// CallScan starts an in-process scan of the music library.
|
||||||
// This is meant to be called from the command line (see cmd/scan.go).
|
// This is meant to be called from the command line (see cmd/scan.go).
|
||||||
func CallScan(ctx context.Context, ds model.DataStore, cw artwork.CacheWarmer, pls core.Playlists,
|
func CallScan(ctx context.Context, ds model.DataStore, pls core.Playlists, fullScan bool) (<-chan *ProgressInfo, error) {
|
||||||
metrics metrics.Metrics, fullScan bool) (<-chan *ProgressInfo, error) {
|
|
||||||
release, err := lockScan(ctx)
|
release, err := lockScan(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -80,7 +79,7 @@ func CallScan(ctx context.Context, ds model.DataStore, cw artwork.CacheWarmer, p
|
|||||||
progress := make(chan *ProgressInfo, 100)
|
progress := make(chan *ProgressInfo, 100)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(progress)
|
defer close(progress)
|
||||||
scanner := &scannerImpl{ds: ds, cw: cw, pls: pls, metrics: metrics}
|
scanner := &scannerImpl{ds: ds, cw: artwork.NoopCacheWarmer(), pls: pls}
|
||||||
scanner.scanAll(ctx, fullScan, progress)
|
scanner.scanAll(ctx, fullScan, progress)
|
||||||
}()
|
}()
|
||||||
return progress, nil
|
return progress, nil
|
||||||
@@ -230,9 +229,11 @@ func (s *controller) ScanAll(requestCtx context.Context, fullScan bool) ([]strin
|
|||||||
}
|
}
|
||||||
// Send the final scan status event, with totals
|
// Send the final scan status event, with totals
|
||||||
if count, folderCount, err := s.getCounters(ctx); err != nil {
|
if count, folderCount, err := s.getCounters(ctx); err != nil {
|
||||||
|
s.metrics.WriteAfterScanMetrics(ctx, false)
|
||||||
return scanWarnings, err
|
return scanWarnings, err
|
||||||
} else {
|
} else {
|
||||||
scanType, elapsed, lastErr := s.getScanInfo(ctx)
|
scanType, elapsed, lastErr := s.getScanInfo(ctx)
|
||||||
|
s.metrics.WriteAfterScanMetrics(ctx, true)
|
||||||
s.sendMessage(ctx, &events.ScanStatus{
|
s.sendMessage(ctx, &events.ScanStatus{
|
||||||
Scanning: false,
|
Scanning: false,
|
||||||
Count: count,
|
Count: count,
|
||||||
|
|||||||
+3
-7
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
"github.com/navidrome/navidrome/core"
|
"github.com/navidrome/navidrome/core"
|
||||||
"github.com/navidrome/navidrome/core/artwork"
|
"github.com/navidrome/navidrome/core/artwork"
|
||||||
"github.com/navidrome/navidrome/core/metrics"
|
|
||||||
"github.com/navidrome/navidrome/db"
|
"github.com/navidrome/navidrome/db"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
@@ -19,10 +18,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type scannerImpl struct {
|
type scannerImpl struct {
|
||||||
ds model.DataStore
|
ds model.DataStore
|
||||||
cw artwork.CacheWarmer
|
cw artwork.CacheWarmer
|
||||||
pls core.Playlists
|
pls core.Playlists
|
||||||
metrics metrics.Metrics
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanState holds the state of an in-progress scan, to be passed to the various phases
|
// scanState holds the state of an in-progress scan, to be passed to the various phases
|
||||||
@@ -111,7 +109,6 @@ func (s *scannerImpl) scanAll(ctx context.Context, fullScan bool, progress chan<
|
|||||||
log.Error(ctx, "Scanner: Finished with error", "duration", time.Since(startTime), err)
|
log.Error(ctx, "Scanner: Finished with error", "duration", time.Since(startTime), err)
|
||||||
_ = s.ds.Property(ctx).Put(consts.LastScanErrorKey, err.Error())
|
_ = s.ds.Property(ctx).Put(consts.LastScanErrorKey, err.Error())
|
||||||
state.sendError(err)
|
state.sendError(err)
|
||||||
s.metrics.WriteAfterScanMetrics(ctx, false)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +118,6 @@ func (s *scannerImpl) scanAll(ctx context.Context, fullScan bool, progress chan<
|
|||||||
state.sendProgress(&ProgressInfo{ChangesDetected: true})
|
state.sendProgress(&ProgressInfo{ChangesDetected: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
s.metrics.WriteAfterScanMetrics(ctx, err == nil)
|
|
||||||
log.Info(ctx, "Scanner: Finished scanning all libraries", "duration", time.Since(startTime))
|
log.Info(ctx, "Scanner: Finished scanning all libraries", "duration", time.Since(startTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user