summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/logr/metrics.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-08-05 20:43:19 +0200
committerGitHub <noreply@github.com>2023-08-05 20:43:19 +0200
commit56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch)
treeb1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/mattermost/logr/metrics.go
parent9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff)
downloadmatterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz
matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2
matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip
Update dependencies and remove old matterclient lib (#2067)HEADmaster
Diffstat (limited to 'vendor/github.com/mattermost/logr/metrics.go')
-rw-r--r--vendor/github.com/mattermost/logr/metrics.go117
1 files changed, 0 insertions, 117 deletions
diff --git a/vendor/github.com/mattermost/logr/metrics.go b/vendor/github.com/mattermost/logr/metrics.go
deleted file mode 100644
index 24fe22b6..00000000
--- a/vendor/github.com/mattermost/logr/metrics.go
+++ /dev/null
@@ -1,117 +0,0 @@
-package logr
-
-import (
- "errors"
-
- "github.com/wiggin77/merror"
-)
-
-const (
- DefMetricsUpdateFreqMillis = 15000 // 15 seconds
-)
-
-// Counter is a simple metrics sink that can only increment a value.
-// Implementations are external to Logr and provided via `MetricsCollector`.
-type Counter interface {
- // Inc increments the counter by 1. Use Add to increment it by arbitrary non-negative values.
- Inc()
- // Add adds the given value to the counter. It panics if the value is < 0.
- Add(float64)
-}
-
-// Gauge is a simple metrics sink that can receive values and increase or decrease.
-// Implementations are external to Logr and provided via `MetricsCollector`.
-type Gauge interface {
- // Set sets the Gauge to an arbitrary value.
- Set(float64)
- // Add adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.)
- Add(float64)
- // Sub subtracts the given value from the Gauge. (The value can be negative, resulting in an increase of the Gauge.)
- Sub(float64)
-}
-
-// MetricsCollector provides a way for users of this Logr package to have metrics pushed
-// in an efficient way to any backend, e.g. Prometheus.
-// For each target added to Logr, the supplied MetricsCollector will provide a Gauge
-// and Counters that will be called frequently as logging occurs.
-type MetricsCollector interface {
- // QueueSizeGauge returns a Gauge that will be updated by the named target.
- QueueSizeGauge(target string) (Gauge, error)
- // LoggedCounter returns a Counter that will be incremented by the named target.
- LoggedCounter(target string) (Counter, error)
- // ErrorCounter returns a Counter that will be incremented by the named target.
- ErrorCounter(target string) (Counter, error)
- // DroppedCounter returns a Counter that will be incremented by the named target.
- DroppedCounter(target string) (Counter, error)
- // BlockedCounter returns a Counter that will be incremented by the named target.
- BlockedCounter(target string) (Counter, error)
-}
-
-// TargetWithMetrics is a target that provides metrics.
-type TargetWithMetrics interface {
- EnableMetrics(collector MetricsCollector, updateFreqMillis int64) error
-}
-
-func (logr *Logr) getMetricsCollector() MetricsCollector {
- logr.mux.RLock()
- defer logr.mux.RUnlock()
- return logr.metrics
-}
-
-// SetMetricsCollector enables metrics collection by supplying a MetricsCollector.
-// The MetricsCollector provides counters and gauges that are updated by log targets.
-func (logr *Logr) SetMetricsCollector(collector MetricsCollector) error {
- if collector == nil {
- return errors.New("collector cannot be nil")
- }
-
- logr.mux.Lock()
- logr.metrics = collector
- logr.queueSizeGauge, _ = collector.QueueSizeGauge("_logr")
- logr.loggedCounter, _ = collector.LoggedCounter("_logr")
- logr.errorCounter, _ = collector.ErrorCounter("_logr")
- logr.mux.Unlock()
-
- logr.metricsInitOnce.Do(func() {
- logr.metricsDone = make(chan struct{})
- go logr.startMetricsUpdater()
- })
-
- merr := merror.New()
-
- logr.tmux.RLock()
- defer logr.tmux.RUnlock()
- for _, target := range logr.targets {
- if tm, ok := target.(TargetWithMetrics); ok {
- if err := tm.EnableMetrics(collector, logr.MetricsUpdateFreqMillis); err != nil {
- merr.Append(err)
- }
- }
-
- }
- return merr.ErrorOrNil()
-}
-
-func (logr *Logr) setQueueSizeGauge(val float64) {
- logr.mux.RLock()
- defer logr.mux.RUnlock()
- if logr.queueSizeGauge != nil {
- logr.queueSizeGauge.Set(val)
- }
-}
-
-func (logr *Logr) incLoggedCounter() {
- logr.mux.RLock()
- defer logr.mux.RUnlock()
- if logr.loggedCounter != nil {
- logr.loggedCounter.Inc()
- }
-}
-
-func (logr *Logr) incErrorCounter() {
- logr.mux.RLock()
- defer logr.mux.RUnlock()
- if logr.errorCounter != nil {
- logr.errorCounter.Inc()
- }
-}