mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
internal/telemetry/metrics: update redis metrics for go-redis (#1694)
This commit is contained in:
parent
d3c697d3e4
commit
64816720c8
6 changed files with 41 additions and 41 deletions
|
@ -480,33 +480,34 @@ Expose a prometheus endpoint on the specified port.
|
||||||
|
|
||||||
#### Pomerium Metrics Tracked
|
#### Pomerium Metrics Tracked
|
||||||
|
|
||||||
Name | Type | Description
|
| Name | Type | Description |
|
||||||
--------------------------------------------- | --------- | -----------------------------------------------------------------------
|
| --------------------------------------------- | --------- | ----------------------------------------------------------------------- |
|
||||||
grpc_client_request_duration_ms | Histogram | GRPC client request duration by service
|
| 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_request_size_bytes | Histogram | GRPC client request size by service |
|
||||||
grpc_client_requests_total | Counter | Total GRPC client requests made 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_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_duration_ms | Histogram | GRPC server request duration by service |
|
||||||
grpc_server_request_size_bytes | Histogram | GRPC server request size 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_requests_total | Counter | Total GRPC server requests made by service |
|
||||||
grpc_server_response_size_bytes | Histogram | GRPC server response size 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_duration_ms | Histogram | HTTP client request duration by service |
|
||||||
http_client_request_size_bytes | Histogram | HTTP client request size 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_requests_total | Counter | Total HTTP client requests made by service |
|
||||||
http_client_response_size_bytes | Histogram | HTTP client response size 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_duration_ms | Histogram | HTTP server request duration by service |
|
||||||
http_server_request_size_bytes | Histogram | HTTP server request size 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_requests_total | Counter | Total HTTP server requests handled by service |
|
||||||
http_server_response_size_bytes | Histogram | HTTP server response size 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_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_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 | 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
|
| 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_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_idle_conns | Gauge | Number of idle connections in the pool |
|
||||||
redis_wait_count_total | Counter | Total number of connections waited for
|
| redis_stale_conns | Gauge | Number of stale connections in the pool |
|
||||||
redis_wait_duration_ms_total | Counter | Total time spent waiting for connections
|
| redis_miss_count_total | Counter | Total number of times a connection was NOT found in the pool |
|
||||||
storage_operation_duration_ms | Histogram | Storage operation duration by operation, result, backend and service
|
| 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
|
#### Envoy Proxy Metrics
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -20,7 +20,6 @@ require (
|
||||||
github.com/go-redis/redis/v8 v8.4.2
|
github.com/go-redis/redis/v8 v8.4.2
|
||||||
github.com/golang/mock v1.4.4
|
github.com/golang/mock v1.4.4
|
||||||
github.com/golang/protobuf v1.4.3
|
github.com/golang/protobuf v1.4.3
|
||||||
github.com/gomodule/redigo v1.8.2
|
|
||||||
github.com/google/btree v1.0.0
|
github.com/google/btree v1.0.0
|
||||||
github.com/google/go-cmp v0.5.4
|
github.com/google/go-cmp v0.5.4
|
||||||
github.com/google/go-jsonnet v0.17.0
|
github.com/google/go-jsonnet v0.17.0
|
||||||
|
|
2
go.sum
2
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 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
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/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 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 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
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
|
// 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 {
|
gaugeMetrics := []struct {
|
||||||
name string
|
name string
|
||||||
desc string
|
desc string
|
||||||
f func() int64
|
f func() int64
|
||||||
}{
|
}{
|
||||||
{"redis_conns", "Number of total connections in the pool", func() int64 { return int64(stats().ActiveCount) }},
|
{"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().IdleCount) }},
|
{"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 {
|
for _, m := range gaugeMetrics {
|
||||||
|
@ -24,8 +25,8 @@ func AddRedisMetrics(stats func() redis.PoolStats) {
|
||||||
desc string
|
desc string
|
||||||
f func() int64
|
f func() int64
|
||||||
}{
|
}{
|
||||||
{"redis_wait_count_total", "Total number of connections waited for", func() int64 { return stats().WaitCount }},
|
{"redis_miss_count_total", "Total number of times a connection was not found in the pool", func() int64 { return int64(stats().Misses) }},
|
||||||
{"redis_wait_duration_ms_total", "Total time spent waiting for connections", func() int64 { return stats().WaitDuration.Milliseconds() }},
|
{"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 {
|
for _, m := range cumulativeMetrics {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package metrics
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
redis "github.com/go-redis/redis/v8"
|
||||||
"go.opencensus.io/metric/metricdata"
|
"go.opencensus.io/metric/metricdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@ func Test_AddRedisMetrics(t *testing.T) {
|
||||||
stat redis.PoolStats
|
stat redis.PoolStats
|
||||||
want int64
|
want int64
|
||||||
}{
|
}{
|
||||||
{"redis_conns", redis.PoolStats{ActiveCount: 7}, 7},
|
{"redis_conns", redis.PoolStats{TotalConns: 7}, 7},
|
||||||
{"redis_idle_conns", redis.PoolStats{IdleCount: 3}, 3},
|
{"redis_idle_conns", redis.PoolStats{IdleConns: 3}, 3},
|
||||||
{"redis_wait_count_total", redis.PoolStats{WaitCount: 2}, 2},
|
{"redis_miss_count_total", redis.PoolStats{Misses: 2}, 2},
|
||||||
}
|
}
|
||||||
|
|
||||||
labelValues := []metricdata.LabelValue{
|
labelValues := []metricdata.LabelValue{
|
||||||
|
@ -26,7 +26,7 @@ func Test_AddRedisMetrics(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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)
|
testMetricRetrieval(registry.registry.Read(), t, labelValues, tt.want, tt.name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ func New(rawURL string, options ...Option) (*DB, error) {
|
||||||
opts.TLSConfig = db.cfg.tls
|
opts.TLSConfig = db.cfg.tls
|
||||||
}
|
}
|
||||||
db.client = redis.NewClient(opts)
|
db.client = redis.NewClient(opts)
|
||||||
|
metrics.AddRedisMetrics(db.client.PoolStats)
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue