leadership

package
v0.1.331 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag struct {
	// contains filtered or unexported fields
}

Flag is a distributed flag intended to manage leadership in a group of processes. Only one of the processes using it will see it raised at any point in time.

func (*Flag) Close

func (f *Flag) Close() error

Close releases all the resources used by the flag.

func (*Flag) Raised

func (f *Flag) Raised() bool

Raised returns true if the flag is raised. At any point in time only one of the identities will see the flag raised.

type FlagBuilder

type FlagBuilder struct {
	// contains filtered or unexported fields
}

FlagBuilder contains the data and logic needed to build leadership flags.

func NewFlag

func NewFlag() *FlagBuilder

NewFlag creates a builder that can then be used to configure and create a leadership flag.

func (*FlagBuilder) Build

func (b *FlagBuilder) Build(ctx context.Context) (result *Flag, err error)

Build uses the data stored in the builder to configure and create a new leadership flag.

func (*FlagBuilder) Handle

func (b *FlagBuilder) Handle(value *sql.DB) *FlagBuilder

Handle sets the database handle that the flag will use to store its state. This is mandatory.

func (*FlagBuilder) Interval

func (b *FlagBuilder) Interval(value time.Duration) *FlagBuilder

Interval sets the interval for renewing the ownership of the flag. The default value is thirty seconds.

func (*FlagBuilder) Jitter

func (b *FlagBuilder) Jitter(value float64) *FlagBuilder

Jitter sets a factor that will be used to randomize the intervals. For example, if this is set to 0.1 then a random adjustment of +10% or -10% will be done to the intervals each time they are used. This is intended to reduce simultaneous database accesses by processes that have been started simultaneously. The default value is 0.2.

func (*FlagBuilder) Logger

func (b *FlagBuilder) Logger(value logging.Logger) *FlagBuilder

Logger sets the logger that the flag will use to write to the log. This is mandatory.

func (*FlagBuilder) MetricsRegisterer

func (b *FlagBuilder) MetricsRegisterer(value prometheus.Registerer) *FlagBuilder

MetricsRegisterer sets the Prometheus registerer that will be used to register the metrics. The default is to use the default Prometheus registerer and there is usually no need to change that. This is intended for unit tests, where it is convenient to have a registerer that doesn't interfere with the rest of the system.

func (*FlagBuilder) MetricsSubsystem

func (b *FlagBuilder) MetricsSubsystem(value string) *FlagBuilder

MetricsSubsystem sets the name of the subsystem that will be used by the flag to register metrics with Prometheus. If this isn't explicitly specified, or if it is an empty string, then no metrics will be registered. For example, if the value is `background_tasks` then the following metrics will be registered:

tasks_leadership_flag_state - State of the flag.

The `...leadership_flag_state` metric will have the following labels:

name - Name of the flag.
process - Name of the process.

The value of the `...leaderhsip_flag_state` metric will be one if this process is currently the holder of the flag or zero if it isn't.

Note that setting this attribute is not enough to have metrics published, you also need to create and start a metrics server, as described in the documentation of the Prometheus library.

func (*FlagBuilder) Name

func (b *FlagBuilder) Name(value string) *FlagBuilder

Name of the flag. This can be used to have different flags for different uses, or for different environments that happen to share the database. This is mandatory.

func (*FlagBuilder) Process

func (b *FlagBuilder) Process(value string) *FlagBuilder

Process sets the name of the process. This should be unique amonts the set of processes using the same flag name. A typical name would be the name of a Kubernetes pod, or the combination of a Kubernets cluser name and pod name, to make it unique across different clusters. This is mandatory.

func (*FlagBuilder) Timeout

func (b *FlagBuilder) Timeout(value time.Duration) *FlagBuilder

Timeout sets the timeout for database operations. The default is on second.

Jump to

Keyboard shortcuts

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