apiserverk8s.io/apiserver/pkg/endpoints/metrics Index | Files

package metrics

import "k8s.io/apiserver/pkg/endpoints/metrics"

Index

Constants

const (
	APIServerComponent string = "apiserver"
	OtherRequestMethod string = "other"
)
const (
	// ReadOnlyKind is a string identifying read only request kind
	ReadOnlyKind = "readOnly"
	// MutatingKind is a string identifying mutating request kind
	MutatingKind = "mutating"

	// WaitingPhase is the phase value for a request waiting in a queue
	WaitingPhase = "waiting"
	// ExecutingPhase is the phase value for an executing request
	ExecutingPhase = "executing"
)
const (
	// The source that is recording the apiserver_request_post_timeout_total metric.
	// The "executing" request handler returns after the timeout filter times out the request.
	PostTimeoutSourceTimeoutHandler = "timeout-handler"

	// The source that is recording the apiserver_request_post_timeout_total metric.
	// The "executing" request handler returns after the rest layer times out the request.
	PostTimeoutSourceRestHandler = "rest-handler"
)
const (
	// The executing request handler panicked after the request had
	// been timed out by the apiserver.
	PostTimeoutHandlerPanic = "panic"

	// The executing request handler has returned an error to the post-timeout
	// receiver after the request had been timed out by the apiserver.
	PostTimeoutHandlerError = "error"

	// The executing request handler has returned a result to the post-timeout
	// receiver after the request had been timed out by the apiserver.
	PostTimeoutHandlerOK = "ok"

	// The executing request handler has not panicked or returned any error/result to
	// the post-timeout receiver yet after the request had been timed out by the apiserver.
	// The post-timeout receiver gives up after waiting for certain threshold and if the
	// executing request handler has not returned yet we use the following label.
	PostTimeoutHandlerPending = "pending"
)

Variables

var (

	// TLSHandshakeErrors is a number of requests dropped with 'TLS handshake error from' error
	TLSHandshakeErrors = compbasemetrics.NewCounter(
		&compbasemetrics.CounterOpts{
			Subsystem:      APIServerComponent,
			Name:           "tls_handshake_errors_total",
			Help:           "Number of requests dropped with 'TLS handshake error from' error",
			StabilityLevel: compbasemetrics.ALPHA,
		},
	)
	WatchEvents = compbasemetrics.NewCounterVec(
		&compbasemetrics.CounterOpts{
			Subsystem:      APIServerComponent,
			Name:           "watch_events_total",
			Help:           "Number of events sent in watch clients",
			StabilityLevel: compbasemetrics.ALPHA,
		},
		[]string{"group", "version", "kind"},
	)
	WatchEventsSizes = compbasemetrics.NewHistogramVec(
		&compbasemetrics.HistogramOpts{
			Subsystem:      APIServerComponent,
			Name:           "watch_events_sizes",
			Help:           "Watch event size distribution in bytes",
			Buckets:        compbasemetrics.ExponentialBuckets(1024, 2.0, 8),
			StabilityLevel: compbasemetrics.ALPHA,
		},
		[]string{"group", "version", "kind"},
	)
)

* By default, all the following metrics are defined as falling under * ALPHA stability level https://github.com/kubernetes/enhancements/blob/master/keps/sig-instrumentation/1209-metrics-stability/kubernetes-control-plane-metrics-stability.md#stability-classes) * * Promoting the stability level of the metric is a responsibility of the component owner, since it * involves explicitly acknowledging support for the metric across multiple releases, in accordance with * the metric stability policy.

Functions

func CanonicalVerb

func CanonicalVerb(verb string, scope string) string

CanonicalVerb distinguishes LISTs from GETs (and HEADs). It assumes verb is UPPERCASE.

func CleanListScope

func CleanListScope(ctx context.Context, opts *metainternalversion.ListOptions) string

CleanListScope computes the request scope for metrics.

Note that normally we would use CleanScope for computation. But due to the same reasons mentioned in determineRequestNamespaceAndName we cannot.

func CleanScope

func CleanScope(requestInfo *request.RequestInfo) string

CleanScope returns the scope of the request.

func CleanVerb

