event: add IntDistribution metric Change-Id: Ib10130c9165fdd0d3d9d03ab416d28f72c14e725 Reviewed-on: https://go-review.googlesource.com/c/exp/+/326675 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/event/metric.go b/event/metric.go index 0c989ef..594cc88 100644 --- a/event/metric.go +++ b/event/metric.go
@@ -139,3 +139,25 @@ func (d *Duration) Record(v time.Duration) MetricValue { return MetricValue{d, DurationOf(v)} } + +// An IntDistribution records a distribution of int64s. +type IntDistribution struct { + *MetricDescriptor +} + +// NewIntDistribution creates a new IntDistribution with the given name. +func NewIntDistribution(name, description string) *IntDistribution { + return &IntDistribution{newMetricDescriptor(name, description)} +} + +// Descriptor returns the receiver's MetricDescriptor. +func (d *IntDistribution) Descriptor() *MetricDescriptor { + return d.MetricDescriptor +} + +// Record converts its argument into a Value and returns a MetricValue with the +// receiver and the value. It is intended to be used as an argument to +// Builder.Metric. +func (d *IntDistribution) Record(v int64) MetricValue { + return MetricValue{d, Int64Of(v)} +}