input_data_registry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package input_data_registry holds application metrics from shoot kube-apiserver (Kapi) pods and information necessary to scrape such metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeInputDataRegistry

type FakeInputDataRegistry struct {
	HasNoCACertificate               bool
	Watcher                          *KapiWatcher
	ShouldWatcherNotifyOfPreexisting bool

	MinSampleGap time.Duration
	// contains filtered or unexported fields
}

func (*FakeInputDataRegistry) AddKapiWatcher

func (fidr *FakeInputDataRegistry) AddKapiWatcher(watcher *KapiWatcher, shouldNotifyOfPreexisting bool)

func (*FakeInputDataRegistry) DataSource

func (fidr *FakeInputDataRegistry) DataSource() InputDataSource

func (*FakeInputDataRegistry) GetKapiData

func (fidr *FakeInputDataRegistry) GetKapiData(shootNamespace string, podName string) *KapiData

func (*FakeInputDataRegistry) GetKapis

func (fidr *FakeInputDataRegistry) GetKapis() []*KapiData

func (*FakeInputDataRegistry) GetShootAuthSecret

func (fidr *FakeInputDataRegistry) GetShootAuthSecret(_ string) string

func (*FakeInputDataRegistry) GetShootCACertificate

func (fidr *FakeInputDataRegistry) GetShootCACertificate(_ string) *x509.CertPool

func (*FakeInputDataRegistry) NotifyKapiMetricsFault

func (fidr *FakeInputDataRegistry) NotifyKapiMetricsFault(_ string, _ string) int

func (*FakeInputDataRegistry) RemoveKapiData

func (fidr *FakeInputDataRegistry) RemoveKapiData(shootNamespace string, podName string) bool

func (*FakeInputDataRegistry) RemoveKapiWatcher

func (fidr *FakeInputDataRegistry) RemoveKapiWatcher(*KapiWatcher) bool

func (*FakeInputDataRegistry) RemoveShootAuthSecret

func (fidr *FakeInputDataRegistry) RemoveShootAuthSecret()

func (*FakeInputDataRegistry) SetKapiData

func (fidr *FakeInputDataRegistry) SetKapiData(
	shootNamespace string, podName string, uid types.UID, podLabels map[string]string, metricsUrl string)

func (*FakeInputDataRegistry) SetKapiLastScrapeTime

func (fidr *FakeInputDataRegistry) SetKapiLastScrapeTime(shootNamespace string, podName string, value time.Time)

func (*FakeInputDataRegistry) SetKapiMetrics

func (fidr *FakeInputDataRegistry) SetKapiMetrics(shootNamespace string, podName string, currentTotalRequestCount int64)

func (*FakeInputDataRegistry) SetKapiMetricsWithTime

func (fidr *FakeInputDataRegistry) SetKapiMetricsWithTime(
	shootNamespace string, podName string, currentTotalRequestCount int64, metricsTime time.Time)

func (*FakeInputDataRegistry) SetKapis

func (fidr *FakeInputDataRegistry) SetKapis(kapis []*KapiData)

func (*FakeInputDataRegistry) SetShootAuthSecret

func (fidr *FakeInputDataRegistry) SetShootAuthSecret(_ string, _ string)

func (*FakeInputDataRegistry) SetShootCACertificate

func (fidr *FakeInputDataRegistry) SetShootCACertificate(_ string, _ []byte)

type InputDataRegistry

