mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 00:40:25 +02:00
cache: remove unused metrics and options (#957)
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
parent
f7760c413e
commit
452c9be06d
8 changed files with 7 additions and 266 deletions
|
@ -1,107 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/golang/groupcache"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
// AddGroupCacheMetrics registers a metrics handler against a *groupcache.Group
|
||||
func AddGroupCacheMetrics(gc *groupcache.Group) {
|
||||
|
||||
cumulativeMetrics := []struct {
|
||||
name string
|
||||
desc string
|
||||
f func() int64
|
||||
}{
|
||||
{"groupcache_gets_total", "Total get request, including from peers", gc.Stats.Gets.Get},
|
||||
{"groupcache_cache_hits_total", "Total cache hits in local or cluster cache", gc.Stats.CacheHits.Get},
|
||||
{"groupcache_cache_hits_total", "Total cache hits in local or cluster cache", gc.Stats.CacheHits.Get},
|
||||
{"groupcache_peer_loads_total", "Total remote loads or cache hits without error", gc.Stats.PeerLoads.Get},
|
||||
{"groupcache_peer_errors_total", "Total errors from peers", gc.Stats.PeerErrors.Get},
|
||||
{"groupcache_loads_total", "Total gets without cache hits", gc.Stats.Loads.Get},
|
||||
{"groupcache_loads_deduped_total", "gets without cache hits after duplicate suppression", gc.Stats.LoadsDeduped.Get},
|
||||
{"groupcache_local_loads_total", "Total good local loads", gc.Stats.LocalLoads.Get},
|
||||
{"groupcache_local_load_errs_total", "Total local load errors", gc.Stats.LocalLoadErrs.Get},
|
||||
{"groupcache_server_requests_total", "Total gets from peers", gc.Stats.ServerRequests.Get},
|
||||
}
|
||||
|
||||
for _, m := range cumulativeMetrics {
|
||||
registry.addInt64DerivedCumulativeMetric(m.name, m.desc, "autocache", m.f)
|
||||
}
|
||||
}
|
||||
|
||||
// AddBoltDBMetrics registers a metrics handler against a *bbolt.DB
|
||||
func AddBoltDBMetrics(stats func() bbolt.Stats) {
|
||||
gaugeMetrics := []struct {
|
||||
name string
|
||||
desc string
|
||||
f func() int64
|
||||
}{
|
||||
{"boltdb_free_page_n", "Number of free pages on the freelist", func() int64 { return int64(stats().FreePageN) }},
|
||||
{"boltdb_pending_page_n", "Number of pending pages on the freelist", func() int64 { return int64(stats().PendingPageN) }},
|
||||
{"boltdb_free_alloc_size_bytes", "Bytes allocated in free pages", func() int64 { return int64(stats().FreeAlloc) }},
|
||||
{"boltdb_freelist_inuse_size_bytes", "Bytes used by the freelist", func() int64 { return int64(stats().FreelistInuse) }},
|
||||
{"boltdb_txn", "total number of started read transactions", func() int64 { return int64(stats().TxN) }},
|
||||
{"boltdb_open_txn", "number of currently open read transactions", func() int64 { return int64(stats().OpenTxN) }},
|
||||
}
|
||||
|
||||
for _, m := range gaugeMetrics {
|
||||
registry.addInt64DerivedGaugeMetric(m.name, m.desc, "boltdb", m.f)
|
||||
}
|
||||
|
||||
cumulativeMetrics := []struct {
|
||||
name string
|
||||
desc string
|
||||
f func() int64
|
||||
}{
|
||||
{"boltdb_txn_page_total", "Total number of page allocations", func() int64 { return int64(stats().TxStats.PageCount) }},
|
||||
{"boltdb_txn_page_alloc_size_bytes_total", "Total bytes allocated", func() int64 { return int64(stats().TxStats.PageAlloc) }},
|
||||
{"boltdb_txn_cursor_total", "Total number of cursors created", func() int64 { return int64(stats().TxStats.CursorCount) }},
|
||||
{"boltdb_txn_node_total", "Total number of node allocations", func() int64 { return int64(stats().TxStats.NodeCount) }},
|
||||
{"boltdb_txn_node_deref_total", "Total number of node dereferences", func() int64 { return int64(stats().TxStats.NodeDeref) }},
|
||||
{"boltdb_txn_rebalance_total", "Total number of node rebalances", func() int64 { return int64(stats().TxStats.Rebalance) }},
|
||||
{"boltdb_txn_rebalance_duration_ms_total", "Total time spent rebalancing", func() int64 { return stats().TxStats.RebalanceTime.Milliseconds() }},
|
||||
{"boltdb_txn_split_total", "Total number of nodes split", func() int64 { return int64(stats().TxStats.Split) }},
|
||||
{"boltdb_txn_spill_total", "Total number of nodes spilled", func() int64 { return int64(stats().TxStats.Spill) }},
|
||||
{"boltdb_txn_spill_duration_ms_total", "Total time spent spilling", func() int64 { return stats().TxStats.SpillTime.Milliseconds() }},
|
||||
{"boltdb_txn_write_total", "Total number of writes performed", func() int64 { return int64(stats().TxStats.Write) }},
|
||||
{"boltdb_txn_write_duration_ms_total", "Total time spent writing to disk", func() int64 { return stats().TxStats.WriteTime.Milliseconds() }},
|
||||
}
|
||||
|
||||
for _, m := range cumulativeMetrics {
|
||||
registry.addInt64DerivedCumulativeMetric(m.name, m.desc, "boltdb", m.f)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// AddRedisMetrics registers a metrics handler against a redis Client's PoolStats() method
|
||||
func AddRedisMetrics(stats func() *redis.PoolStats) {
|
||||
gaugeMetrics := []struct {
|
||||
name string
|
||||
desc string
|
||||
f func() int64
|
||||
}{
|
||||
{"redis_conns", "Number of total connections in the pool", func() int64 { return int64(stats().TotalConns) }},
|
||||
{"redis_idle_conns", "Number of idle connections in the pool", func() int64 { return int64(stats().IdleConns) }},
|
||||
}
|
||||
|
||||
for _, m := range gaugeMetrics {
|
||||
registry.addInt64DerivedGaugeMetric(m.name, m.desc, "redis", m.f)
|
||||
}
|
||||
|
||||
cumulativeMetrics := []struct {
|
||||
name string
|
||||
desc string
|
||||
f func() int64
|
||||
}{
|
||||
{"redis_hits_total", "Total number of times free connection was found in the pool", func() int64 { return int64(stats().Hits) }},
|
||||
{"redis_misses_total", "Total number of times free connection was NOT found in the pool", func() int64 { return int64(stats().Misses) }},
|
||||
{"redis_timeouts_total", "Total number of times a wait timeout occurred", func() int64 { return int64(stats().Timeouts) }},
|
||||
{"redis_stale_conns_total", "Total number of stale connections removed from the pool", func() int64 { return int64(stats().StaleConns) }},
|
||||
}
|
||||
|
||||
for _, m := range cumulativeMetrics {
|
||||
registry.addInt64DerivedCumulativeMetric(m.name, m.desc, "redis", m.f)
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/golang/groupcache"
|
||||
"go.etcd.io/bbolt"
|
||||
"go.opencensus.io/metric/metricdata"
|
||||
)
|
||||
|
||||
func Test_AddGroupCacheMetrics(t *testing.T) {
|
||||
gc := &groupcache.Group{}
|
||||
AddGroupCacheMetrics(gc)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
stat *groupcache.AtomicInt
|
||||
want int64
|
||||
}{
|
||||
{"groupcache_gets_total", &gc.Stats.Gets, 4},
|
||||
{"groupcache_loads_total", &gc.Stats.Loads, 42},
|
||||
{"groupcache_server_requests_total", &gc.Stats.ServerRequests, 8},
|
||||
}
|
||||
|
||||
labelValues := []metricdata.LabelValue{
|
||||
metricdata.NewLabelValue("autocache"),
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.stat.Add(tt.want)
|
||||
testMetricRetrieval(registry.registry.Read(), t, labelValues, tt.want, tt.name)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Test_AddBoltDBMetrics(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
stat bbolt.Stats
|
||||
want int64
|
||||
}{
|
||||
{"boltdb_free_page_n", bbolt.Stats{FreePageN: 14}, 14},
|
||||
{"boltdb_txn", bbolt.Stats{TxN: 88}, 88},
|
||||
|
||||
{"boltdb_txn_rebalance_duration_ms_total", bbolt.Stats{TxStats: bbolt.TxStats{RebalanceTime: 42 * time.Millisecond}}, 42},
|
||||
{"boltdb_txn_write_total", bbolt.Stats{TxStats: bbolt.TxStats{Write: 42}}, 42},
|
||||
}
|
||||
|
||||
labelValues := []metricdata.LabelValue{
|
||||
metricdata.NewLabelValue("boltdb"),
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
AddBoltDBMetrics(func() bbolt.Stats { return tt.stat })
|
||||
testMetricRetrieval(registry.registry.Read(), t, labelValues, tt.want, tt.name)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Test_AddRedisMetrics(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
stat *redis.PoolStats
|
||||
want int64
|
||||
}{
|
||||
{"redis_conns", &redis.PoolStats{TotalConns: 7}, 7},
|
||||
{"redis_hits_total", &redis.PoolStats{Hits: 78}, 78},
|
||||
{"redis_timeouts_total", &redis.PoolStats{Timeouts: 2}, 2},
|
||||
}
|
||||
|
||||
labelValues := []metricdata.LabelValue{
|
||||
metricdata.NewLabelValue("redis"),
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
AddRedisMetrics(func() *redis.PoolStats { return tt.stat })
|
||||
testMetricRetrieval(registry.registry.Read(), t, labelValues, tt.want, tt.name)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
|
@ -106,39 +106,3 @@ func (r *metricRegistry) setConfigChecksum(service string, checksum uint64) {
|
|||
}
|
||||
m.Set(float64(checksum))
|
||||
}
|
||||
|
||||
func (r *metricRegistry) addInt64DerivedGaugeMetric(name string, desc string, service string, f func() int64) {
|
||||
|
||||
m, err := r.registry.AddInt64DerivedGauge(name, metric.WithDescription(desc), metric.WithLabelKeys("service"))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("service", service).Msg("telemetry/metrics: failed to register metric")
|
||||
return
|
||||
}
|
||||
|
||||
err = m.UpsertEntry(
|
||||
f,
|
||||
metricdata.NewLabelValue(service),
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("service", service).Msg("telemetry/metrics: failed to update metric")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *metricRegistry) addInt64DerivedCumulativeMetric(name string, desc string, service string, f func() int64) {
|
||||
|
||||
m, err := r.registry.AddInt64DerivedCumulative(name, metric.WithDescription(desc), metric.WithLabelKeys("service"))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("service", service).Msg("telemetry/metrics: failed to register metric")
|
||||
return
|
||||
}
|
||||
|
||||
err = m.UpsertEntry(
|
||||
f,
|
||||
metricdata.NewLabelValue(service),
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("service", service).Msg("telemetry/metrics: failed to update metric")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue