diff --git a/docs/reference/readme.md b/docs/reference/readme.md index c79a667f5..4872b68be 100644 --- a/docs/reference/readme.md +++ b/docs/reference/readme.md @@ -480,33 +480,34 @@ Expose a prometheus endpoint on the specified port. #### Pomerium Metrics Tracked -Name | Type | Description ---------------------------------------------- | --------- | ----------------------------------------------------------------------- -grpc_client_request_duration_ms | Histogram | GRPC client request duration by service -grpc_client_request_size_bytes | Histogram | GRPC client request size by service -grpc_client_requests_total | Counter | Total GRPC client requests made by service -grpc_client_response_size_bytes | Histogram | GRPC client response size by service -grpc_server_request_duration_ms | Histogram | GRPC server request duration by service -grpc_server_request_size_bytes | Histogram | GRPC server request size by service -grpc_server_requests_total | Counter | Total GRPC server requests made by service -grpc_server_response_size_bytes | Histogram | GRPC server response size by service -http_client_request_duration_ms | Histogram | HTTP client request duration by service -http_client_request_size_bytes | Histogram | HTTP client request size by service -http_client_requests_total | Counter | Total HTTP client requests made by service -http_client_response_size_bytes | Histogram | HTTP client response size by service -http_server_request_duration_ms | Histogram | HTTP server request duration by service -http_server_request_size_bytes | Histogram | HTTP server request size by service -http_server_requests_total | Counter | Total HTTP server requests handled by service -http_server_response_size_bytes | Histogram | HTTP server response size by service -pomerium_build_info | Gauge | Pomerium build metadata by git revision, service, version and goversion -pomerium_config_checksum_int64 | Gauge | Currently loaded configuration checksum by service -pomerium_config_last_reload_success | Gauge | Whether the last configuration reload succeeded by service -pomerium_config_last_reload_success_timestamp | Gauge | The timestamp of the last successful configuration reload by service -redis_conns | Gauge | Number of total connections in the pool -redis_idle_conns | Gauge | Total number of times free connection was found in the pool -redis_wait_count_total | Counter | Total number of connections waited for -redis_wait_duration_ms_total | Counter | Total time spent waiting for connections -storage_operation_duration_ms | Histogram | Storage operation duration by operation, result, backend and service +| Name | Type | Description | +| --------------------------------------------- | --------- | ----------------------------------------------------------------------- | +| grpc_client_request_duration_ms | Histogram | GRPC client request duration by service | +| grpc_client_request_size_bytes | Histogram | GRPC client request size by service | +| grpc_client_requests_total | Counter | Total GRPC client requests made by service | +| grpc_client_response_size_bytes | Histogram | GRPC client response size by service | +| grpc_server_request_duration_ms | Histogram | GRPC server request duration by service | +| grpc_server_request_size_bytes | Histogram | GRPC server request size by service | +| grpc_server_requests_total | Counter | Total GRPC server requests made by service | +| grpc_server_response_size_bytes | Histogram | GRPC server response size by service | +| http_client_request_duration_ms | Histogram | HTTP client request duration by service | +| http_client_request_size_bytes | Histogram | HTTP client request size by service | +| http_client_requests_total | Counter | Total HTTP client requests made by service | +| http_client_response_size_bytes | Histogram | HTTP client response size by service | +| http_server_request_duration_ms | Histogram | HTTP server request duration by service | +| http_server_request_size_bytes | Histogram | HTTP server request size by service | +| http_server_requests_total | Counter | Total HTTP server requests handled by service | +| http_server_response_size_bytes | Histogram | HTTP server response size by service | +| pomerium_build_info | Gauge | Pomerium build metadata by git revision, service, version and goversion | +| pomerium_config_checksum_int64 | Gauge | Currently loaded configuration checksum by service | +| pomerium_config_last_reload_success | Gauge | Whether the last configuration reload succeeded by service | +| pomerium_config_last_reload_success_timestamp | Gauge | The timestamp of the last successful configuration reload by service | +| redis_conns | Gauge | Number of total connections in the pool | +| redis_idle_conns | Gauge | Number of idle connections in the pool | +| redis_stale_conns | Gauge | Number of stale connections in the pool | +| redis_miss_count_total | Counter | Total number of times a connection was NOT found in the pool | +| redis_hit_count_total | Counter | Total number of times a connection was found in the pool | +| storage_operation_duration_ms | Histogram | Storage operation duration by operation, result, backend and service | #### Envoy Proxy Metrics diff --git a/go.mod b/go.mod index 0bce6a93f..c9f738150 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,6 @@ require ( github.com/go-redis/redis/v8 v8.4.2 github.com/golang/mock v1.4.4 github.com/golang/protobuf v1.4.3 - github.com/gomodule/redigo v1.8.2 github.com/google/btree v1.0.0 github.com/google/go-cmp v0.5.4 github.com/google/go-jsonnet v0.17.0 diff --git a/go.sum b/go.sum index 04c1ac242..6c7c4c015 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k= -github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= diff --git a/internal/telemetry/metrics/kv.go b/internal/telemetry/metrics/kv.go index 8f56f3e1d..1cfed806b 100644 --- a/internal/telemetry/metrics/kv.go +++ b/internal/telemetry/metrics/kv.go @@ -1,18 +1,19 @@ package metrics import ( - "github.com/gomodule/redigo/redis" + redis "github.com/go-redis/redis/v8" ) // AddRedisMetrics registers a metrics handler against a redis Client's PoolStats() method -func AddRedisMetrics(stats func() redis.PoolStats) { +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().ActiveCount) }}, - {"redis_idle_conns", "Number of idle connections in the pool", func() int64 { return int64(stats().IdleCount) }}, + {"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) }}, + {"redis_stale_conns", "Number of stale connections in the pool", func() int64 { return int64(stats().StaleConns) }}, } for _, m := range gaugeMetrics { @@ -24,8 +25,8 @@ func AddRedisMetrics(stats func() redis.PoolStats) { desc string f func() int64 }{ - {"redis_wait_count_total", "Total number of connections waited for", func() int64 { return stats().WaitCount }}, - {"redis_wait_duration_ms_total", "Total time spent waiting for connections", func() int64 { return stats().WaitDuration.Milliseconds() }}, + {"redis_miss_count_total", "Total number of times a connection was not found in the pool", func() int64 { return int64(stats().Misses) }}, + {"redis_hit_count_total", "Total number of times a connection was found in the pool", func() int64 { return int64(stats().Hits) }}, } for _, m := range cumulativeMetrics { diff --git a/internal/telemetry/metrics/kv_test.go b/internal/telemetry/metrics/kv_test.go index 2aea734f6..d0a7f81ce 100644 --- a/internal/telemetry/metrics/kv_test.go +++ b/internal/telemetry/metrics/kv_test.go @@ -3,7 +3,7 @@ package metrics import ( "testing" - "github.com/gomodule/redigo/redis" + redis "github.com/go-redis/redis/v8" "go.opencensus.io/metric/metricdata" ) @@ -15,9 +15,9 @@ func Test_AddRedisMetrics(t *testing.T) { stat redis.PoolStats want int64 }{ - {"redis_conns", redis.PoolStats{ActiveCount: 7}, 7}, - {"redis_idle_conns", redis.PoolStats{IdleCount: 3}, 3}, - {"redis_wait_count_total", redis.PoolStats{WaitCount: 2}, 2}, + {"redis_conns", redis.PoolStats{TotalConns: 7}, 7}, + {"redis_idle_conns", redis.PoolStats{IdleConns: 3}, 3}, + {"redis_miss_count_total", redis.PoolStats{Misses: 2}, 2}, } labelValues := []metricdata.LabelValue{ @@ -26,7 +26,7 @@ func Test_AddRedisMetrics(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AddRedisMetrics(func() redis.PoolStats { return tt.stat }) + AddRedisMetrics(func() *redis.PoolStats { return &tt.stat }) testMetricRetrieval(registry.registry.Read(), t, labelValues, tt.want, tt.name) }) } diff --git a/pkg/storage/redis/redis.go b/pkg/storage/redis/redis.go index 84d123661..6e38f5c27 100644 --- a/pkg/storage/redis/redis.go +++ b/pkg/storage/redis/redis.go @@ -60,6 +60,7 @@ func New(rawURL string, options ...Option) (*DB, error) { opts.TLSConfig = db.cfg.tls } db.client = redis.NewClient(opts) + metrics.AddRedisMetrics(db.client.PoolStats) return db, nil }