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

Node to detect changes between consecutive values in a series field #1844

Merged
merged 6 commits into from
Mar 9, 2018

Conversation

aanthony1243
Copy link
Contributor

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

@aanthony1243 aanthony1243 requested a review from nathanielc March 9, 2018 16:41
Copy link
Contributor

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

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

Looks great!. There are a few spots that can be simplified, I noted them in the comments below.

change_detect.go Outdated
if s := begin.SizeHint(); s > 0 {
begin = begin.ShallowCopy()
begin.SetSizeHint(s - 1)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This size hinting is not relevant to the change detect node, meaning its now know that the batch size will be s - 1, but rather its unknown. As such the size hint should be set to 0 since an unknown number of points will be emitted.

change_detect.go Outdated
}

fields := n.Fields().Copy()
fields[g.n.d.Field] = value
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking over the code I believe this can be simplified. The value here is guaranteed to be the existing value for the field correct? Meaning that all the logic to mutate the point can be removed, since changeDetect is just a special case of a filter node.

That means that doChangeDetect need only accept a edge.FieldTagsTimeGetter and does not need the setter.

If this is not the case, what code path actually changes the value of the field?

change_detect.go Outdated
// changeDetect calculates the changeDetect between prev and cur.
// Return is the resulting changeDetect, whether the current point should be
// stored as previous, and whether the point result should be emitted.
func (n *ChangeDetectNode) changeDetect(prev, curr models.Fields, prevTime, currTime time.Time) (interface{}, bool, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like {prev,curr}Time are unused, we should remove them from the function args.

stream
|from().measurement('packets')
|changeDetect('value')
|window()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, could you fix the whitespace difference here?

// The changeDetect is computed on a single field,
// discarding consecutive duplicate values, detecting
// detects the points at which the series field
// changes from one value to another.
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 it would be good to mention the output of the changeDetect node, i.e. that it just passes the data through unmodified and therefore acts like a special kind of filter.

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, the Kapacitor docs here are autogenerated from these comments on the types in the pipeline package.

|changeDetect('work')
.as('very important')
.unit(1h)
.nonNegative()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test needs to be updated.

Copy link
Contributor

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

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

🎉

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.

2 participants