metrics

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 10 Imported by: 26

Documentation

Index

Constants

View Source
const (
	// SubsystemSidecar is the default subsystem name in a metrics
	// (= the prefix in the final metrics name). It is to be used
	// by CSI sidecars. Using the same subsystem in different CSI
	// drivers makes it possible to reuse dashboards because
	// the metrics names will be identical. Data from different
	// drivers can be selected via the "driver_name" tag.
	SubsystemSidecar = "csi_sidecar"
	// SubsystemPlugin is what CSI driver's should use as
	// subsystem name.
	SubsystemPlugin = "csi_plugin"

	// LabelMigrated is the Label that indicate whether this is a CSI migration operation
	LabelMigrated = "migrated"
)

Variables

View Source
var NewCSIMetricsManager = NewCSIMetricsManagerForSidecar

NewCSIMetricsManager is provided for backwards-compatibility.

Functions

func VerifyMetricsMatch

func VerifyMetricsMatch(expectedMetrics, actualMetrics string, metricToIgnore string) error

VerifyMetricsMatch is a helper function that verifies that the expected and actual metrics are identical excluding metricToIgnore. This method is only used by tests. Ideally it should be in the _test file, but *_test.go files are compiled into the package only when running go test for that package and this method is used by metrics_test as well as connection_test. If there are more consumers in the future, we can consider moving it to a new, standalone package.

Types

type CSIMetricsManager

type CSIMetricsManager interface {
	// GetRegistry() returns the metrics.KubeRegistry used by this metrics manager.
	GetRegistry() metrics.KubeRegistry

	// RecordMetrics must be called upon CSI Operation completion to record
	// the operation's metric.
	// operationName - Name of the CSI operation.
	// operationErr - Error, if any, that resulted from execution of operation.
	// operationDuration - time it took for the operation to complete
	//
	// If WithLabelNames was used to define additional labels when constructing
	// the manager, then WithLabelValues should be used to create a wrapper which
	// holds the corresponding values before calling RecordMetrics of the wrapper.
	// Labels with missing values are recorded as empty.
	RecordMetrics(
		operationName string,
		operationErr error,
		operationDuration time.Duration)

	// WithLabelValues must be used to add the additional label
	// values defined via WithLabelNames. When calling RecordMetrics
	// without it or with too few values, the missing values are
	// recorded as empty. WithLabelValues can be called multiple times
	// and then accumulates values.
	WithLabelValues(labels map[string]string) (CSIMetricsManager, error)

	// HaveAdditionalLabel can be used to check if the additional label
	// value is defined in the metrics manager
	HaveAdditionalLabel(name string) bool

	// SetDriverName is called to update the CSI driver name. This should be done
	// as soon as possible, otherwise metrics recorded by this manager will be
	// recorded with an "unknown-driver" driver_name.
	// driverName - Name of the CSI driver against which this operation was executed.
	SetDriverName(driverName string)

	// RegisterToServer registers an HTTP handler for this metrics manager to the
	// given server at the specified address/path.
	RegisterToServer(s Server, metricsPath string)

	// RegisterPprofToServer registers the HTTP handlers necessary to enable pprof
	// for this metrics manager to the given server at the usual path.
	// This function is not needed when using DefaultServeMux as the Server since
	// the handlers will automatically be registered when importing pprof.
	RegisterPprofToServer(s Server)
}

CSIMetricsManager exposes functions for recording metrics for CSI operations.

func NewCSIMetricsManagerForPlugin added in v0.8.0

func NewCSIMetricsManagerForPlugin(driverName string) CSIMetricsManager

NewCSIMetricsManagerForPlugin creates and registers metrics for CSI drivers and returns an object that can be used to trigger the metrics. It uses "csi_plugin" as subsystem.

driverName - Name of the CSI driver against which this operation was executed.

If unknown, leave empty, and use SetDriverName method to update later.

func NewCSIMetricsManagerForSidecar added in v0.8.0

func NewCSIMetricsManagerForSidecar(driverName string) CSIMetricsManager

NewCSIMetricsManagerForSidecar creates and registers metrics for CSI Sidecars and returns an object that can be used to trigger the metrics. It uses "csi_sidecar" as subsystem.

driverName - Name of the CSI driver against which this operation was executed.

If unknown, leave empty, and use SetDriverName method to update later.

func NewCSIMetricsManagerWithOptions added in v0.8.0

func NewCSIMetricsManagerWithOptions(driverName string, options ...MetricsManagerOption) CSIMetricsManager

NewCSIMetricsManagerWithOptions is a customizable constructor, to be used only if there are special needs like changing the default subsystems.

driverName - Name of the CSI driver against which this operation was executed.

If unknown, leave empty, and use SetDriverName method to update later.

type MetricsManagerOption added in v0.8.0

type MetricsManagerOption func(*csiMetricsManager)

MetricsManagerOption is used to pass optional configuration to a new metrics manager.

func WithCustomRegistry added in v0.12.0

func WithCustomRegistry(registry metrics.KubeRegistry) MetricsManagerOption

WithCustomRegistry allow user to use custom pre-created registry instead of a new created one.

func WithLabelNames added in v0.8.0

func WithLabelNames(labelNames ...string) MetricsManagerOption

WithLabelNames defines labels for each sample that get added to the default labels (driver, method call, and gRPC result). This makes it possible to partition the histograms along additional dimensions.

To record a metrics with additional values, use CSIMetricManager.WithLabelValues().RecordMetrics().

func WithLabels added in v0.8.0

func WithLabels(labels map[string]string) MetricsManagerOption

WithLabels defines some label name and value pairs that are added to all samples. They get recorded sorted by name.

func WithMigration added in v0.9.1

func WithMigration() MetricsManagerOption

WithMigration adds the migrated field to the current metrics label

func WithProcessStartTime added in v0.9.0

func WithProcessStartTime(registerProcessStartTime bool) MetricsManagerOption

WithProcessStartTime controlls whether process_start_time_seconds is registered in the registry of the metrics manager. It's enabled by default out of convenience (no need to do anything special in most sidecars) but should be disabled in more complex scenarios (more than one metrics manager per process, metric already provided elsewhere like via the Prometheus Golang collector).

In particular, registering this metric via metric manager and thus the Kubernetes component base conflicts with the Prometheus Golang collector (gathered metric family process_start_time_seconds has help "[ALPHA] Start time of the process since unix epoch in seconds." but should have "Start time of the process since unix epoch in seconds."

func WithStabilityLevel added in v0.8.0

func WithStabilityLevel(stabilityLevel metrics.StabilityLevel) MetricsManagerOption

WithStabilityLevel overrides the default stability level. The recommended usage is to keep metrics at a lower level when csi-lib-utils switches to beta or GA. Overriding the alpha default with beta or GA is risky because the metrics can still change in the library.

func WithSubsystem added in v0.8.0

func WithSubsystem(subsystem string) MetricsManagerOption

WithSubsystem overrides the default subsystem name.

type Server added in v0.9.0

type Server interface {
	Handle(pattern string, handler http.Handler)
}

Server represents any type that could serve HTTP requests for the metrics endpoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL