bc3d12ec2c
- Fix promMetrics.Gauge/Counter/Observer mutating caller's labels map by using maps.Copy instead of direct assignment - Fix Gauge/Counter/Observer returning nil for unknown metric names (now return noop implementations) - Fix metricService.Close() race with sync.Once for safe concurrent calls - Fix SetDSCP returning nil instead of errUnsupport on unsupported ops - Add nil guards to WrapConn, WrapPacketConn, WrapUDPConn, WrapListener - Add doc comments to all exported symbols - Add 45 unit tests (metrics, noop, prom, service, wrapper)
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package metrics
|
|
|
|
import "github.com/go-gost/core/metrics"
|
|
|
|
var (
|
|
nopGauge = &noopGauge{}
|
|
nopCounter = &noopCounter{}
|
|
nopObserver = &noopObserver{}
|
|
|
|
noop metrics.Metrics = &noopMetrics{}
|
|
)
|
|
|
|
type noopMetrics struct{}
|
|
|
|
// Noop returns a Metrics implementation whose counters, gauges, and observers
|
|
// are all no-ops.
|
|
func Noop() metrics.Metrics {
|
|
return noop
|
|
}
|
|
|
|
func (m *noopMetrics) Counter(name metrics.MetricName, labels metrics.Labels) metrics.Counter {
|
|
return nopCounter
|
|
}
|
|
|
|
func (m *noopMetrics) Gauge(name metrics.MetricName, labels metrics.Labels) metrics.Gauge {
|
|
return nopGauge
|
|
}
|
|
|
|
func (m *noopMetrics) Observer(name metrics.MetricName, labels metrics.Labels) metrics.Observer {
|
|
return nopObserver
|
|
}
|
|
|
|
type noopGauge struct{}
|
|
|
|
func (*noopGauge) Inc() {}
|
|
func (*noopGauge) Dec() {}
|
|
func (*noopGauge) Add(v float64) {}
|
|
func (*noopGauge) Set(v float64) {}
|
|
|
|
type noopCounter struct{}
|
|
|
|
func (*noopCounter) Inc() {}
|
|
func (*noopCounter) Add(v float64) {}
|
|
|
|
type noopObserver struct{}
|
|
|
|
func (*noopObserver) Observe(v float64) {}
|