-
Notifications
You must be signed in to change notification settings - Fork 454
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
Add irate #897
Add irate #897
Conversation
} | ||
} | ||
|
||
// func TestUnknownAggregation(t *testing.T) { |
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 delete
src/query/functions/temporal/rate.go
Outdated
return math.NaN() | ||
} | ||
|
||
// {0, 1, 2, 3, 4}, |
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.
delete
2883443
to
2cf04be
Compare
5256f8f
to
ec8739b
Compare
Codecov Report
@@ Coverage Diff @@
## master #897 +/- ##
=========================================
+ Coverage 78.29% 78.39% +0.1%
=========================================
Files 397 398 +1
Lines 33799 33844 +45
=========================================
+ Hits 26462 26533 +71
+ Misses 5520 5501 -19
+ Partials 1817 1810 -7
Continue to review full report at Codecov.
|
src/query/functions/temporal/rate.go
Outdated
} | ||
|
||
func (r *rateNode) Process(values []float64) float64 { | ||
switch r.op.operatorType { |
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.
instead of doing this, the node can just store a boolean isRate. In Process, just pass that boolean in. This way you don't have to look at operatorType in node
src/query/functions/temporal/rate.go
Outdated
) | ||
|
||
const ( | ||
// IRateTemporalType calculates the per-second instant rate of increase of the time series |
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.
fix comment ? we don't have instant/ range vector concept.
src/query/functions/temporal/rate.go
Outdated
previousSample := values[nonNanIdx] | ||
|
||
var resultValue float64 | ||
if isRate && lastSample < previousSample { |
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.
i think you need reset for both types ?
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.
Not according to Prom logic
src/query/functions/temporal/rate.go
Outdated
} | ||
|
||
func instantValue(values []float64, isRate bool, stepSize time.Duration) float64 { | ||
fmt.Println(values) |
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.
delete
src/query/functions/temporal/rate.go
Outdated
} | ||
|
||
func (r *rateNode) Process(values []float64) float64 { | ||
switch r.op.operatorType { |
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.
No need to check operator type in the process function.
src/query/functions/temporal/rate.go
Outdated
lastSample := values[valuesLen-1] | ||
previousSample := values[valuesLen-2] | ||
|
||
fmt.Println(lastSample, previousSample) |
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.
delete
src/query/functions/temporal/rate.go
Outdated
return i | ||
} | ||
} | ||
return -1 |
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 newline
src/query/functions/temporal/rate.go
Outdated
if nonNanIdx < 1 { | ||
return math.NaN() | ||
} | ||
lastSample := values[nonNanIdx] |
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 newline
src/query/functions/temporal/rate.go
Outdated
if nonNanIdx == -1 { | ||
return math.NaN() | ||
} | ||
previousSample := values[nonNanIdx] |
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 newline
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.
Think this is fine :)
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.
I thought we were add newlines after each closing bracket with lines following it
src/query/functions/temporal/rate.go
Outdated
} | ||
|
||
if isRate { | ||
resultValue /= float64(stepSize) / math.Pow10(9) |
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.
Two things here;
-
I think this is wrong; you should be multiplying stepSize by the difference between indices for lastSample and previousSample
-
It's a bit confusing to do
x /= y / z
, better to write this as
resultValue *= float64(time.Second)
resultValue /= float64(stepSize * (indexLast - indexPrevious))
} | ||
} | ||
|
||
func TestFindNonNanIdx(t *testing.T) { |
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.
Either add test or delete this function
src/query/functions/temporal/rate.go
Outdated
return math.NaN() | ||
} | ||
|
||
var indexLast int |
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.
Don't need this, just initialize the var when you need it
src/query/functions/temporal/rate.go
Outdated
|
||
nonNanIdx := valuesLen - 1 | ||
// find idx for last non-NaN value | ||
nonNanIdx = findNonNanIdx(values, nonNanIdx) |
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.
You can doindexLast := findNonNanIdx(values, nonNanIdx)
instead
src/query/functions/temporal/rate.go
Outdated
if nonNanIdx < 1 { | ||
return math.NaN() | ||
} | ||
indexLast = nonNanIdx |
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: newline
src/query/functions/temporal/rate.go
Outdated
return -1 | ||
} | ||
|
||
func instantValue(values []float64, isRate bool, stepSize time.Duration) float64 { |
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.
This function isn't necessary, you can move the logic into the Process()
function instead
src/query/functions/temporal/rate.go
Outdated
) | ||
|
||
const ( | ||
// IRateTemporalType calculates the per-second rate of increase of the time series |
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.
IRateType is fine since it's in temporal, otherwise you have temporal.IRateTemporal
src/query/functions/temporal/rate.go
Outdated
|
||
// IDeltaTemporalType calculates the difference between the last two values in the time series. | ||
// IDeltaTemporalType should only be used with gauges. | ||
IDeltaTemporalType = "idelta" |
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.
same comment here
src/query/functions/temporal/rate.go
Outdated
} | ||
|
||
func newRateNode(op baseOp, controller *transform.Controller, opts transform.Options) Processor { | ||
var isRate bool |
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.
isRate := op.operatorType == IRateTemporalType
src/query/functions/temporal/rate.go
Outdated
return math.NaN() | ||
} | ||
|
||
lastSample := values[indexLast] |
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: since you keep track of this index, you can define lastSample
lower down, closer to where you use it
No description provided.