Skip to content

Commit ec85393

Browse files
committed
Add logging to flushing
1 parent 982333c commit ec85393

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

cmd/maps-tile-uploader/flush_strategy.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"log/slog"
56
"time"
67

78
"github.com/cinode/go/pkg/cinodefs"
@@ -18,11 +19,13 @@ func NewFlushStrategy(
1819
fs cinodefs.FS,
1920
cfg FlushStrategyConfig,
2021
timeSource func() time.Time,
22+
log *slog.Logger,
2123
) FlushStrategy {
2224
return &flushStrategy{
2325
fs: fs,
2426
cfg: cfg,
2527
timeSource: timeSource,
28+
log: log,
2629
}
2730
}
2831

@@ -38,9 +41,11 @@ type flushStrategy struct {
3841
lastFlushTime time.Time
3942
cfg FlushStrategyConfig
4043
timeSource func() time.Time
44+
log *slog.Logger
4145
}
4246

43-
func (f *flushStrategy) flush(ctx context.Context) error {
47+
func (f *flushStrategy) flush(ctx context.Context, reason string) error {
48+
f.log.InfoContext(ctx, "Flushing filesystem", "reason", reason)
4449
if err := f.fs.Flush(ctx); err != nil {
4550
return err
4651
}
@@ -59,29 +64,29 @@ func (f *flushStrategy) FlushOpportunity(ctx context.Context) error {
5964
return nil
6065
}
6166

62-
return f.flush(ctx)
67+
return f.flush(ctx, "maxFlushInterval reached")
6368
}
6469

6570
func (f *flushStrategy) ColumnFinished(ctx context.Context, isDetailedRegion bool) error {
6671
if isDetailedRegion && f.cfg.FlushOnDetailedColumnFinished {
67-
return f.flush(ctx)
72+
return f.flush(ctx, "detailed column finished")
6873
}
6974

7075
if f.cfg.FlushOnColumnFinished {
71-
return f.flush(ctx)
76+
return f.flush(ctx, "column finished")
7277
}
7378

7479
return nil
7580
}
7681

7782
func (f *flushStrategy) ZLayerFinished(ctx context.Context) error {
7883
if f.cfg.FlushOnZLayerFinished {
79-
return f.flush(ctx)
84+
return f.flush(ctx, "zoom layer finished")
8085
}
8186

8287
return nil
8388
}
8489

8590
func (f *flushStrategy) ProcessFinished(ctx context.Context) error {
86-
return f.flush(ctx)
91+
return f.flush(ctx, "process finished")
8792
}

cmd/maps-tile-uploader/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ func main() {
9898
fmt.Printf(" WriterInfo: %s\n", golang.Must(fs.RootWriterInfo(ctx)))
9999
}
100100

101+
log := slog.Default()
102+
101103
gen := tilesGenerator{
102104
cfg: cfg,
103105
fs: fs,
104-
log: slog.Default(),
105-
flush: NewFlushStrategy(fs, cfg.FlushStrategy, time.Now),
106+
log: log,
107+
flush: NewFlushStrategy(fs, cfg.FlushStrategy, time.Now, log),
106108
}
107109

108110
err = gen.Process(ctx)
109111
if err != nil {
110-
log.Fatal(err)
112+
log.ErrorContext(ctx, "Failed to process tiles", "err", err)
113+
os.Exit(1)
111114
}
112115
}
113116

0 commit comments

Comments
 (0)