Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,19 @@ func (edm *dnstapMinimiser) reverseLabelsBounded(labels []string, maxLen int) []
return boundedReverseLabels
}

const sentHistogramRetention = 24 * time.Hour

func sentHistogramExpired(modTime, now time.Time) bool {
return now.Sub(modTime) > sentHistogramRetention
}

func (edm *dnstapMinimiser) diskCleaner(wg *sync.WaitGroup, sentDir string) {
// We will scan the directory each tick for sent files to remove.
defer wg.Done()

ticker := time.NewTicker(time.Second * 60)
defer ticker.Stop()

oneDay := time.Hour * 12

timerLoop:
for {
select {
Expand All @@ -397,7 +401,7 @@ timerLoop:
continue
}

if time.Since(fileInfo.ModTime()) > oneDay {
if sentHistogramExpired(fileInfo.ModTime(), time.Now()) {
absPath := filepath.Join(sentDir, dirEntry.Name())
edm.log.Info("diskCleaner: removing file", "filename", absPath)
err = os.Remove(absPath)
Expand Down
12 changes: 12 additions & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2145,3 +2145,15 @@ func TestWriteHistogramParquetExplicitThreshold(t *testing.T) {
}
}
}

func TestDiskCleanerRetentionThreshold(t *testing.T) {
now := time.Date(2026, 4, 30, 12, 0, 0, 0, time.UTC)

if !sentHistogramExpired(now.Add(-25*time.Hour), now) {
t.Fatal("histogram older than 24 hours should expire")
}

if sentHistogramExpired(now.Add(-23*time.Hour), now) {
t.Fatal("histogram newer than 24 hours should not expire")
}
}