2021-01-20 01:21:15 +03:00
|
|
|
package meter
|
2020-11-15 00:38:38 +03:00
|
|
|
|
|
|
|
import (
|
2021-01-27 00:54:19 +03:00
|
|
|
"io"
|
2020-11-15 00:38:38 +03:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// NoopMeter is an noop implementation of Meter
|
|
|
|
type noopMeter struct {
|
2021-02-13 01:46:16 +03:00
|
|
|
opts Options
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// NewMeter returns a configured noop reporter:
|
|
|
|
func NewMeter(opts ...Option) Meter {
|
2021-01-27 00:54:19 +03:00
|
|
|
return &noopMeter{opts: NewOptions(opts...)}
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-29 13:17:32 +03:00
|
|
|
func (r *noopMeter) Name() string {
|
|
|
|
return r.opts.Name
|
|
|
|
}
|
|
|
|
|
2020-11-15 00:53:40 +03:00
|
|
|
// Init initialize options
|
2021-01-22 18:21:40 +03:00
|
|
|
func (r *noopMeter) Init(opts ...Option) error {
|
2020-11-15 00:53:40 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&r.opts)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// Counter implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Counter(name string, opts ...Option) Counter {
|
|
|
|
options := Options{}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &noopCounter{labels: options.Labels}
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// FloatCounter implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) FloatCounter(name string, opts ...Option) FloatCounter {
|
2021-02-13 01:46:16 +03:00
|
|
|
options := Options{}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &noopFloatCounter{labels: options.Labels}
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// Gauge implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Gauge(name string, f func() float64, opts ...Option) Gauge {
|
2021-02-13 01:46:16 +03:00
|
|
|
options := Options{}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &noopGauge{labels: options.Labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Summary implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Summary(name string, opts ...Option) Summary {
|
2021-02-13 01:46:16 +03:00
|
|
|
options := Options{}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &noopSummary{labels: options.Labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SummaryExt implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) SummaryExt(name string, window time.Duration, quantiles []float64, opts ...Option) Summary {
|
2021-02-13 01:46:16 +03:00
|
|
|
options := Options{}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &noopSummary{labels: options.Labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Histogram implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Histogram(name string, opts ...Option) Histogram {
|
2021-02-13 01:46:16 +03:00
|
|
|
options := Options{}
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &noopHistogram{labels: options.Labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Set(opts ...Option) Meter {
|
|
|
|
m := &noopMeter{opts: r.opts}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&m.opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-02-14 16:16:01 +03:00
|
|
|
func (r *noopMeter) Write(w io.Writer, opts ...Option) error {
|
2021-01-27 00:54:19 +03:00
|
|
|
return nil
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// Options implements the Meter interface
|
|
|
|
func (r *noopMeter) Options() Options {
|
2020-11-15 00:38:38 +03:00
|
|
|
return r.opts
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
// String implements the Meter interface
|
|
|
|
func (r *noopMeter) String() string {
|
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
2021-01-27 00:54:19 +03:00
|
|
|
type noopCounter struct {
|
|
|
|
labels Labels
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
func (r *noopCounter) Add(int) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopCounter) Dec() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopCounter) Get() uint64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopCounter) Inc() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopCounter) Set(uint64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-13 01:46:16 +03:00
|
|
|
type noopFloatCounter struct {
|
|
|
|
labels Labels
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
func (r *noopFloatCounter) Add(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Get() float64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Set(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Sub(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-13 01:46:16 +03:00
|
|
|
type noopGauge struct {
|
|
|
|
labels Labels
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
func (r *noopGauge) Get() float64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-02-13 01:46:16 +03:00
|
|
|
type noopSummary struct {
|
|
|
|
labels Labels
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
func (r *noopSummary) Update(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopSummary) UpdateDuration(time.Time) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-13 01:46:16 +03:00
|
|
|
type noopHistogram struct {
|
|
|
|
labels Labels
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
func (r *noopHistogram) Reset() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopHistogram) Update(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopHistogram) UpdateDuration(time.Time) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//func (r *noopHistogram) VisitNonZeroBuckets(f func(vmrange string, count uint64)) {}
|