func CleanVerb(verb string, request *http.Request, requestInfo *request.RequestInfo) string

CleanVerb returns a normalized verb, so that it is easy to tell WATCH from LIST, APPLY from PATCH and CONNECT from others.

func InstrumentHandlerFunc

func InstrumentHandlerFunc(verb, group, version, resource, subresource, scope, component string, deprecated bool, removedRelease string, handler http.HandlerFunc) http.HandlerFunc

InstrumentHandlerFunc works like Prometheus' InstrumentHandlerFunc but adds some Kubernetes endpoint specific information.

func InstrumentRouteFunc

func InstrumentRouteFunc(verb, group, version, resource, subresource, scope, component string, deprecated bool, removedRelease string, routeFunc restful.RouteFunction) restful.RouteFunction

InstrumentRouteFunc works like Prometheus' InstrumentHandlerFunc but wraps the go-restful RouteFunction instead of a HandlerFunc plus some Kubernetes endpoint specific information.

func MonitorRequest

func MonitorRequest(req *http.Request, verb, group, version, resource, subresource, scope, component string, deprecated bool, removedRelease string, httpCode, respSize int, elapsed time.Duration)

MonitorRequest handles standard transformations for client and the reported verb and then invokes Monitor to record a request. verb must be uppercase to be backwards compatible with existing monitoring tooling.

func NormalizedVerb

func NormalizedVerb(req *http.Request) string

NormalizedVerb returns normalized verb

func RecordDroppedRequest

func RecordDroppedRequest(req *http.Request, requestInfo *request.RequestInfo, component string, isMutatingRequest bool)

RecordDroppedRequest records that the request was rejected via http.TooManyRequests.

func RecordFilterLatency

func RecordFilterLatency(ctx context.Context, name string, elapsed time.Duration)

func RecordLongRunning

func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, component string, fn func())

RecordLongRunning tracks the execution of a long running request against the API server. It provides an accurate count of the total number of open long running requests. requestInfo may be nil if the caller is not in the normal request flow.

func RecordRequestAbort

func RecordRequestAbort(req *http.Request, requestInfo *request.RequestInfo)

RecordRequestAbort records that the request was aborted possibly due to a timeout.

func RecordRequestPostTimeout

func RecordRequestPostTimeout(source string, status string)

func RecordRequestTermination

func RecordRequestTermination(req *http.Request, requestInfo *request.RequestInfo, component string, code int)

RecordRequestTermination records that the request was terminated early as part of a resource preservation or apiserver self-defense mechanism (e.g. timeouts, maxinflight throttling, proxyHandler errors). RecordRequestTermination should only be called zero or one times per request.

func RecordTimestampComparisonLatency

func RecordTimestampComparisonLatency(codePath string, elapsed time.Duration)

func RecordWatchListLatency

func RecordWatchListLatency(ctx context.Context, gvr schema.GroupVersionResource, metricsScope string)

RecordWatchListLatency simply records response latency for watch list requests.

func Register

func Register()

Register all metrics.

func Reset

func Reset()

Reset all metrics.

func ResetLabelAllowLists

func ResetLabelAllowLists()

ResetLabelAllowLists resets the label allow lists for all metrics. NOTE: This is only used for testing.

func UpdateInflightRequestMetrics

func UpdateInflightRequestMetrics(phase string, nonmutating, mutating int)

UpdateInflightRequestMetrics reports concurrency metrics classified by mutating vs Readonly.

Types

type ResponseWriterDelegator

type ResponseWriterDelegator struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriterDelegator interface wraps http.ResponseWriter to additionally record content-length, status-code, etc.

func (*ResponseWriterDelegator) ContentLength

func (r *ResponseWriterDelegator) ContentLength() int

func (*ResponseWriterDelegator) Status

func (r *ResponseWriterDelegator) Status() int

func (*ResponseWriterDelegator) Unwrap

func (*ResponseWriterDelegator) Write

func (r *ResponseWriterDelegator) Write(b []byte) (int, error)

func (*ResponseWriterDelegator) WriteHeader

func (r *ResponseWriterDelegator) WriteHeader(code int)

Source Files

metrics.go

Version
v0.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
21 packages
Last checked
1 hour ago

Tools for package owners.