backupstats

package
v0.15.8 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package backupstats provides a Stats interface for backup and restore operations in the mysqlctl package.

The goal is to provide a consistent reporting interface that can be used by any BackupEngine, BackupStorage, or FileHandle component, so that those components don't have to register their own stats or reference global variables.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DeprecatedBackupDurationS is a deprecated statistic that will be removed
	// in the next release. Use backup_duration_nanoseconds instead.
	DeprecatedBackupDurationS = stats.NewGauge(
		"backup_duration_seconds",
		"[DEPRECATED] How long it took to complete the last backup operation (in seconds)",
	)

	// DeprecatedRestoreDurationS is a deprecated statistic that will be
	// removed in the next release. Use restore_duration_nanoseconds instead.
	DeprecatedRestoreDurationS = stats.NewGauge(
		"restore_duration_seconds",
		"[DEPRECATED] How long it took to complete the last restore operation (in seconds)",
	)
)

Functions

This section is empty.

Types

type ComponentType

type ComponentType int

ComponentType is used to scope Stats. E.g. stats.Scope(Component(BackupEngine)).

const (
	BackupEngine ComponentType = iota
	BackupStorage
)

func (ComponentType) String

func (c ComponentType) String() string

type FakeStats

type FakeStats struct {
	ScopeV                   map[ScopeType]ScopeValue
	TimedIncrementCalls      []time.Duration
	TimedIncrementBytesCalls []struct {
		Bytes    int
		Duration time.Duration
	}
	ScopeCalls   [][]Scope
	ScopeReturns []*FakeStats
	// contains filtered or unexported fields
}

func NewFakeStats

func NewFakeStats(scopes ...Scope) *FakeStats

func (*FakeStats) Scope

func (fs *FakeStats) Scope(scopes ...Scope) Stats

Scope returns a new FakeStats with scopes merged from the current FakeStats' scopes and provided scopes. It also records the return value in ScopeReturns, for use in unit test assertions.

func (*FakeStats) TimedIncrement

func (fs *FakeStats) TimedIncrement(d time.Duration)

TimedIncrement does nothing except record calls made to this function in TimedIncrementCalls, for use in unit test assertions.

func (*FakeStats) TimedIncrementBytes

func (fs *FakeStats) TimedIncrementBytes(b int, d time.Duration)

TimedIncrementBytes does nothing except record calls made to this function in TimedIncrementBytesCalls, for use in unit test assertions.

type Scope

type Scope struct {
	Type  ScopeType
	Value ScopeValue
}

Scope is used to specify the scope of Stats. In this way the same Stats can be passed down to different layers and components of backup and restore operations, while allowing each component to emit stats without overwriting the stats of other components.

func Component

func Component(c ComponentType) Scope

func Implementation

func Implementation(v ScopeValue) Scope

func Operation

func Operation(v ScopeValue) Scope

type ScopeType

type ScopeType int

ScopeType is used to specify the type of scope being set.

const (
	// ScopeComponent is used to specify the type of component, such as
	// "BackupEngine" or "BackupStorage".
	ScopeComponent ScopeType = iota
	// ScopeImplementation is used to specify the specific component, such as
	// "Builtin" and "XtraBackup" in the case of a "BackupEngine" componenet.
	ScopeImplementation
	// ScopeOperation is used to specify the type of operation. Examples of
	// high-level operations are "Backup" and "Restore", and examples of
	// low-level operations like "Read" and "Write".
	ScopeOperation
)

type ScopeValue

type ScopeValue = string

ScopeValue is used to specify the value of the scope being set.

type Stats

type Stats interface {
	// Scope creates a new Stats which inherits this Stats' scopes plus any
	// new provided scopes.
	//
	// Once a ScopeType has been set in a Stats, it cannot be changed by
	// further calls to Scope().
	//
	// This allows parent components to prepare properly scoped Stats and pass
	// them to child components in such a way that child components cannot
	// overwrite another components' metrics.
	Scope(...Scope) Stats
	// Increment count by 1 and increase duration.
	TimedIncrement(time.Duration)
	// Increment bytes and increase duration.
	TimedIncrementBytes(int, time.Duration)
}

Stats is a reporting interface meant to be shared among backup and restore components.

This interface is meant to give those components a way to report stats without having to register their own stats or to import globally registered stats. This way out-of-tree plugins can have a mechanism for reporting stats, while the policies for those stats (metric names and labels, stat sinks) remain in the control of in-tree Vitess code and Vitess users.

func BackupStats

func BackupStats() Stats

BackupStats creates a new Stats for backup operations.

It registers the following metrics with the Vitess stats package.

  • BackupBytes: number of bytes processed by an an operation for given component and implementation.
  • BackupCount: number of times an operation has happened for given component and implementation.
  • BackupDurationNanoseconds: time spent on an operation for a given component and implementation.

func NoStats

func NoStats() Stats

NoStats returns a no-op Stats suitable for tests and for backwards compoatibility.

func RestoreStats

func RestoreStats() Stats

RestoreStats creates a new Stats for restore operations.

It registers the following metrics with the Vitess stats package.

  • RestoreBytes: number of bytes processed by an an operation for given component and implementation.
  • RestoreCount: number of times an operation has happened for given component and implementation.
  • RestoreDurationNanoseconds: time spent on an operation for a given component and implementation.

Jump to

Keyboard shortcuts

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