mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* Initial retention job * Generate manifest * Clean up retention test * Lint * Fix work test for compaction job * Add provider package to handle the job loops * Improve nil job handling * Refactor backendscheduler to leverage provider * Generate manifest * Pick pint * Fix race in shutdown * Fix race in test * Drop spurious debug messages * Include compaction backoff when no compactions are needed * Configure the test backoff * Drop comment * Fix regression so we skip blocks which are already mentioned * Drop unused config after relocate * Leverage existing interface for HasBlocks call on compaction * Clean up config * Drop unused method * Improve retention test coverage * Clean, trace and metric the scheduler * Clean, trace and metric the compaction provider; prefer backoff over poll interval * Generate manifest, update test config reference * Fix lint * Avoid channel block for context handling * Address PR feedback
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/go-kit/log"
|
|
"github.com/grafana/tempo/modules/backendscheduler/work"
|
|
"github.com/grafana/tempo/pkg/tempopb"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRetentionProvider(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
defer cancel()
|
|
|
|
cfg := RetentionConfig{}
|
|
cfg.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{})
|
|
cfg.Interval = 10 * time.Millisecond
|
|
|
|
workCfg := work.Config{}
|
|
workCfg.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{})
|
|
w := work.New(workCfg)
|
|
|
|
logger := log.NewLogfmtLogger(os.Stderr)
|
|
|
|
p := NewRetentionProvider(
|
|
cfg,
|
|
logger,
|
|
w,
|
|
)
|
|
|
|
jobChan := p.Start(ctx)
|
|
|
|
var receivedJobs []*work.Job
|
|
for job := range jobChan {
|
|
err := w.AddJob(job)
|
|
if job == nil {
|
|
require.Error(t, err)
|
|
require.Equal(t, work.ErrJobNil, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
require.Equal(t, tempopb.JobType_JOB_TYPE_RETENTION, job.Type)
|
|
require.Equal(t, "", job.Tenant())
|
|
job.Start() // mark the job as started so that we avoid new retention jobs
|
|
}
|
|
|
|
receivedJobs = append(receivedJobs, job)
|
|
}
|
|
|
|
// Since we started only one job, no other jobs should be in the queue
|
|
require.Len(t, receivedJobs, 1)
|
|
}
|