From 3f5b19497c97aefb75a3dddd7eda8360688abddc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 9 Oct 2021 23:50:57 +0300 Subject: [PATCH] meter: add Clone method Signed-off-by: Vasiliy Tolstov --- meter/meter.go | 14 ++++++++++++++ meter/noop.go | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/meter/meter.go b/meter/meter.go index 204022c2..286f08bc 100644 --- a/meter/meter.go +++ b/meter/meter.go @@ -28,17 +28,31 @@ var ( // Meter is an interface for collecting and instrumenting metrics type Meter interface { + // Name returns meter name Name() string + // Init initialize meter Init(opts ...Option) error + // Clone create meter copy with new options + Clone(opts ...Option) Meter + // Counter get or create counter Counter(name string, labels ...string) Counter + // FloatCounter get or create float counter FloatCounter(name string, labels ...string) FloatCounter + // Gauge get or create gauge Gauge(name string, fn func() float64, labels ...string) Gauge + // Set create new meter metrics set Set(opts ...Option) Meter + // Histogram get or create histogram Histogram(name string, labels ...string) Histogram + // Summary get or create summary Summary(name string, labels ...string) Summary + // SummaryExt get or create summary with spcified quantiles and window time SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) Summary + // Write writes metrics to io.Writer Write(w io.Writer, opts ...Option) error + // Options returns meter options Options() Options + // String return meter type String() string } diff --git a/meter/noop.go b/meter/noop.go index 875310c4..a1b47a94 100644 --- a/meter/noop.go +++ b/meter/noop.go @@ -15,6 +15,15 @@ func NewMeter(opts ...Option) Meter { return &noopMeter{opts: NewOptions(opts...)} } +// Clone return old meter with new options +func (r *noopMeter) Clone(opts ...Option) Meter { + options := r.opts + for _, o := range opts { + o(&options) + } + return &noopMeter{opts: options} +} + func (r *noopMeter) Name() string { return r.opts.Name }