mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-13 05:41:35 +00:00
add new metrics for the internal client-go transport generator
Add two new metrics to monitor the client-go logic that generate http.Transports for the clients. - rest_client_transport_cache_entries is a gauge metrics with the number of existin entries in the internal cache - rest_client_transport_create_calls_total is a counter that increments each time a new transport is created, storing the result of the operation needed to generate it: hit, miss or uncacheable Change-Id: I2d8bde25281153d8f8e8faa249385edde3c1cb39 Kubernetes-commit: 3f3e1d507d081528ce8081f0daf4446d8a3b9bc0
This commit is contained in:
committed by
Kubernetes Publisher
parent
783d0d3362
commit
7cf3125431
@@ -64,6 +64,17 @@ type RetryMetric interface {
|
|||||||
IncrementRetry(ctx context.Context, code string, method string, host string)
|
IncrementRetry(ctx context.Context, code string, method string, host string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TransportCacheMetric shows the number of entries in the internal transport cache
|
||||||
|
type TransportCacheMetric interface {
|
||||||
|
Observe(value int)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransportCreateCallsMetric counts the number of times a transport is created
|
||||||
|
// partitioned by the result of the cache: hit, miss, uncacheable
|
||||||
|
type TransportCreateCallsMetric interface {
|
||||||
|
Increment(result string)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ClientCertExpiry is the expiry time of a client certificate
|
// ClientCertExpiry is the expiry time of a client certificate
|
||||||
ClientCertExpiry ExpiryMetric = noopExpiry{}
|
ClientCertExpiry ExpiryMetric = noopExpiry{}
|
||||||
@@ -85,6 +96,12 @@ var (
|
|||||||
// RequestRetry is the retry metric that tracks the number of
|
// RequestRetry is the retry metric that tracks the number of
|
||||||
// retries sent to the server.
|
// retries sent to the server.
|
||||||
RequestRetry RetryMetric = noopRetry{}
|
RequestRetry RetryMetric = noopRetry{}
|
||||||
|
// TransportCacheEntries is the metric that tracks the number of entries in the
|
||||||
|
// internal transport cache.
|
||||||
|
TransportCacheEntries TransportCacheMetric = noopTransportCache{}
|
||||||
|
// TransportCreateCalls is the metric that counts the number of times a new transport
|
||||||
|
// is created
|
||||||
|
TransportCreateCalls TransportCreateCallsMetric = noopTransportCreateCalls{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterOpts contains all the metrics to register. Metrics may be nil.
|
// RegisterOpts contains all the metrics to register. Metrics may be nil.
|
||||||
@@ -98,6 +115,8 @@ type RegisterOpts struct {
|
|||||||
RequestResult ResultMetric
|
RequestResult ResultMetric
|
||||||
ExecPluginCalls CallsMetric
|
ExecPluginCalls CallsMetric
|
||||||
RequestRetry RetryMetric
|
RequestRetry RetryMetric
|
||||||
|
TransportCacheEntries TransportCacheMetric
|
||||||
|
TransportCreateCalls TransportCreateCallsMetric
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register registers metrics for the rest client to use. This can
|
// Register registers metrics for the rest client to use. This can
|
||||||
@@ -131,6 +150,12 @@ func Register(opts RegisterOpts) {
|
|||||||
if opts.RequestRetry != nil {
|
if opts.RequestRetry != nil {
|
||||||
RequestRetry = opts.RequestRetry
|
RequestRetry = opts.RequestRetry
|
||||||
}
|
}
|
||||||
|
if opts.TransportCacheEntries != nil {
|
||||||
|
TransportCacheEntries = opts.TransportCacheEntries
|
||||||
|
}
|
||||||
|
if opts.TransportCreateCalls != nil {
|
||||||
|
TransportCreateCalls = opts.TransportCreateCalls
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,3 +186,11 @@ func (noopCalls) Increment(int, string) {}
|
|||||||
type noopRetry struct{}
|
type noopRetry struct{}
|
||||||
|
|
||||||
func (noopRetry) IncrementRetry(context.Context, string, string, string) {}
|
func (noopRetry) IncrementRetry(context.Context, string, string, string) {}
|
||||||
|
|
||||||
|
type noopTransportCache struct{}
|
||||||
|
|
||||||
|
func (noopTransportCache) Observe(int) {}
|
||||||
|
|
||||||
|
type noopTransportCreateCalls struct{}
|
||||||
|
|
||||||
|
func (noopTransportCreateCalls) Increment(string) {}
|
||||||
|
@@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"k8s.io/client-go/tools/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TlsTransportCache caches TLS http.RoundTrippers different configurations. The
|
// TlsTransportCache caches TLS http.RoundTrippers different configurations. The
|
||||||
@@ -80,11 +81,16 @@ func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
|
|||||||
// Ensure we only create a single transport for the given TLS options
|
// Ensure we only create a single transport for the given TLS options
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
defer metrics.TransportCacheEntries.Observe(len(c.transports))
|
||||||
|
|
||||||
// See if we already have a custom transport for this config
|
// See if we already have a custom transport for this config
|
||||||
if t, ok := c.transports[key]; ok {
|
if t, ok := c.transports[key]; ok {
|
||||||
|
metrics.TransportCreateCalls.Increment("hit")
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
metrics.TransportCreateCalls.Increment("miss")
|
||||||
|
} else {
|
||||||
|
metrics.TransportCreateCalls.Increment("uncacheable")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the TLS options for this client config
|
// Get the TLS options for this client config
|
||||||
|
Reference in New Issue
Block a user