feat(observability/metrics): add Emitter, options, buckets, and label vocabulary#181
feat(observability/metrics): add Emitter, options, buckets, and label vocabulary#181xytan0056 wants to merge 5 commits into
Conversation
b879ee5 to
4a55fde
Compare
| ResultFail Result = "fail" | ||
| ResultHit Result = "hit" | ||
| ResultMiss Result = "miss" | ||
| ) |
There was a problem hiding this comment.
rest of consts will be added as used. Keeping the change incremental for easier review
cd500a7 to
7e2b539
Compare
|
|
||
| // Emitter is the interface for emitting metrics. | ||
| type Emitter interface { | ||
| Inc(op, name string, opts ...Option) |
There was a problem hiding this comment.
these methods should all be documented
| "github.com/uber-go/tally" | ||
| ) | ||
|
|
||
| func counterValue(t *testing.T, s tally.TestScope, name string, tags map[string]string) int64 { |
There was a problem hiding this comment.
style: helpers should be placed below the tests.
| // limitations under the License. | ||
|
|
||
| // Package metrics is a thin wrapper over tally.Scope that pins the naming, | ||
| // bucket, and tag conventions defined in the Tango Metrics Inventory. |
There was a problem hiding this comment.
what is this "Tango Metrics Inventory"? It's better to document these in the package doc directly rather than just referencing something.
| ) | ||
|
|
||
| // Emitter is the interface for emitting metrics. | ||
| type Emitter interface { |
There was a problem hiding this comment.
now that we've written it out, I'm not sure if we want Emitter to be an interface or a struct since we only have a single implementation of it.
The only reason this might be useful is if people want to plug in metrics emitter that are not backed by Tally, but that seems unlikely -- Thoughts?
There was a problem hiding this comment.
- with interface, downstream can just
New(nil)without Tally.NewTestScope (which is not bad either). This also forces construction here, with exporting struct,people can dometrics.Emitter{}, which can panic with nil scope - uber internal (duplica server) can implement this interface for consistency, not necessarily required tho
There was a problem hiding this comment.
I think the whole purpose of Emitter interface is to have it potentially pluggable and not depend on Tally.
The alternative approach (this is done in sqv2) is to use Tally as is with a potentially customized backend, because Tally itself is an abstraction.
8ee7643 to
7e2b539
Compare
7e2b539 to
300d46c
Compare
| ) | ||
|
|
||
| // Emitter is the interface for emitting metrics. | ||
| type Emitter interface { |
There was a problem hiding this comment.
I think the whole purpose of Emitter interface is to have it potentially pluggable and not depend on Tally.
The alternative approach (this is done in sqv2) is to use Tally as is with a potentially customized backend, because Tally itself is an abstraction.
| // the default duration buckets unless overridden with WithDurationBuckets. | ||
| RecordDur(op, name string, d time.Duration, opts ...Option) | ||
| // RecordCount records v in the named histogram under the op subscope, using | ||
| // the default value buckets unless overridden with WithValueBuckets. |
There was a problem hiding this comment.
where practically will it be used?
I think the only reason to record into histogram is a duration, otherwise it is simply a counter with tags.
There was a problem hiding this comment.
this is for recording targets count from changedtargets call. This way we have an idea of repo scale and sanity of response
counter (by Inc) is for recording traffic trends
|
|
||
| // Result values for TagResult. | ||
| const ( | ||
| ResultSuccess Result = "success" |
There was a problem hiding this comment.
all exported times are to be commented
There was a problem hiding this comment.
these are self-explanatory constants, I'm going to add more later for operations, adding a comment to each of them seems a bit redundant
Single implementation and a thin tally wrapper — drop the interface and export the struct directly. New/Tagged return *Emitter. Callers fake metrics with tally.NewTestScope, not an interface mock.
60dae4c to
53a8e41
Compare
4371e62 to
f6e4228
Compare
Adds the
observability/metricspackage: theEmitterinterface with a tally-backed implementation, per-call options (WithTags, duration/value bucket overrides), the default histogram buckets, and the shared tag keys +Resultvalues.Stacked on #158.