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

Cleaner/easier way for user to specify Cloudwatch metric percentiles #599

Merged
merged 4 commits into from
Aug 16, 2017

Conversation

feliksik
Copy link
Contributor

@feliksik feliksik commented Aug 8, 2017

Two changes:

sorry for not including these previously, I should have added [WIP] tag, as I intended to still agree on requirements, before merge.

@peterbourgon
Copy link
Member

Is there a good reason to make the breaking p change besides consistency with other metrics?

@feliksik
Copy link
Contributor Author

feliksik commented Aug 8, 2017

@peterbourgon : the reasons are 1) consistency and 2) clarity (that it is a percentile).

Whether that's good enough is arguable. I can also pull it out and just include the WithPercentiles() change, if you like.

@feliksik
Copy link
Contributor Author

feliksik commented Aug 8, 2017

I believe there is no tag released since it was included, so I guessed it didn't matter much; that's why I asked @cam-stitt .

The extent to which you want to keep master backwards compatible is up to you.

@feliksik
Copy link
Contributor Author

feliksik commented Aug 8, 2017

I see that I messed up the test:

--- FAIL: TestHistogram (0.23s)
	cloudwatch_test.go:182: p50: want 500.000000, have 0.000000; p90: want 532.038789, have 0.000000; p95: want 541.121341, have 0.000000; p99: want 558.158697, have 0.000000
FAIL

So I'll happily fix it, as soon as you can tell me which of the 2 changes you would accept :-) goodnight!

for _, entry := range p {
if entry.f < 0 || entry.f > 1 {
continue // illegal entry
c.percentiles = make([]float64, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Why zero here, as opposed to len(percentiles)?
    It looks like you're betting in favor of them all being illegal.

Copy link
Contributor Author

@feliksik feliksik Aug 9, 2017

Choose a reason for hiding this comment

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

You are correct, make([]float64, 0, len(percentiles) would be more efficient, and will not have to re-allocate the slice twice.

I don't care to optimize this stuff for slices that are so short; in this slice is likely to be max 4 entries.

Actually, if there is an illegal entry, the len(percentiles) approach will never release the unused memory of the over-allocation ;-)

But I can fix it if you like.

Copy link
Contributor

Choose a reason for hiding this comment

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

That you wrote a number at all made me take note.

I usually try to avoid the intermediate reallocations (and consequent copying) in loops like these by allocating beforehand the maximum that I might need. I'd rather hang on to that unused memory (assuming it's relatively small like this) than reallocate several times accumulating the values.

I don't know how often this code executes, so it may not make any difference. For your approach, though, I recommend just removing the length entirely, deleting line 65. You can pass a nil slice argument to append.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comment. You are right, I never needed to set it to 0. It's better to delete the line, or initialize with len(). But the current line makes no sense.

I'll update this later :-) still waiting for a verdict on the 'p' prefix anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, thinking about it, the percentiles was already initialized by the beginning of the New() function. So not re-initializing it will add percentiles, not override the defaults. That's not good...

For context: The method is only used once for every cloudwatch instance you make, which is generally 1 per application runtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could write the following:

c.percentiles = nil

Whether that's better—assuming your desire is to start here with no room—is a matter of taste.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems all fine with me; I will see if I can add some tests for the custom percentiles, and will change it to either nil or Len(), whichever you like.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to use the length of the candidate sequence supplied to the filter—here, len(percentiles)—but my contribution to go-kit thus far has been negligible, so I defer to any others more familiar with conventions or preferences applied more consistently throughout the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@feliksik
Copy link
Contributor Author

feliksik commented Aug 9, 2017

Great, will do! As long as nobody else comments, let's do as you suggest :-)

// but with custom percentiles we don't have those.
// So fake them. Maybe we should make teststat.nvq() public and use that?
p95 = 541.121341
p99 = 558.158697
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterbourgon this may not be the nicest to hardcode; we can also make teststat.nvq() public. Do you have a preference?

Copy link
Member

@peterbourgon peterbourgon Aug 11, 2017

Choose a reason for hiding this comment

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

Maybe it's fine to just leave this [part of the] test out, for this particular metric?

I'm tentatively fine with the hard-coded percentiles, only because this whole package is getting a ground-up refactor in the short/medium term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for you comment @peterbourgon ; Do you mean leave out the whole added part about testing WithPercentile() ?
I think that's the only way.

We can also leave it hardcoded for now; it's all fine with me. I actually do think it's useful to test the WithPercentile(), but I'm not really attached to it.

If you have a preference, let me know; otherwise I'll leave it as-is.

@feliksik
Copy link
Contributor Author

@peterbourgon you mentioned on slack "I rather leave it out, if you don't mind. Keep the old syntax."
Fine with me! The names are referted in the most recent commit.

@peterbourgon peterbourgon merged commit 94d041d into go-kit:master Aug 16, 2017
@peterbourgon
Copy link
Member

Thanks!

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