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

Add irate #897

Merged
merged 10 commits into from
Sep 14, 2018
Merged

Add irate #897

merged 10 commits into from
Sep 14, 2018

Conversation

benraskin92
Copy link
Collaborator

No description provided.

}
}

// func TestUnknownAggregation(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit delete

return math.NaN()
}

// {0, 1, 2, 3, 4},
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete

@codecov
Copy link

codecov bot commented Sep 12, 2018

Codecov Report

Merging #897 into master will increase coverage by 0.1%.
The diff coverage is 87.23%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#dbnode 81.51% <ø> (+0.12%) ⬆️
#m3ninx 71.93% <ø> (ø) ⬆️
#query 67.84% <87.23%> (+0.12%) ⬆️

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 721ac92...8774436. Read the comment docs.

@benraskin92 benraskin92 changed the title [WIP] Add irate Add irate Sep 12, 2018
}

func (r *rateNode) Process(values []float64) float64 {
switch r.op.operatorType {
Copy link
Contributor

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

)

const (
// IRateTemporalType calculates the per-second instant rate of increase of the time series
Copy link
Contributor

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.

previousSample := values[nonNanIdx]

var resultValue float64
if isRate && lastSample < previousSample {
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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

}

func instantValue(values []float64, isRate bool, stepSize time.Duration) float64 {
fmt.Println(values)
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete

}

func (r *rateNode) Process(values []float64) float64 {
switch r.op.operatorType {
Copy link
Collaborator

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.

lastSample := values[valuesLen-1]
previousSample := values[valuesLen-2]

fmt.Println(lastSample, previousSample)
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete

return i
}
}
return -1
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit newline

if nonNanIdx < 1 {
return math.NaN()
}
lastSample := values[nonNanIdx]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit newline

if nonNanIdx == -1 {
return math.NaN()
}
previousSample := values[nonNanIdx]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit newline

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Think this is fine :)

Copy link
Collaborator

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

}

if isRate {
resultValue /= float64(stepSize) / math.Pow10(9)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two things here;

  1. I think this is wrong; you should be multiplying stepSize by the difference between indices for lastSample and previousSample

  2. It's a bit confusing to do x /= y / z, better to write this as
    resultValue *= float64(time.Second)
    resultValue /= float64(stepSize * (indexLast - indexPrevious))

nikunjgit
nikunjgit previously approved these changes Sep 14, 2018
}
}

func TestFindNonNanIdx(t *testing.T) {
Copy link
Collaborator

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

return math.NaN()
}

var indexLast int
Copy link
Collaborator

@arnikola arnikola Sep 14, 2018

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


nonNanIdx := valuesLen - 1
// find idx for last non-NaN value
nonNanIdx = findNonNanIdx(values, nonNanIdx)
Copy link
Collaborator

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

if nonNanIdx < 1 {
return math.NaN()
}
indexLast = nonNanIdx
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: newline

return -1
}

func instantValue(values []float64, isRate bool, stepSize time.Duration) float64 {
Copy link
Collaborator

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

)

const (
// IRateTemporalType calculates the per-second rate of increase of the time series
Copy link
Collaborator

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


// IDeltaTemporalType calculates the difference between the last two values in the time series.
// IDeltaTemporalType should only be used with gauges.
IDeltaTemporalType = "idelta"
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment here

}

func newRateNode(op baseOp, controller *transform.Controller, opts transform.Options) Processor {
var isRate bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

isRate := op.operatorType == IRateTemporalType

return math.NaN()
}

lastSample := values[indexLast]
Copy link
Collaborator

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

@benraskin92 benraskin92 merged commit 7adcd64 into master Sep 14, 2018
@prateek prateek deleted the braskin/add_irate branch September 29, 2018 18:08
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.

3 participants