type InputDataRegistry interface {
	// DataSource returns an InputDataSource interface to the registry, which is focused on metrics consumption, and
	// abstracts other details away.
	DataSource() InputDataSource
	// GetKapiData returns a KapiData object which contains the registry's information, specific to the Kapi pod identified
	// by shootNamespace and podName.
	// The output is a deep copy, and fully detached from the registry. If the registry has no information about the
	// specified pod, nil is returned.
	GetKapiData(shootNamespace string, podName string) *KapiData
	// SetKapiData stores registry data specific to the k8s Kapi pod object identified by shootNamespace and podName.
	SetKapiData(
		shootNamespace string, podName string, podUID types.UID, podLabels map[string]string, metricsUrl string)
	// RemoveKapiData deletes all registry data specific to the Kapi pod identified by shootNamespace and podName.
	// The output value is false if the registry did not contain data for the identified pod.
	RemoveKapiData(shootNamespace string, podName string) bool
	// SetKapiMetrics records the current metrics value for the Kapi pod identified by shootNamespace and podName.
	// If the registry does not contain a record for the specified pod, the operation has no effect.
	SetKapiMetrics(shootNamespace string, podName string, currentTotalRequestCount int64)
	// SetKapiLastScrapeTime records the start time of the last scrape for the Kapi pod identified by shootNamespace and podName.
	// If the registry does not contain a record for the specified pod, the operation has no effect.
	SetKapiLastScrapeTime(shootNamespace string, podName string, value time.Time)
	// NotifyKapiMetricsFault is the counterpart of SetKapiMetrics which is used when a metrics scrape fails. Instead of
	// recording the newly obtained metrics values, it records the fact that values could not be obtained.
	// If the registry does not contain a record for the specified pod, the operation has no effect.
	//
	// The function returns the number of consecutive faults on record, including the one reflected by this call.
	// Returns -1 if the registry currently does not maintain a record for the specified pod.
	NotifyKapiMetricsFault(shootNamespace string, podName string) int
	// GetShootAuthSecret retrieves the authentication secret used to access Kapi metrics on the shoot identified by shootNamespace.
	// Returns empty string if there is no auth secret on record for that shoot.
	GetShootAuthSecret(shootNamespace string) string
	// SetShootAuthSecret records the specified authentication secret for the shoot identified by ShootNamespace, so it can
	// later be retrieved via GetShootAuthSecret(). Passing authSecret="" deletes the record, if one exists.
	SetShootAuthSecret(shootNamespace string, authSecret string)
	// GetShootCACertificate retrieves the Kapi CA certificate registered for the shoot identified by shootNamespace.
	// Returns nil if a CA cert is not registered for the shoot. The result is in the form of a CertPool, containing
	// only the shoot's CA certificate. Callers should not modify the returned object.
	GetShootCACertificate(shootNamespace string) *x509.CertPool
	// SetShootCACertificate records the specified certificate as the CA certificate for the Kapi of the shoot identified by
	// shootNamespace, so it can later be retrieved via GetShootCACertificate(). Passing certificate=nil deletes the record,
	// if one exists.
	SetShootCACertificate(shootNamespace string, certificate []byte)
	// AddKapiWatcher subscribes an event handler which gets called when there is a change in the ShootKapi objects on
	// record in the registry.
	// If shouldNotifyOfPreexisting is true, a KapiEventCreate event will be delivered to the watcher for each ShootKapi
	// which is already in the registry at the time of the call. If false, the watcher will only be notified of subsequent
	// changes.
	//
	// IMPORTANT:
	// If a goroutine exists which could hold a given lock while calling a method on a given InputDataRegistry instance,
	// then it is illegal for any KapiWatcher registered on that instance to block, even indirectly, on that same lock.
	// The KapiWatcher is still allowed to e.g. create a separate goroutine which blocks in the lock, as long as it doesn't
	// block waiting on the goroutine.
	AddKapiWatcher(watcher *KapiWatcher, shouldNotifyOfPreexisting bool)
	// RemoveKapiWatcher removes the event watcher, registered by a prior AddKapiWatcher call.
	// The watcher pointer must have the same value as the one provided to said AddKapiWatcher() call.
	// Returns false, if the specified watcher has never been added to the registry, or was already removed.
	RemoveKapiWatcher(watcher *KapiWatcher) bool
}

InputDataRegistry abstracts the inputDataRegistry type, so it can be replaced for testing isolation purposes.

func NewInputDataRegistry

func NewInputDataRegistry(minSampleGap time.Duration, log logr.Logger) InputDataRegistry

NewInputDataRegistry creates a new InputDataRegistry object

type InputDataSource

