-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[query] Optional value decrease tolerance in M3TSZ decoder #3876
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,14 @@ func (it *readerIterator) Next() bool { | |
if !it.intOptimized || it.isFloat { | ||
it.curr.Value = math.Float64frombits(it.floatIter.PrevFloatBits) | ||
} else { | ||
it.curr.Value = convertFromIntFloat(it.intVal, it.mult) | ||
prevValue := it.curr.Value | ||
currValue := convertFromIntFloat(it.intVal, it.mult) | ||
decreaseTolerance, toleranceUntil := it.opts.ValueDecreaseTolerance() | ||
if decreaseTolerance > 0 && it.curr.TimestampNanos.Before(toleranceUntil) && | ||
!first && currValue < prevValue && currValue > prevValue*(1-decreaseTolerance) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there some advantage of using With multiplication depending on how large the value is different can be bigger. Maybe that's the intention? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolute delta would not work when your actual values themselves are smaller than that delta. |
||
currValue = prevValue | ||
} | ||
it.curr.Value = currValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: to me a more readable approach would be:
I guess it's not idiomatic Go code, but it clearly separates 2 code paths - when tolerance is set and when it is not. |
||
} | ||
|
||
return it.hasNext() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,9 @@ type options struct { | |
iStreamReaderSizeM3TSZ int | ||
iStreamReaderSizeProto int | ||
metrics Metrics | ||
|
||
valueDecreaseTolerance float64 | ||
valueDecreaseToleranceUntil xtime.UnixNano | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: do you think maybe wrapping these under struct would be better? And make it optional. So that if its nil then decrease tolerance logic is not applied? Otherwise if its specified then it must not be 0 for both fields. |
||
} | ||
|
||
func newOptions() Options { | ||
|
@@ -191,3 +194,19 @@ func (o *options) SetMetrics(value Metrics) Options { | |
func (o *options) Metrics() Metrics { | ||
return o.metrics | ||
} | ||
|
||
func (o *options) SetValueDecreaseTolerance(value float64) Options { | ||
opts := *o | ||
opts.valueDecreaseTolerance = value | ||
return &opts | ||
} | ||
|
||
func (o *options) SetValueDecreaseToleranceUntil(value xtime.UnixNano) Options { | ||
opts := *o | ||
opts.valueDecreaseToleranceUntil = value | ||
return &opts | ||
} | ||
|
||
func (o *options) ValueDecreaseTolerance() (float64, xtime.UnixNano) { | ||
return o.valueDecreaseTolerance, o.valueDecreaseToleranceUntil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,7 @@ type Options interface { | |
// for proto encoding iteration. | ||
SetIStreamReaderSizeProto(value int) Options | ||
|
||
// SetIStreamReaderSizeProto returns the IStream bufio reader size | ||
// IStreamReaderSizeProto returns the IStream bufio reader size | ||
// for proto encoding iteration. | ||
IStreamReaderSizeProto() int | ||
|
||
|
@@ -171,6 +171,15 @@ type Options interface { | |
|
||
// Metrics returns the encoding metrics. | ||
Metrics() Metrics | ||
|
||
// SetValueDecreaseTolerance sets relative tolerance against decoded time series value decrease. | ||
SetValueDecreaseTolerance(value float64) Options | ||
|
||
// SetValueDecreaseToleranceUntil sets the timestamp (exclusive) until which the tolerance applies. | ||
SetValueDecreaseToleranceUntil(value xtime.UnixNano) Options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to have a timestamp until the tolerance applies? Does this mean that it should be set on each iteration? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be set to the date when #3872 is deployed. |
||
|
||
// ValueDecreaseTolerance returns relative tolerance against decoded time series value decrease. | ||
ValueDecreaseTolerance() (float64, xtime.UnixNano) | ||
} | ||
|
||
// Iterator is the generic interface for iterating over encoded data. | ||
|
@@ -210,7 +219,7 @@ type MultiReaderIterator interface { | |
Reset(readers []xio.SegmentReader, start xtime.UnixNano, | ||
blockSize time.Duration, schema namespace.SchemaDescr) | ||
|
||
// Reset resets the iterator to read from a slice of slice readers | ||
// ResetSliceOfSlices resets the iterator to read from a slice of slice readers | ||
// with a new schema (for schema aware iterators). | ||
ResetSliceOfSlices( | ||
readers xio.ReaderSliceOfSlicesIterator, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You may want to allow toleranceUntil to be zero and if so then always apply? Just thinking instead of needing to set it to MaxTime or something if you want it on for good.
e.g.
(toleranceUntil.IsZero() || it.curr.TimestampNanos.Before(toleranceUntil))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be set to something like 2099-12-31 for such use cases. Don't want to add any more conditionals there.