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"
|
2023-07-29 00:40:58 +03:00
|
|
|
|
|
|
|
"go.unistack.org/micro/v4/options"
|
2020-11-15 00:38:38 +03:00
|
|
|
)
|
|
|
|
|
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:
|
2023-07-29 00:40:58 +03:00
|
|
|
func NewMeter(opts ...options.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
|
2023-07-29 00:40:58 +03:00
|
|
|
func (r *noopMeter) Clone(opts ...options.Option) Meter {
|
2021-10-09 23:50:57 +03:00
|
|
|
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
|
2023-07-29 00:40:58 +03:00
|
|
|
func (r *noopMeter) Init(opts ...options.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-04-26 23:13:36 +03:00
|
|
|
func (r *noopMeter) Counter(name string, labels ...string) Counter {
|
|
|
|
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
|
2021-04-26 23:13:36 +03:00
|
|
|
func (r *noopMeter) FloatCounter(name string, labels ...string) FloatCounter {
|
|
|
|
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
|
2021-04-26 23:13:36 +03:00
|
|
|
func (r *noopMeter) Gauge(name string, f func() float64, labels ...string) Gauge {
|
|
|
|
return &noopGauge{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Summary implements the Meter interface
|
2021-04-26 23:13:36 +03:00
|
|
|
func (r *noopMeter) Summary(name string, labels ...string) Summary {
|
|
|
|
return &noopSummary{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SummaryExt implements the Meter interface
|
2021-04-26 23:13:36 +03:00
|
|
|
func (r *noopMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) Summary {
|
|
|
|
return &noopSummary{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Histogram implements the Meter interface
|
2021-04-26 23:13:36 +03:00
|
|
|
func (r *noopMeter) Histogram(name string, labels ...string) Histogram {
|
|
|
|
return &noopHistogram{labels: labels}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set implements the Meter interface
|
2023-07-29 00:40:58 +03:00
|
|
|
func (r *noopMeter) Set(opts ...options.Option) Meter {
|
2021-01-27 00:54:19 +03:00
|
|
|
m := &noopMeter{opts: r.opts}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&m.opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-07-29 00:40:58 +03:00
|
|
|
func (r *noopMeter) Write(_ io.Writer, _ ...options.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)) {}
|