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-01-27 00:54:19 +03:00
|
|
|
opts Options
|
|
|
|
labels Labels
|
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
|
|
|
}
|
|
|
|
|
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-01-22 18:21:40 +03:00
|
|
|
return &noopFloatCounter{}
|
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-01-22 18:21:40 +03:00
|
|
|
return &noopGauge{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Summary implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Summary(name string, opts ...Option) Summary {
|
2021-01-22 18:21:40 +03:00
|
|
|
return &noopSummary{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-01-22 18:21:40 +03:00
|
|
|
return &noopSummary{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Histogram implements the Meter interface
|
2021-01-27 00:54:19 +03:00
|
|
|
func (r *noopMeter) Histogram(name string, opts ...Option) Histogram {
|
2021-01-22 18:21:40 +03:00
|
|
|
return &noopHistogram{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopMeter) Write(w io.Writer, withProcessMetrics bool) error {
|
|
|
|
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) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopFloatCounter struct{}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Add(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Get() float64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Set(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopFloatCounter) Sub(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopGauge struct{}
|
|
|
|
|
|
|
|
func (r *noopGauge) Get() float64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopSummary struct{}
|
|
|
|
|
|
|
|
func (r *noopSummary) Update(float64) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopSummary) UpdateDuration(time.Time) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopHistogram struct{}
|
|
|
|
|
|
|
|
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)) {}
|