metrics: add support for PCP#363
Conversation
peterbourgon
left a comment
There was a problem hiding this comment.
Thanks very much! In general the comments need a lot of cleanup, and you should remove the panics. Also, the histogram needs a way to Observe in units of seconds (see comment on that method). But this is a good start! I think it won't be a lot of work to resolve.
| import ( | ||
| "github.com/go-kit/kit/metrics" | ||
| "github.com/performancecopilot/speed" | ||
| ) |
There was a problem hiding this comment.
Please group imports according to the canonical style, that is,
import (
// stdlib
// third-party, not Go kit
// Go kit
)| "github.com/performancecopilot/speed" | ||
| ) | ||
|
|
||
| // Reporter encapsulates a speed client |
There was a problem hiding this comment.
Thanks for the method comments! Please use complete sentences, including proper punctuation and grammar, i.e.
// Reporter encapsulates a speed client.| func NewReporter(appname string) *Reporter { | ||
| c, err := speed.NewPCPClient(appname) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
Is that necessary? Can it return (*Reporter, error) instead?
| c *speed.PCPClient | ||
| } | ||
|
|
||
| // NewReporter creates a new reporter instance |
There was a problem hiding this comment.
- Please use proper punctuation, as above.
- Please describe a bit the meaning of the appname parameter, and the behavior if there is some error or misconfiguration.
| return &Reporter{c} | ||
| } | ||
|
|
||
| // Start starts reporting currently registered metrics to the backend |
There was a problem hiding this comment.
- Please use proper punctuation (further comments of this type elided).
- What does "backend" mean?
There was a problem hiding this comment.
using 'PCP installation' instead of backend
| // but that will mean this will need a mutex, to be safe | ||
| func (c *Counter) Add(delta float64) { c.c.Inc(int64(delta)) } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////////////// |
| func (r *Reporter) NewGauge(name string, desc ...string) *Gauge { | ||
| g, err := speed.NewPCPGauge(0, name, desc...) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
Same comment re: panic vs. returning an error.
|
|
||
| // NewHistogram creates a new Histogram | ||
| // minimum observeable value is 0 | ||
| // maximum observeable value is 3600000000 |
There was a problem hiding this comment.
Shouldn't these values be parameters?
| func (r *Reporter) NewHistogram(name string, desc ...string) *Histogram { | ||
| h, err := speed.NewPCPHistogram(name, 0, 3600000000, 5, desc...) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
Similar comment re: panic vs. returning an error.
| // | ||
| // this converts float64 value to int64, as the Histogram in speed | ||
| // is backed using codahale/hdrhistogram, which only observes int64 values | ||
| func (h *Histogram) Observe(value float64) { h.h.MustRecord(int64(value)) } |
There was a problem hiding this comment.
Simply converting to an int64 is going to be problematic, because it is idiomatic to Observe in a histogram in units of seconds, which typically are well less than 1. How should this be supported, do you think?
There was a problem hiding this comment.
The histogram implementation isn't native and simply wraps a PCP metric around codahale/hdrhistogram, which only records int64 (https://godoc.org/github.com/codahale/hdrhistogram#Histogram.RecordValue), which in turn is based on a java version, which itself records only long (http://hdrhistogram.github.io/HdrHistogram/JavaDoc/org/HdrHistogram/AbstractHistogram.html#recordValue(long)).
Raw PCP metrics allow setting a unit (https://github.com/performancecopilot/speed#singletonmetric), and I have shorted it to OneUnit at most places as it represents Count unit and most of the times we just want to count stuff. But I can provide a units parameter in histogram, similar to Timer (https://github.com/performancecopilot/speed#timer) so users can customize the unit to Milliseconds, Microseconds, Nanoseconds and report int64.
The other option is to replace the underlying histogram with another implementation. I like hdrhistogram for its ideas on precision and reduced memory footprint, but am open to ideas.
There was a problem hiding this comment.
I'm fine with keeping HDRHistogram. I like the Unit idea, it should be settable at metric construction time. Testing with -race will always be much slower than otherwise; I wouldn't worry about profiling it.
|
@peterbourgon sorry for the late update on this
|
| // NewReporter creates a new Reporter instance. | ||
| // The first parameter is the application name and is used to create the speed client. | ||
| // Hence it should be a valid speed parameter name and should not contain spaces or the path separator | ||
| // for your operating system. |
There was a problem hiding this comment.
Please wrap this and all comment blocks at 80 columns.
|
|
||
| // Add implements Counter. | ||
| // speed Counters only take int64. | ||
| // speed Gauges can take float64 and Add(float64) is implemented by metrics.Gauge. |
There was a problem hiding this comment.
Please fix the capitalization in this and all comment blocks, and clarify the behavior.
// Add implements Counter. Speed counters only take int64, so
// the delta is converted to an int64 before observation.
|
|
||
| // NewHistogram creates a new Histogram. | ||
| // minimum observeable value is 0. | ||
| // maximum observeable value is 3600000000. |
There was a problem hiding this comment.
Please fix capitalization here, and wrap the comment block at 80 columns.
| // Observe observes a value. | ||
| // | ||
| // this converts float64 value to int64, as the Histogram in speed | ||
| // is backed using codahale/hdrhistogram, which only observes int64 values. |
There was a problem hiding this comment.
Please mention something about the value being interpreted as the unit passed to the constructor.
|
Please don't waste time finding out why tests take longer to run with the race detector enabled. The race detector adds a lot of overhead by design. |
|
With those final cleanups I've requested, I'm happy to merge. Thanks for taking the time! |
|
@peterbourgon as requested I have updated the comment blocks to be a maximum of 80 columns in length. Moreover, I have generated the godoc for the package on my fork, which can be seen at (https://godoc.org/github.com/suyash/kit/metrics/pcp). I am using the package name in small characters everywhere ( W.e.f the histogram test time issue, the final call is yours, even if I change something in speed, my goal will be to keep things 100% backwards compatible. Right now whenever I can find the time, I am trying to understand the underlying working of hdrhistogram. In case there arises a need for a change in anything in this package, I can always open another PR. Thanks for being patient with me, with the code reviews. The generated godoc LGTM, please let me know if you need anything else. I am using atom to check the line width, and except for line 106, everything looks to be inside. |
|
Thanks for all of the hard work. I'll make a few other minor cleanups post-merge but this is great. 💯 |
|
Thanks ✨, you forgot to close the issue, will close it manually. |
metrics: add support for PCP

Based on the discussion in #354
This is basically the work in my repo except for the readme changes
I have not squashed the commits as GitHub allows squashing all commits into one at merge step, however if it is important, I can squash all changes and submit just one commit