Skip to content
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

Merged
merged 3 commits into from
Oct 27, 2021

Conversation

linasm
Copy link
Collaborator

@linasm linasm commented Oct 27, 2021

What this PR does / why we need it:
Allows setting relative decrease tolerance up to which value decreases are eliminated while decoding time series data.

Special notes for your reviewer:
See #3872.

Does this PR introduce a user-facing and/or backwards incompatible change?:
NONE

Does this PR require updating code package or user-facing documentation?:
NONE

@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #3876 (c4c1f8b) into master (80730d2) will increase coverage by 0.0%.
The diff coverage is 41.1%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #3876   +/-   ##
======================================
  Coverage    57.0%   57.0%           
======================================
  Files         552     552           
  Lines       63263   63279   +16     
======================================
+ Hits        36062   36099   +37     
+ Misses      23996   23966   -30     
- Partials     3205    3214    +9     
Flag Coverage Δ
aggregator 64.3% <ø> (-0.2%) ⬇️
cluster ∅ <ø> (∅)
collector 58.4% <ø> (ø)
dbnode 60.5% <41.1%> (+0.1%) ⬆️
m3em 46.4% <ø> (ø)
metrics 19.7% <ø> (ø)
msg 74.2% <ø> (-0.3%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80730d2...c4c1f8b. Read the comment docs.

!first && currValue < prevValue && currValue > prevValue*(1-decreaseTolerance) {
currValue = prevValue
}
it.curr.Value = currValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: to me a more readable approach would be:

decreaseTolerance, toleranceUntil := it.opts.ValueDecreaseTolerance()
if decreaseTolerance > 0 {
  // do new logic
} else {
  it.curr.Value = currValue
}

I guess it's not idiomatic Go code, but it clearly separates 2 code paths - when tolerance is set and when it is not.

@@ -53,6 +53,9 @@ type options struct {
iStreamReaderSizeM3TSZ int
iStreamReaderSizeProto int
metrics Metrics

valueDecreaseTolerance float64
valueDecreaseToleranceUntil xtime.UnixNano
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there some advantage of using prevValue*(1-decreaseTolerance) and not simply delta? Like if current value is smaller then prev value by 0.00001 we say it's the same value?

With multiplication depending on how large the value is different can be bigger. Maybe that's the intention?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

SetValueDecreaseTolerance(value float64) Options

// SetValueDecreaseToleranceUntil sets the timestamp (exclusive) until which the tolerance applies.
SetValueDecreaseToleranceUntil(value xtime.UnixNano) Options
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be set to the date when #3872 is deployed.

it.curr.Value = convertFromIntFloat(it.intVal, it.mult)
prevValue := it.curr.Value
currValue := convertFromIntFloat(it.intVal, it.mult)
decreaseTolerance, toleranceUntil := it.opts.ValueDecreaseTolerance()
Copy link
Collaborator

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))

Copy link
Collaborator Author

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.

Copy link
Collaborator

@robskillington robskillington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the minor nit comment, could take it or leave it though

@linasm linasm merged commit 0b2dece into master Oct 27, 2021
@linasm linasm deleted the linasm/decoder-value-decrease-tolerance branch October 27, 2021 12:56
linasm added a commit that referenced this pull request Nov 22, 2021
linasm added a commit that referenced this pull request Nov 22, 2021
…3876)" (#3939)

* Revert "[query] Optional value decrease tolerance in M3TSZ decoder (#3876)"

This reverts commit 0b2dece.

* Fix method comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants