state

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package state stores FerretDB process state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

Provider provides access to FerretDB process state.

func NewProvider

func NewProvider(filename string) (*Provider, error)

NewProvider creates a new Provider that stores state in the given file.

If filename is empty, then the state is not persisted.

All provider's methods are thread-safe.

func (*Provider) Get

func (p *Provider) Get() *State

Get returns a copy of the current process state.

It is okay to call this function often. The caller should not cache result; Provider does everything needed itself.

func (*Provider) MetricsCollector

func (p *Provider) MetricsCollector(addUUIDToMetric bool) prometheus.Collector

MetricsCollector returns Prometheus metrics collector for that provider.

If addUUIDToMetric is true, then the UUID is added to the Prometheus metric.

func (*Provider) Subscribe

func (p *Provider) Subscribe() chan struct{}

Subscribe returns a channel that would receive notifications on state changes. One notification would be scheduled immediately.

func (*Provider) Update

func (p *Provider) Update(update func(s *State)) error

Update gets the current state, calls the given function, updates state, and notifies all subscribers.

type State

type State struct {
	UUID      string `json:"uuid"`
	Telemetry *bool  `json:"telemetry,omitempty"` // nil for undecided

	// never persisted
	TelemetryLocked bool      `json:"-"`
	Start           time.Time `json:"-"`
	LatestVersion   string    `json:"-"` // may be empty
	HandlerVersion  string    `json:"-"` // may be empty
}

State represents FerretDB process state.

func (*State) TelemetryString added in v0.9.2

func (s *State) TelemetryString() string

TelemetryString returns "enabled", "disabled" or "undecided".

func (*State) UpdateAvailable added in v0.9.2

func (s *State) UpdateAvailable() bool

UpdateAvailable returns true if there is a newer version available.

Jump to

Keyboard shortcuts

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