type InputDataSource interface {
	// GetShootKapis lists the known Kapi pods for the shoot identified by shootNamespace. Returns nil if the shoot
	// is unknown to InputDataSource at the time of the call.
	GetShootKapis(shootNamespace string) []ShootKapi

	// AddKapiWatcher subscribes an event handler which gets called when there is a change in the ShootKapi objects on
	// record in the InputDataSource.
	// If shouldNotifyOfPreexisting is true, a KapiEventCreate event will be delivered to the watcher for each ShootKapi
	// which is already in the InputDataSource at the time of the call. If false, the watcher will only be notified of
	// future changes.
	//
	// IMPORTANT:
	// If a goroutine exists which could hold a given lock while calling a method on a given InputDataSource instance,
	// then it is illegal for any KapiWatcher registered on that instance to block, even indirectly, on that same lock.
	// The KapiWatcher is still allowed to e.g. create a separate goroutine which blocks in the lock, as long as it
	// doesn't block waiting on the goroutine.
	AddKapiWatcher(watcher *KapiWatcher, shouldNotifyOfPreexisting bool)

	// RemoveKapiWatcher removes the event watcher, registered by a prior AddKapiWatcher call.
	// The watcher pointer must have the same value as the one provided to said AddKapiWatcher() call.
	// Returns false, if the specified watcher has never been added to the InputDataSource, or was already removed.
	RemoveKapiWatcher(watcher *KapiWatcher) bool
}

InputDataSource provides kube-apiserver application metrics data. The scope of one instance is multiple shoots on the same seed. All operations are concurrency-safe.

type KapiData

type KapiData struct {
	PodLabels             map[string]string // The K8s labels on the pod object
	MetricsUrl            string            // The URL where metrics for the pod can be scraped
	TotalRequestCountNew  int64             // Most recent value for the number of Kapi requests to this pod, since the pod started.
	MetricsTimeNew        time.Time         // The point in time to which TotalRequestCountNew refers. Zero when the metrics sample is unavailable.
	TotalRequestCountOld  int64             // The previous value of TotalRequestCountNew. Enables rate-of-change calculations.
	MetricsTimeOld        time.Time         // The point in time to which TotalRequestCountOld refers. Zero when the metrics sample is unavailable.
	PodUID                types.UID
	LastMetricsScrapeTime time.Time // The start time of the most recent metrics scrape for the Kapi.
	FaultCount            int       // Number of consecutive failed attempt to obtain metrics for this pod. Reset to zero upon success.
	// contains filtered or unexported fields
}

KapiData holds all registry information for a single kube-apiserver pod

func (*KapiData) Copy

func (kapi *KapiData) Copy() *KapiData

Copy returns a deep copy.

func (*KapiData) PodName

func (kapi *KapiData) PodName() string

PodName and ShootNamespace jointly identify the KapiData

func (*KapiData) ShootNamespace

func (kapi *KapiData) ShootNamespace() string

ShootNamespace and PodName jointly identify the KapiData

type KapiEventType

type KapiEventType int

KapiEventType classifies the events on ShootKapi objects, for which a notification can be exchanged.

const (
	KapiEventCreate KapiEventType = iota // KapiEventCreate indicates that a ShootKapi was added.
	KapiEventDelete                      // KapiEventDelete indicates that the ShootKapi is about to be removed.
)

type KapiWatcher

type KapiWatcher func(kapi ShootKapi, event KapiEventType)

KapiWatcher is the type of event handlers subscribing to receive ShootKapi events from an InputDataSource. The kapi parameter may point to the actual memory backing the InputDataSource. It is illegal to modify the object or access it after the event handler has returned. See also: KapiEventType.

type ShootKapi

type ShootKapi interface {
	ShootNamespace() string       // ShootNamespace and PodName are immutable and together serve as ID
	PodName() string              // ShootNamespace and PodName are immutable and together serve as ID
	PodLabels() map[string]string // The K8s labels on the pod object
	TotalRequestCountNew() int64  // Most recent value for the number of Kapi requests to this pod, since the pod started.
	TotalRequestCountOld() int64  // The previous value of TotalRequestCountNew. Enables rate-of-change calculations.
	MetricsTimeNew() time.Time    // The point in time to which TotalRequestCountNew refers. Zero when the metrics sample is unavailable.
	MetricsTimeOld() time.Time    // The point in time to which TotalRequestCountOld refers. Zero when the metrics sample is unavailable.
	PodUID() types.UID
}

ShootKapi contains metrics for a single kube-apiserver pod

Jump to

Keyboard shortcuts

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