Switch from grpc-ecosystem/go-grpc-prometheus to grpc-ecosystem/go-grpc-middleware/providers/prometheus
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
@ -216,7 +216,16 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"project": "github.com/grpc-ecosystem/go-grpc-prometheus",
|
"project": "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus",
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "Apache License 2.0",
|
||||||
|
"confidence": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors",
|
||||||
"licenses": [
|
"licenses": [
|
||||||
{
|
{
|
||||||
"type": "Apache License 2.0",
|
"type": "Apache License 2.0",
|
||||||
@ -785,6 +794,10 @@
|
|||||||
{
|
{
|
||||||
"project": "sigs.k8s.io/yaml",
|
"project": "sigs.k8s.io/yaml",
|
||||||
"licenses": [
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "Apache License 2.0",
|
||||||
|
"confidence": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "BSD 3-clause \"New\" or \"Revised\" License",
|
"type": "BSD 3-clause \"New\" or \"Revised\" License",
|
||||||
"confidence": 1
|
"confidence": 1
|
||||||
|
@ -7,6 +7,15 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"project": "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors",
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "Apache License 2.0",
|
||||||
|
"confidence": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"project": "github.com/inconshreveable/mousetrap",
|
"project": "github.com/inconshreveable/mousetrap",
|
||||||
"licenses": [
|
"licenses": [
|
||||||
|
@ -7,7 +7,7 @@ toolchain go1.23.5
|
|||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1
|
github.com/coreos/go-semver v0.3.1
|
||||||
github.com/dustin/go-humanize v1.0.1
|
github.com/dustin/go-humanize v1.0.1
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.20.5
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
go.etcd.io/etcd/api/v3 v3.6.0-alpha.0
|
go.etcd.io/etcd/api/v3 v3.6.0-alpha.0
|
||||||
@ -24,6 +24,7 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/protobuf v1.5.4 // indirect
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
|
@ -24,8 +24,10 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
|
@ -32,8 +32,10 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
@ -52,7 +52,8 @@ require (
|
|||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.4.2 // indirect
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||||
|
@ -37,8 +37,10 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
3
go.mod
3
go.mod
@ -59,7 +59,8 @@ require (
|
|||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.4.2 // indirect
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||||
|
6
go.sum
6
go.sum
@ -67,8 +67,10 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
|
|||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
@ -211,6 +211,9 @@ type ServerConfig struct {
|
|||||||
|
|
||||||
// ServerFeatureGate is a server level feature gate
|
// ServerFeatureGate is a server level feature gate
|
||||||
ServerFeatureGate featuregate.FeatureGate
|
ServerFeatureGate featuregate.FeatureGate
|
||||||
|
|
||||||
|
// Metrics types of metrics - should be either 'basic' or 'extensive'
|
||||||
|
Metrics string
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
|
||||||
"github.com/soheilhy/cmux"
|
"github.com/soheilhy/cmux"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -239,6 +238,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
|
|||||||
V2Deprecation: cfg.V2DeprecationEffective(),
|
V2Deprecation: cfg.V2DeprecationEffective(),
|
||||||
ExperimentalLocalAddress: cfg.InferLocalAddr(),
|
ExperimentalLocalAddress: cfg.InferLocalAddr(),
|
||||||
ServerFeatureGate: cfg.ServerFeatureGate,
|
ServerFeatureGate: cfg.ServerFeatureGate,
|
||||||
|
Metrics: cfg.Metrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
if srvcfg.ExperimentalEnableDistributedTracing {
|
if srvcfg.ExperimentalEnableDistributedTracing {
|
||||||
@ -876,10 +876,6 @@ func (e *Etcd) createMetricsListener(murl url.URL) (net.Listener, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Etcd) serveMetrics() (err error) {
|
func (e *Etcd) serveMetrics() (err error) {
|
||||||
if e.cfg.Metrics == "extensive" {
|
|
||||||
grpc_prometheus.EnableHandlingTimeHistogram()
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(e.cfg.ListenMetricsUrls) > 0 {
|
if len(e.cfg.ListenMetricsUrls) > 0 {
|
||||||
metricsMux := http.NewServeMux()
|
metricsMux := http.NewServeMux()
|
||||||
etcdhttp.HandleMetrics(metricsMux)
|
etcdhttp.HandleMetrics(metricsMux)
|
||||||
|
@ -30,8 +30,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
|
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
|
||||||
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||||
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
|
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/soheilhy/cmux"
|
"github.com/soheilhy/cmux"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -505,11 +506,14 @@ func newGRPCProxyServer(lg *zap.Logger, client *clientv3.Client) *grpc.Server {
|
|||||||
|
|
||||||
alwaysLoggingDeciderServer := func(ctx context.Context, fullMethodName string, servingObject any) bool { return true }
|
alwaysLoggingDeciderServer := func(ctx context.Context, fullMethodName string, servingObject any) bool { return true }
|
||||||
|
|
||||||
|
serverMetrics := grpc_prometheus.NewServerMetrics()
|
||||||
|
prometheus.MustRegister(serverMetrics)
|
||||||
|
|
||||||
grpcChainStreamList := []grpc.StreamServerInterceptor{
|
grpcChainStreamList := []grpc.StreamServerInterceptor{
|
||||||
grpc_prometheus.StreamServerInterceptor,
|
serverMetrics.StreamServerInterceptor(),
|
||||||
}
|
}
|
||||||
grpcChainUnaryList := []grpc.UnaryServerInterceptor{
|
grpcChainUnaryList := []grpc.UnaryServerInterceptor{
|
||||||
grpc_prometheus.UnaryServerInterceptor,
|
serverMetrics.UnaryServerInterceptor(),
|
||||||
}
|
}
|
||||||
if grpcProxyEnableLogging {
|
if grpcProxyEnableLogging {
|
||||||
grpcChainStreamList = append(grpcChainStreamList,
|
grpcChainStreamList = append(grpcChainStreamList,
|
||||||
|
@ -18,8 +18,10 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||||
|
"go.uber.org/zap"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/health"
|
"google.golang.org/grpc/health"
|
||||||
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
@ -39,10 +41,17 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, interceptor grpc.UnarySer
|
|||||||
if tls != nil {
|
if tls != nil {
|
||||||
opts = append(opts, grpc.Creds(credentials.NewTransportCredential(tls)))
|
opts = append(opts, grpc.Creds(credentials.NewTransportCredential(tls)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serverMetrics := grpc_prometheus.NewServerMetrics()
|
||||||
|
err := prometheus.Register(serverMetrics)
|
||||||
|
if err != nil {
|
||||||
|
s.Cfg.Logger.Warn("etcdserver: failed to register grpc metrics: ", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
chainUnaryInterceptors := []grpc.UnaryServerInterceptor{
|
chainUnaryInterceptors := []grpc.UnaryServerInterceptor{
|
||||||
newLogUnaryInterceptor(s),
|
newLogUnaryInterceptor(s),
|
||||||
newUnaryInterceptor(s),
|
newUnaryInterceptor(s),
|
||||||
grpc_prometheus.UnaryServerInterceptor,
|
serverMetrics.UnaryServerInterceptor(),
|
||||||
}
|
}
|
||||||
if interceptor != nil {
|
if interceptor != nil {
|
||||||
chainUnaryInterceptors = append(chainUnaryInterceptors, interceptor)
|
chainUnaryInterceptors = append(chainUnaryInterceptors, interceptor)
|
||||||
@ -50,7 +59,14 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, interceptor grpc.UnarySer
|
|||||||
|
|
||||||
chainStreamInterceptors := []grpc.StreamServerInterceptor{
|
chainStreamInterceptors := []grpc.StreamServerInterceptor{
|
||||||
newStreamInterceptor(s),
|
newStreamInterceptor(s),
|
||||||
grpc_prometheus.StreamServerInterceptor,
|
serverMetrics.StreamServerInterceptor(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// If extensive metrics are enabled, register a histogram to track the reponse latency of gRPC requests
|
||||||
|
if s.Cfg.Metrics == "extensive" {
|
||||||
|
unaryInterceptor, streamInterceptor := constructExtensiveMetricsInterceptors()
|
||||||
|
chainUnaryInterceptors = append(chainUnaryInterceptors, unaryInterceptor)
|
||||||
|
chainStreamInterceptors = append(chainStreamInterceptors, streamInterceptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Cfg.ExperimentalEnableDistributedTracing {
|
if s.Cfg.ExperimentalEnableDistributedTracing {
|
||||||
@ -79,7 +95,7 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, interceptor grpc.UnarySer
|
|||||||
pb.RegisterMaintenanceServer(grpcServer, NewMaintenanceServer(s, healthNotifier))
|
pb.RegisterMaintenanceServer(grpcServer, NewMaintenanceServer(s, healthNotifier))
|
||||||
|
|
||||||
// set zero values for metrics registered for this grpc server
|
// set zero values for metrics registered for this grpc server
|
||||||
grpc_prometheus.Register(grpcServer)
|
serverMetrics.InitializeMetrics(grpcServer)
|
||||||
|
|
||||||
return grpcServer
|
return grpcServer
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,14 @@
|
|||||||
|
|
||||||
package v3rpc
|
package v3rpc
|
||||||
|
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sentBytes = prometheus.NewCounter(prometheus.CounterOpts{
|
sentBytes = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
@ -58,3 +65,46 @@ func init() {
|
|||||||
prometheus.MustRegister(streamFailures)
|
prometheus.MustRegister(streamFailures)
|
||||||
prometheus.MustRegister(clientRequests)
|
prometheus.MustRegister(clientRequests)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitMethodName(fullMethodName string) (string, string) {
|
||||||
|
fullMethodName = strings.TrimPrefix(fullMethodName, "/") // remove leading slash
|
||||||
|
if i := strings.Index(fullMethodName, "/"); i >= 0 {
|
||||||
|
return fullMethodName[:i], fullMethodName[i+1:]
|
||||||
|
}
|
||||||
|
return "unknown", "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructExtensiveMetricsInterceptors constructs unary and stream interceptors to record histogram metrics for gRPC requests
|
||||||
|
func constructExtensiveMetricsInterceptors() (grpc.UnaryServerInterceptor, grpc.StreamServerInterceptor) {
|
||||||
|
// Define a new histogram metric using default buckets
|
||||||
|
serverHandledHistogram := prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "grpc_server_handling_seconds",
|
||||||
|
Help: "Histogram of response latency (seconds) of gRPC that had been application-level handled by the server.",
|
||||||
|
Buckets: prometheus.DefBuckets,
|
||||||
|
},
|
||||||
|
[]string{"grpc_type", "grpc_service", "grpc_method"},
|
||||||
|
)
|
||||||
|
prometheus.MustRegister(serverHandledHistogram)
|
||||||
|
|
||||||
|
// method to record histogram metrics for both unary and stream requests
|
||||||
|
recordHistogramMetrics := func(serverHandledHistogram *prometheus.HistogramVec, grpcType, fullMethodName string, startTime time.Time) {
|
||||||
|
grpcService, grpcMethod := splitMethodName(fullMethodName)
|
||||||
|
serverHandledHistogram.WithLabelValues(grpcType, grpcService, grpcMethod).Observe(time.Since(startTime).Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a new interceptor to spit out histogram metrics for unary requests
|
||||||
|
unaryInterceptor := func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
|
||||||
|
startTime := time.Now()
|
||||||
|
resp, err = handler(ctx, req)
|
||||||
|
recordHistogramMetrics(serverHandledHistogram, "unary", info.FullMethod, startTime)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
streamInterceptor := func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||||
|
startTime := time.Now()
|
||||||
|
err := handler(srv, ss)
|
||||||
|
recordHistogramMetrics(serverHandledHistogram, "stream", info.FullMethod, startTime)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return unaryInterceptor, streamInterceptor
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ require (
|
|||||||
github.com/google/btree v1.1.3
|
github.com/google/btree v1.1.3
|
||||||
github.com/google/go-cmp v0.6.0
|
github.com/google/go-cmp v0.6.0
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0
|
||||||
github.com/jonboulle/clockwork v0.5.0
|
github.com/jonboulle/clockwork v0.5.0
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.20.5
|
||||||
@ -56,6 +56,7 @@ require (
|
|||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.4.2 // indirect
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||||
|
@ -59,8 +59,10 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
|
|||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
@ -175,6 +175,7 @@ type ClusterConfig struct {
|
|||||||
MaxLearners int
|
MaxLearners int
|
||||||
DisableStrictReconfigCheck bool
|
DisableStrictReconfigCheck bool
|
||||||
CorruptCheckTime time.Duration
|
CorruptCheckTime time.Duration
|
||||||
|
Metrics string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
@ -292,6 +293,7 @@ func (c *Cluster) MustNewMember(t testutil.TB) *Member {
|
|||||||
MaxLearners: c.Cfg.MaxLearners,
|
MaxLearners: c.Cfg.MaxLearners,
|
||||||
DisableStrictReconfigCheck: c.Cfg.DisableStrictReconfigCheck,
|
DisableStrictReconfigCheck: c.Cfg.DisableStrictReconfigCheck,
|
||||||
CorruptCheckTime: c.Cfg.CorruptCheckTime,
|
CorruptCheckTime: c.Cfg.CorruptCheckTime,
|
||||||
|
Metrics: c.Cfg.Metrics,
|
||||||
})
|
})
|
||||||
m.DiscoveryURL = c.Cfg.DiscoveryURL
|
m.DiscoveryURL = c.Cfg.DiscoveryURL
|
||||||
return m
|
return m
|
||||||
@ -617,6 +619,7 @@ type MemberConfig struct {
|
|||||||
MaxLearners int
|
MaxLearners int
|
||||||
DisableStrictReconfigCheck bool
|
DisableStrictReconfigCheck bool
|
||||||
CorruptCheckTime time.Duration
|
CorruptCheckTime time.Duration
|
||||||
|
Metrics string
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustNewMember return an inited member with the given name. If peerTLS is
|
// MustNewMember return an inited member with the given name. If peerTLS is
|
||||||
@ -731,6 +734,7 @@ func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member {
|
|||||||
if mcfg.MaxLearners != 0 {
|
if mcfg.MaxLearners != 0 {
|
||||||
m.MaxLearners = mcfg.MaxLearners
|
m.MaxLearners = mcfg.MaxLearners
|
||||||
}
|
}
|
||||||
|
m.Metrics = mcfg.Metrics
|
||||||
m.V2Deprecation = config.V2_DEPR_DEFAULT
|
m.V2Deprecation = config.V2_DEPR_DEFAULT
|
||||||
m.GRPCServerRecorder = &grpctesting.GRPCRecorder{}
|
m.GRPCServerRecorder = &grpctesting.GRPCRecorder{}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.4
|
github.com/golang/protobuf v1.5.4
|
||||||
github.com/google/go-cmp v0.6.0
|
github.com/google/go-cmp v0.6.0
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.20.5
|
||||||
github.com/prometheus/client_model v0.6.1
|
github.com/prometheus/client_model v0.6.1
|
||||||
@ -71,6 +71,7 @@ require (
|
|||||||
github.com/google/btree v1.1.3 // indirect
|
github.com/google/btree v1.1.3 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.4.2 // indirect
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
|
@ -71,8 +71,10 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
|
|||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
@ -23,7 +23,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
grpcprom "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -35,11 +36,13 @@ func mockClient_metrics() {
|
|||||||
|
|
||||||
func ExampleClient_metrics() {
|
func ExampleClient_metrics() {
|
||||||
forUnitTestsRunInMockedContext(mockClient_metrics, func() {
|
forUnitTestsRunInMockedContext(mockClient_metrics, func() {
|
||||||
|
clientMetrics := grpcprom.NewClientMetrics()
|
||||||
|
prometheus.Register(clientMetrics)
|
||||||
cli, err := clientv3.New(clientv3.Config{
|
cli, err := clientv3.New(clientv3.Config{
|
||||||
Endpoints: exampleEndpoints(),
|
Endpoints: exampleEndpoints(),
|
||||||
DialOptions: []grpc.DialOption{
|
DialOptions: []grpc.DialOption{
|
||||||
grpc.WithUnaryInterceptor(grpcprom.UnaryClientInterceptor),
|
grpc.WithUnaryInterceptor(clientMetrics.UnaryClientInterceptor()),
|
||||||
grpc.WithStreamInterceptor(grpcprom.StreamClientInterceptor),
|
grpc.WithStreamInterceptor(clientMetrics.StreamClientInterceptor()),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,6 +16,7 @@ package clientv3test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
@ -27,9 +28,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
grpcprom "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"github.com/prometheus/common/expfmt"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"go.etcd.io/etcd/client/pkg/v3/transport"
|
"go.etcd.io/etcd/client/pkg/v3/transport"
|
||||||
@ -75,11 +77,14 @@ func TestV3ClientMetrics(t *testing.T) {
|
|||||||
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1})
|
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1})
|
||||||
defer clus.Terminate(t)
|
defer clus.Terminate(t)
|
||||||
|
|
||||||
|
clientMetrics := grpcprom.NewClientMetrics()
|
||||||
|
prometheus.Register(clientMetrics)
|
||||||
|
|
||||||
cfg := clientv3.Config{
|
cfg := clientv3.Config{
|
||||||
Endpoints: []string{clus.Members[0].GRPCURL},
|
Endpoints: []string{clus.Members[0].GRPCURL},
|
||||||
DialOptions: []grpc.DialOption{
|
DialOptions: []grpc.DialOption{
|
||||||
grpc.WithUnaryInterceptor(grpcprom.UnaryClientInterceptor),
|
grpc.WithUnaryInterceptor(clientMetrics.UnaryClientInterceptor()),
|
||||||
grpc.WithStreamInterceptor(grpcprom.StreamClientInterceptor),
|
grpc.WithStreamInterceptor(clientMetrics.StreamClientInterceptor()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cli, cerr := integration2.NewClient(t, cfg)
|
cli, cerr := integration2.NewClient(t, cfg)
|
||||||
@ -147,6 +152,24 @@ func sumCountersForMetricAndLabels(t *testing.T, url string, metricName string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHTTPBodyAsLines(t *testing.T, url string) []string {
|
func getHTTPBodyAsLines(t *testing.T, url string) []string {
|
||||||
|
data := getHTTPBodyAsBytes(t, url)
|
||||||
|
|
||||||
|
reader := bufio.NewReader(bytes.NewReader(data))
|
||||||
|
var lines []string
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
t.Fatalf("error reading: %v", err)
|
||||||
|
}
|
||||||
|
lines = append(lines, line)
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHTTPBodyAsBytes(t *testing.T, url string) []byte {
|
||||||
cfgtls := transport.TLSInfo{}
|
cfgtls := transport.TLSInfo{}
|
||||||
tr, err := transport.NewTransport(cfgtls, time.Second)
|
tr, err := transport.NewTransport(cfgtls, time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -162,21 +185,12 @@ func getHTTPBodyAsLines(t *testing.T, url string) []string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error fetching: %v", err)
|
t.Fatalf("Error fetching: %v", err)
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
reader := bufio.NewReader(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
var lines []string
|
|
||||||
for {
|
|
||||||
line, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, io.EOF) {
|
t.Fatalf("Error reading http body: %v", err)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
t.Fatalf("error reading: %v", err)
|
return body
|
||||||
}
|
|
||||||
lines = append(lines, line)
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
return lines
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAllMetricsGenerated(t *testing.T) {
|
func TestAllMetricsGenerated(t *testing.T) {
|
||||||
@ -213,7 +227,7 @@ func TestAllMetricsGenerated(t *testing.T) {
|
|||||||
|
|
||||||
url := "unix://" + addr + "/metrics"
|
url := "unix://" + addr + "/metrics"
|
||||||
|
|
||||||
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1})
|
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1, Metrics: "extensive"})
|
||||||
defer clus.Terminate(t)
|
defer clus.Terminate(t)
|
||||||
|
|
||||||
clientMetrics := grpcprom.NewClientMetrics()
|
clientMetrics := grpcprom.NewClientMetrics()
|
||||||
@ -249,42 +263,26 @@ func TestAllMetricsGenerated(t *testing.T) {
|
|||||||
// Define the expected list of metrics
|
// Define the expected list of metrics
|
||||||
expectedMetrics := []string{
|
expectedMetrics := []string{
|
||||||
"etcd_cluster_version",
|
"etcd_cluster_version",
|
||||||
"etcd_disk_backend_commit_duration_seconds_bucket",
|
"etcd_disk_backend_commit_duration_seconds",
|
||||||
"etcd_disk_backend_commit_duration_seconds_count",
|
"etcd_disk_backend_defrag_duration_seconds",
|
||||||
"etcd_disk_backend_commit_duration_seconds_sum",
|
"etcd_disk_backend_snapshot_duration_seconds",
|
||||||
"etcd_disk_backend_defrag_duration_seconds_bucket",
|
|
||||||
"etcd_disk_backend_defrag_duration_seconds_count",
|
|
||||||
"etcd_disk_backend_defrag_duration_seconds_sum",
|
|
||||||
"etcd_disk_backend_snapshot_duration_seconds_bucket",
|
|
||||||
"etcd_disk_backend_snapshot_duration_seconds_count",
|
|
||||||
"etcd_disk_backend_snapshot_duration_seconds_sum",
|
|
||||||
"etcd_disk_defrag_inflight",
|
"etcd_disk_defrag_inflight",
|
||||||
"etcd_disk_wal_fsync_duration_seconds_bucket",
|
"etcd_disk_wal_fsync_duration_seconds",
|
||||||
"etcd_disk_wal_fsync_duration_seconds_count",
|
|
||||||
"etcd_disk_wal_fsync_duration_seconds_sum",
|
|
||||||
"etcd_disk_wal_write_bytes_total",
|
"etcd_disk_wal_write_bytes_total",
|
||||||
"etcd_disk_wal_write_duration_seconds_bucket",
|
"etcd_disk_wal_write_duration_seconds",
|
||||||
"etcd_disk_wal_write_duration_seconds_count",
|
|
||||||
"etcd_disk_wal_write_duration_seconds_sum",
|
|
||||||
"etcd_mvcc_db_open_read_transactions",
|
"etcd_mvcc_db_open_read_transactions",
|
||||||
"etcd_mvcc_db_total_size_in_bytes",
|
"etcd_mvcc_db_total_size_in_bytes",
|
||||||
"etcd_mvcc_db_total_size_in_use_in_bytes",
|
"etcd_mvcc_db_total_size_in_use_in_bytes",
|
||||||
"etcd_mvcc_delete_total",
|
"etcd_mvcc_delete_total",
|
||||||
"etcd_mvcc_hash_duration_seconds_bucket",
|
"etcd_mvcc_hash_duration_seconds",
|
||||||
"etcd_mvcc_hash_duration_seconds_count",
|
"etcd_mvcc_hash_rev_duration_seconds",
|
||||||
"etcd_mvcc_hash_duration_seconds_sum",
|
|
||||||
"etcd_mvcc_hash_rev_duration_seconds_bucket",
|
|
||||||
"etcd_mvcc_hash_rev_duration_seconds_count",
|
|
||||||
"etcd_mvcc_hash_rev_duration_seconds_sum",
|
|
||||||
"etcd_mvcc_put_total",
|
"etcd_mvcc_put_total",
|
||||||
"etcd_mvcc_range_total",
|
"etcd_mvcc_range_total",
|
||||||
"etcd_mvcc_txn_total",
|
"etcd_mvcc_txn_total",
|
||||||
"etcd_network_client_grpc_received_bytes_total",
|
"etcd_network_client_grpc_received_bytes_total",
|
||||||
"etcd_network_client_grpc_sent_bytes_total",
|
"etcd_network_client_grpc_sent_bytes_total",
|
||||||
"etcd_network_known_peers",
|
"etcd_network_known_peers",
|
||||||
"etcd_server_apply_duration_seconds_bucket",
|
"etcd_server_apply_duration_seconds",
|
||||||
"etcd_server_apply_duration_seconds_count",
|
|
||||||
"etcd_server_apply_duration_seconds_sum",
|
|
||||||
"etcd_server_client_requests_total",
|
"etcd_server_client_requests_total",
|
||||||
"etcd_server_go_version",
|
"etcd_server_go_version",
|
||||||
"etcd_server_has_leader",
|
"etcd_server_has_leader",
|
||||||
@ -306,20 +304,15 @@ func TestAllMetricsGenerated(t *testing.T) {
|
|||||||
"etcd_server_slow_read_indexes_total",
|
"etcd_server_slow_read_indexes_total",
|
||||||
"etcd_server_snapshot_apply_in_progress_total",
|
"etcd_server_snapshot_apply_in_progress_total",
|
||||||
"etcd_server_version",
|
"etcd_server_version",
|
||||||
"etcd_snap_db_fsync_duration_seconds_bucket",
|
"etcd_snap_db_fsync_duration_seconds",
|
||||||
"etcd_snap_db_fsync_duration_seconds_count",
|
"etcd_snap_db_save_total_duration_seconds",
|
||||||
"etcd_snap_db_fsync_duration_seconds_sum",
|
"etcd_snap_fsync_duration_seconds",
|
||||||
"etcd_snap_db_save_total_duration_seconds_bucket",
|
|
||||||
"etcd_snap_db_save_total_duration_seconds_count",
|
|
||||||
"etcd_snap_db_save_total_duration_seconds_sum",
|
|
||||||
"etcd_snap_fsync_duration_seconds_bucket",
|
|
||||||
"etcd_snap_fsync_duration_seconds_count",
|
|
||||||
"etcd_snap_fsync_duration_seconds_sum",
|
|
||||||
"grpc_client_handled_total",
|
"grpc_client_handled_total",
|
||||||
"grpc_client_msg_received_total",
|
"grpc_client_msg_received_total",
|
||||||
"grpc_client_msg_sent_total",
|
"grpc_client_msg_sent_total",
|
||||||
"grpc_client_started_total",
|
"grpc_client_started_total",
|
||||||
"grpc_server_handled_total",
|
"grpc_server_handled_total",
|
||||||
|
"grpc_server_handling_seconds",
|
||||||
"grpc_server_msg_received_total",
|
"grpc_server_msg_received_total",
|
||||||
"grpc_server_msg_sent_total",
|
"grpc_server_msg_sent_total",
|
||||||
"grpc_server_started_total",
|
"grpc_server_started_total",
|
||||||
@ -335,20 +328,15 @@ func TestAllMetricsGenerated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMetricsList(t *testing.T, url string) []string {
|
func getMetricsList(t *testing.T, url string) []string {
|
||||||
lines := getHTTPBodyAsLines(t, url)
|
data := getHTTPBodyAsBytes(t, url)
|
||||||
metrics := make(map[string]struct{})
|
var parser expfmt.TextParser
|
||||||
for _, line := range lines {
|
mfs, err := parser.TextToMetricFamilies(bytes.NewReader(data))
|
||||||
if strings.Contains(line, "{") {
|
if err != nil {
|
||||||
metric := line[:strings.Index(line, "{")]
|
t.Errorf("Failed to parse metric families")
|
||||||
metrics[metric] = struct{}{}
|
|
||||||
} else {
|
|
||||||
metric := line[:strings.Index(line, " ")]
|
|
||||||
metrics[metric] = struct{}{}
|
|
||||||
}
|
}
|
||||||
|
var ms []string
|
||||||
|
for key := range mfs {
|
||||||
|
ms = append(ms, key)
|
||||||
}
|
}
|
||||||
var metricList []string
|
return ms
|
||||||
for metric := range metrics {
|
|
||||||
metricList = append(metricList, metric)
|
|
||||||
}
|
|
||||||
return metricList
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user