metrics

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Overview

Package metrics provides metrics support shared among all packages in this Go module:

- the metrics registry - exporting metrics via HTTP - common metrics

It does NOT include code that is specific to other packages of this module.

Global State

The API of this packages makes use of global state to get access to instances so that keeping and passing references is not necessary. For non-test use cases this perfectly fits to the global nature of metric support.

For testing it may be required to let SUTs use test doubles instead of the original global instances of this package. This can be achieved by patching the global state of this package during test setup and reverting the patch at test teardown. Be aware that tests patching global state must not run concurrently to other tests to avoid interference. See the Testing type for test support.

Index

Constants

View Source
const (
	// Subsystem is the subsystem name of Steward to be used
	// as part of metric names.
	Subsystem = "steward"
)

Variables

This section is empty.

Functions

func CodeLocation added in v0.15.0

func CodeLocation(skip uint16) string

CodeLocation returns a string representation of the caller's code location. `skip` is the number of call stack frames to skip.

func Registerer added in v0.15.0

func Registerer() prometheus.Registerer

Registerer returns the registerer for metrics that should be exported by the metrics server

func StartServer added in v0.15.0

func StartServer(port uint16)

StartServer starts the HTTP server providing the metrics for scraping.

Types

type RetriesMetric added in v0.15.0

type RetriesMetric interface {
	// Observe performs a single observation of a finished retry loop.
	// codeLocation is a string representation of the code location
	// of the retry loop.
	// retryCount is the number of retries performed, where the very
	// first attempt is not counted as retry.
	// latency is the elapsed time from the start of the retry loop
	// until is has been finished.
	Observe(codeLocation string, retryCount uint64, latency time.Duration)
}

RetriesMetric observes finished retried operations.

var (
	// Retries observes finished retried operations.
	Retries RetriesMetric = &retriesMetric{}
)

type Testing added in v0.15.0

type Testing struct{}

Testing provides utility functions for testing with this package. Do not use it for non-testing purposes!

func (Testing) PatchRegistry added in v0.15.0

func (Testing) PatchRegistry(replacement *prometheus.Registry) func()

PatchRegistry replaces the internal Prometheus metrics registry with a replacement and returns a function that reverts the patch. Multiple nested replacements must be reverted in exactly the opposite order (revert last replacement first).

Directories

Path Synopsis
Package k8srestclient embeds metrics exposed by package k8s.io/client-go/rest.
Package k8srestclient embeds metrics exposed by package k8s.io/client-go/rest.
Package workqueue embeds metrics exposed by package k8s.io/client-go/util/workqueue.
Package workqueue embeds metrics exposed by package k8s.io/client-go/util/workqueue.

Jump to

Keyboard shortcuts

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