Skip to content

Commit

Permalink
Removed SetOutOfOrderTimeWindow
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Rabenhorst <[email protected]>
  • Loading branch information
rabenhorst committed May 24, 2024
1 parent 157ec2e commit 74aa743
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 deletions.
23 changes: 13 additions & 10 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,7 @@ func main() {
}
if agentMode {
// WAL storage.
opts := cfg.agent.ToAgentOptions()
opts.SetOutOfOrderTimeWindow(cfg.tsdb.OutOfOrderTimeWindow)
opts := cfg.agent.ToAgentOptions(cfg.tsdb.OutOfOrderTimeWindow)
cancel := make(chan struct{})
g.Add(
func() error {
Expand Down Expand Up @@ -1712,15 +1711,19 @@ type agentOptions struct {
OutOfOrderTimeWindow int64
}

func (opts agentOptions) ToAgentOptions() agent.Options {
func (opts agentOptions) ToAgentOptions(outOfOrderTimeWindow int64) agent.Options {
if outOfOrderTimeWindow < 0 {
outOfOrderTimeWindow = 0
}
return agent.Options{
WALSegmentSize: int(opts.WALSegmentSize),
WALCompression: wlog.ParseCompressionType(opts.WALCompression, opts.WALCompressionType),
StripeSize: opts.StripeSize,
TruncateFrequency: time.Duration(opts.TruncateFrequency),
MinWALTime: durationToInt64Millis(time.Duration(opts.MinWALTime)),
MaxWALTime: durationToInt64Millis(time.Duration(opts.MaxWALTime)),
NoLockfile: opts.NoLockfile,
WALSegmentSize: int(opts.WALSegmentSize),
WALCompression: wlog.ParseCompressionType(opts.WALCompression, opts.WALCompressionType),
StripeSize: opts.StripeSize,
TruncateFrequency: time.Duration(opts.TruncateFrequency),
MinWALTime: durationToInt64Millis(time.Duration(opts.MinWALTime)),
MaxWALTime: durationToInt64Millis(time.Duration(opts.MaxWALTime)),
NoLockfile: opts.NoLockfile,
OutOfOrderTimeWindow: outOfOrderTimeWindow,
}
}

Expand Down
7 changes: 0 additions & 7 deletions tsdb/agent/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ type Options struct {
OutOfOrderTimeWindow int64
}

func (o *Options) SetOutOfOrderTimeWindow(outOfOrderTimeWindow int64) {
if outOfOrderTimeWindow < 0 {
return
}
o.OutOfOrderTimeWindow = outOfOrderTimeWindow
}

// DefaultOptions used for the WAL storage. They are reasonable for setups using
// millisecond-precision timestamps.
func DefaultOptions() *Options {
Expand Down
29 changes: 12 additions & 17 deletions tsdb/agent/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func TestDBAllowOOOSamples(t *testing.T) {

reg := prometheus.NewRegistry()
opts := DefaultOptions()
opts.SetOutOfOrderTimeWindow(math.MaxInt64)
opts.OutOfOrderTimeWindow = math.MaxInt64
s := createTestAgentDB(t, reg, opts)
app := s.Appender(context.TODO())

Expand Down Expand Up @@ -885,36 +885,31 @@ func TestDBAllowOOOSamples(t *testing.T) {
func TestDBOutOfOrderTimeWindow(t *testing.T) {
tc := []struct {
outOfOrderTimeWindow, firstTs, secondTs int64
reject bool
expectedError error
}{
{0, 100, 101, false},
{0, 100, 100, true},
{0, 100, 99, true},
{100, 100, 1, false},
{100, 100, 0, true},
{0, 100, 101, nil},
{0, 100, 100, storage.ErrOutOfOrderSample},
{0, 100, 99, storage.ErrOutOfOrderSample},
{100, 100, 1, nil},
{100, 100, 0, storage.ErrOutOfOrderSample},
}

for _, c := range tc {
t.Run(fmt.Sprintf("outOfOrderTimeWindow=%d, firstTs=%d, secondTs=%d, reject=%t", c.outOfOrderTimeWindow, c.firstTs, c.secondTs, c.reject), func(t *testing.T) {
t.Run(fmt.Sprintf("outOfOrderTimeWindow=%d, firstTs=%d, secondTs=%d, expectedError=%s", c.outOfOrderTimeWindow, c.firstTs, c.secondTs, c.expectedError), func(t *testing.T) {
reg := prometheus.NewRegistry()
opts := DefaultOptions()
opts.SetOutOfOrderTimeWindow(c.outOfOrderTimeWindow)
opts.OutOfOrderTimeWindow = c.outOfOrderTimeWindow
s := createTestAgentDB(t, reg, opts)
app := s.Appender(context.TODO())

var expectedErr error
if c.reject {
expectedErr = storage.ErrOutOfOrderSample
}

lbls := labelsForTest(t.Name()+"_histogram", 1)
lset := labels.New(lbls[0]...)
_, err := app.AppendHistogram(0, lset, c.firstTs, tsdbutil.GenerateTestHistograms(1)[0], nil)
require.NoError(t, err)
err = app.Commit()
require.NoError(t, err)
_, err = app.AppendHistogram(0, lset, c.secondTs, tsdbutil.GenerateTestHistograms(1)[0], nil)
require.ErrorIs(t, err, expectedErr)
require.ErrorIs(t, err, c.expectedError)

lbls = labelsForTest(t.Name(), 1)
lset = labels.New(lbls[0]...)
Expand All @@ -923,10 +918,10 @@ func TestDBOutOfOrderTimeWindow(t *testing.T) {
err = app.Commit()
require.NoError(t, err)
_, err = app.Append(0, lset, c.secondTs, 0)
require.ErrorIs(t, err, expectedErr)
require.ErrorIs(t, err, c.expectedError)

expectedAppendedSamples := float64(2)
if c.reject {
if c.expectedError != nil {
expectedAppendedSamples = 1
}
m := gatherFamily(t, reg, "prometheus_agent_samples_appended_total")
Expand Down

0 comments on commit 74aa743

Please sign in to comment.