state

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 11 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

	TelemetryLocked bool      `json:"-"`
	Start           time.Time `json:"-"`

	// may be empty if FerretDB did not connect to the backend yet
	BackendName    string `json:"-"`
	BackendVersion string `json:"-"`

	// as reported by beacon, if known
	LatestVersion   string `json:"-"`
	UpdateInfo      string `json:"-"`
	UpdateAvailable bool   `json:"-"`
}

State represents FerretDB process state.

func (*State) DisableTelemetry added in v1.2.1

func (s *State) DisableTelemetry()

DisableTelemetry disables telemetry.

It also resets other telemetry fields to avoid stale values when telemetry is re-enabled.

func (*State) EnableTelemetry added in v1.2.1

func (s *State) EnableTelemetry()

EnableTelemetry enables telemetry.

func (*State) TelemetryString added in v0.9.2

func (s *State) TelemetryString() string

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

Jump to

Keyboard shortcuts

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