Merge pull request #115327 from jkh52/fix-metrics
Fix konnectivity-client metric registration. Kubernetes-commit: 301fa8f6333fea5d53aaa3777ce12fb40cc65ecb
This commit is contained in:
commit
ea4e287db4
4
go.mod
4
go.mod
|
|
@ -45,7 +45,7 @@ require (
|
|||
k8s.io/api v0.0.0-20230125050307-40fb3719e88c
|
||||
k8s.io/apimachinery v0.0.0-20230126210059-fdfff894ab1e
|
||||
k8s.io/client-go v0.0.0-20230125050636-adb1f506f945
|
||||
k8s.io/component-base v0.0.0-20230126101426-d7e10fe836b2
|
||||
k8s.io/component-base v0.0.0-20230127050810-4e5c2e38e679
|
||||
k8s.io/klog/v2 v2.80.1
|
||||
k8s.io/kms v0.0.0-20230123211024-c720300a8db5
|
||||
k8s.io/kube-openapi v0.0.0-20230123231816-1cb3ae25d79a
|
||||
|
|
@ -125,6 +125,6 @@ replace (
|
|||
k8s.io/api => k8s.io/api v0.0.0-20230125050307-40fb3719e88c
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230126210059-fdfff894ab1e
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20230125050636-adb1f506f945
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20230126101426-d7e10fe836b2
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20230127050810-4e5c2e38e679
|
||||
k8s.io/kms => k8s.io/kms v0.0.0-20230123211024-c720300a8db5
|
||||
)
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -997,8 +997,8 @@ k8s.io/apimachinery v0.0.0-20230126210059-fdfff894ab1e h1:r+iX1T1BMa2lOlVqpit9Jb
|
|||
k8s.io/apimachinery v0.0.0-20230126210059-fdfff894ab1e/go.mod h1:suKt6w4IrqrQon3BD6BHvCyL3po7Kow0e0cUsKElo/E=
|
||||
k8s.io/client-go v0.0.0-20230125050636-adb1f506f945 h1:j1Ia9yomT26ad1vK12xd/0rKS4uCvHBZdUy1C4VQl2k=
|
||||
k8s.io/client-go v0.0.0-20230125050636-adb1f506f945/go.mod h1:1dDy3x4HR6WwBKoUjK6YOMmEIFCsQ2slhfpDnmUFmjs=
|
||||
k8s.io/component-base v0.0.0-20230126101426-d7e10fe836b2 h1:HlXoz6wducfeY0vBak8fi5T9mG3WGtoYgwk1GaKU6kY=
|
||||
k8s.io/component-base v0.0.0-20230126101426-d7e10fe836b2/go.mod h1:g1Hva9kUZdDC9aLArJgSNeLl0ztEKs9x5DYTagSHZiI=
|
||||
k8s.io/component-base v0.0.0-20230127050810-4e5c2e38e679 h1:pDkuNWfO7RnmF9hRYJipdnAgN1pjPPPQmTbwrA7vlOA=
|
||||
k8s.io/component-base v0.0.0-20230127050810-4e5c2e38e679/go.mod h1:6FAae3pvKZAybDYrC1ihrJpgnoQXFc4fGcZLzyGMqQw=
|
||||
k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
|
||||
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||
k8s.io/kms v0.0.0-20230123211024-c720300a8db5 h1:EnOVrHLYqnz1/owNcRZilQoml6nKI0ogNQh7CNki7MY=
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import (
|
|||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apiserver/pkg/apis/apiserver"
|
||||
egressmetrics "k8s.io/apiserver/pkg/server/egressselector/metrics"
|
||||
compbasemetrics "k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"k8s.io/component-base/tracing"
|
||||
"k8s.io/klog/v2"
|
||||
client "sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client"
|
||||
|
|
@ -45,7 +45,7 @@ import (
|
|||
var directDialer utilnet.DialFunc = http.DefaultTransport.(*http.Transport).DialContext
|
||||
|
||||
func init() {
|
||||
client.Metrics.RegisterMetrics(compbasemetrics.NewKubeRegistry().Registerer())
|
||||
client.Metrics.RegisterMetrics(legacyregistry.Registerer())
|
||||
}
|
||||
|
||||
// EgressSelector is the map of network context type to context dialer, for network egress.
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package egressselector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
|
@ -31,6 +32,9 @@ import (
|
|||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"k8s.io/component-base/metrics/testutil"
|
||||
testingclock "k8s.io/utils/clock/testing"
|
||||
clientmetrics "sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client/metrics"
|
||||
ccmetrics "sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/common/metrics"
|
||||
"sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client"
|
||||
)
|
||||
|
||||
type fakeEgressSelection struct {
|
||||
|
|
@ -272,5 +276,70 @@ func TestMetrics(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestKonnectivityClientMetrics(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
metrics []string
|
||||
trigger func()
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "stream packets",
|
||||
metrics: []string{"konnectivity_network_proxy_client_stream_packets_total"},
|
||||
trigger: func() {
|
||||
clientmetrics.Metrics.ObservePacket(ccmetrics.SegmentFromClient, client.PacketType_DIAL_REQ)
|
||||
},
|
||||
want: `
|
||||
# HELP konnectivity_network_proxy_client_stream_packets_total Count of packets processed, by segment and packet type (example: from_client, DIAL_REQ)
|
||||
# TYPE konnectivity_network_proxy_client_stream_packets_total counter
|
||||
konnectivity_network_proxy_client_stream_packets_total{packet_type="DIAL_REQ",segment="from_client"} 1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "stream errors",
|
||||
metrics: []string{"konnectivity_network_proxy_client_stream_errors_total"},
|
||||
trigger: func() {
|
||||
clientmetrics.Metrics.ObserveStreamError(ccmetrics.SegmentToClient, errors.New("example"), client.PacketType_DIAL_RSP)
|
||||
},
|
||||
want: `
|
||||
# HELP konnectivity_network_proxy_client_stream_errors_total Count of gRPC stream errors, by segment, grpc Code, packet type. (example: from_agent, Code.Unavailable, DIAL_RSP)
|
||||
# TYPE konnectivity_network_proxy_client_stream_errors_total counter
|
||||
konnectivity_network_proxy_client_stream_errors_total{code="Unknown",packet_type="DIAL_RSP",segment="to_client"} 1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "dial failure",
|
||||
metrics: []string{"konnectivity_network_proxy_client_dial_failure_total"},
|
||||
trigger: func() {
|
||||
clientmetrics.Metrics.ObserveDialFailure(clientmetrics.DialFailureTimeout)
|
||||
},
|
||||
want: `
|
||||
# HELP konnectivity_network_proxy_client_dial_failure_total Number of dial failures observed, by reason (example: remote endpoint error)
|
||||
# TYPE konnectivity_network_proxy_client_dial_failure_total counter
|
||||
konnectivity_network_proxy_client_dial_failure_total{reason="timeout"} 1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "client connections",
|
||||
metrics: []string{"konnectivity_network_proxy_client_client_connections"},
|
||||
trigger: func() {
|
||||
clientmetrics.Metrics.GetClientConnectionsMetric().WithLabelValues("dialing").Inc()
|
||||
},
|
||||
want: `
|
||||
# HELP konnectivity_network_proxy_client_client_connections Number of open client connections, by status (Example: dialing)
|
||||
# TYPE konnectivity_network_proxy_client_client_connections gauge
|
||||
konnectivity_network_proxy_client_client_connections{status="dialing"} 1
|
||||
`,
|
||||
},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.trigger()
|
||||
if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(tc.want), tc.metrics...); err != nil {
|
||||
t.Errorf("GatherAndCompare error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue