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-10-09 23:50:57 +03:00
|
|
|
// 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}
|
|
|
|
}
|
|
|
|
|
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
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) Counter(_ string, labels ...string) Counter {
|
2021-04-26 23:13:36 +03:00
|
|
|
return &noopCounter{labels: labels}
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// FloatCounter implements the Meter interface
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) FloatCounter(_ string, labels ...string) FloatCounter {
|
2021-04-26 23:13:36 +03:00
|
|
|
return &noopFloatCounter{labels: labels}
|
2020-11-15 00:38:38 +03:00
|
|
|
}
|
|
|
|
|
2021-01-22 18:21:40 +03:00
|
|
|
// Gauge implements the Meter interface
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) Gauge(_ string, _ func() float64, labels ...string) Gauge {
|
2021-04-26 23:13:36 +03:00
|
|
|
return &noopGauge{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Summary implements the Meter interface
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) Summary(_ string, labels ...string) Summary {
|
2021-04-26 23:13:36 +03:00
|
|
|
return &noopSummary{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SummaryExt implements the Meter interface
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) SummaryExt(_ string, _ time.Duration, _ []float64, labels ...string) Summary {
|
2021-04-26 23:13:36 +03:00
|
|
|
return &noopSummary{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Histogram implements the Meter interface
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) Histogram(_ string, labels ...string) Histogram {
|
2021-04-26 23:13:36 +03:00
|
|
|
return &noopHistogram{labels: 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
|
|
|
|
}
|
|
|
|
|
2024-12-09 16:23:25 +03:00
|
|
|
func (r *noopMeter) Write(_ io.Writer, _ ...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 {
|
2021-03-15 00:44:13 +03:00
|
|
|
labels []string
|
2021-01-27 00:54:19 +03:00
|
|
|
}
|
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 {
|
2021-03-15 00:44:13 +03:00
|
|
|
labels []string
|
2021-02-13 01:46:16 +03:00
|
|
|
}
|
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 {
|
2021-03-15 00:44:13 +03:00
|
|
|
labels []string
|
2021-02-13 01:46:16 +03:00
|
|
|
}
|
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 {
|
2021-03-15 00:44:13 +03:00
|
|
|
labels []string
|
2021-02-13 01:46:16 +03:00
|
|
|
}
|
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 {
|
2021-03-15 00:44:13 +03:00
|
|
|
labels []string
|
2021-02-13 01:46:16 +03:00
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
|
|
|
|
func (r *noopHistogram) Reset() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopHistogram) Update(float64) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *noopHistogram) UpdateDuration(time.Time) {
|
|
|
|
}
|
|
|
|
|
2021-04-27 08:32:47 +03:00
|
|
|
// func (r *noopHistogram) VisitNonZeroBuckets(f func(vmrange string, count uint64)) {}
|