metrics

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: Apache-2.0 Imports: 10 Imported by: 43

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"
)

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)

	// 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)

	// StartMetricsEndpoint starts the metrics endpoint at the specified address/path
	// for this metrics manager.
	// If the metricsAddress is an empty string, this will be a no op.
	StartMetricsEndpoint(metricsAddress, metricsPath string)
}

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 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 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.

Jump to

Keyboard shortcuts

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