configstore

package
v0.22.14 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package configstore abstracts the concepts of where instance files get retrieved.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConnected = fmt.Errorf("not connected to store")

ErrNotConnected is used when a store operation was called but no connection to the store was active.

Functions

func GetCodec

func GetCodec() codec.Codec

GetCodec returns the codec for encoding and decoding instance.Configs in the Remote store.

Types

type API

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

API is an HTTP API to interact with a configstore.

func NewAPI

func NewAPI(l log.Logger, store Store, v Validator, enableGet bool) *API

NewAPI creates a new API. Store can be applied later with SetStore.

func (*API) Collect

func (api *API) Collect(mm chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*API) DeleteConfiguration

func (api *API) DeleteConfiguration(rw http.ResponseWriter, r *http.Request)

DeleteConfiguration deletes a configuration.

func (*API) Describe

func (api *API) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*API) GetConfiguration

func (api *API) GetConfiguration(rw http.ResponseWriter, r *http.Request)

GetConfiguration gets an individual configuration.

func (*API) ListConfigurations

func (api *API) ListConfigurations(rw http.ResponseWriter, r *http.Request)

ListConfigurations returns a list of configurations.

func (*API) PutConfiguration

func (api *API) PutConfiguration(rw http.ResponseWriter, r *http.Request)

PutConfiguration creates or updates a configuration.

func (*API) WireAPI

func (api *API) WireAPI(r *mux.Router)

WireAPI injects routes into the provided mux router for the config store API.

type Mock

type Mock struct {
	ListFunc   func(ctx context.Context) ([]string, error)
	GetFunc    func(ctx context.Context, key string) (instance.Config, error)
	PutFunc    func(ctx context.Context, c instance.Config) (created bool, err error)
	DeleteFunc func(ctx context.Context, key string) error
	AllFunc    func(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)
	WatchFunc  func() <-chan WatchEvent
	CloseFunc  func() error
}

Mock is a Mock Store. Useful primarily for testing.

func (*Mock) All

func (s *Mock) All(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)

All implements Store.

func (*Mock) Close

func (s *Mock) Close() error

Close implements Store.

func (*Mock) Delete

func (s *Mock) Delete(ctx context.Context, key string) error

Delete implements Store.

func (*Mock) Get

func (s *Mock) Get(ctx context.Context, key string) (instance.Config, error)

Get implements Store.

func (*Mock) List

func (s *Mock) List(ctx context.Context) ([]string, error)

List implements Store.

func (*Mock) Put

func (s *Mock) Put(ctx context.Context, c instance.Config) (created bool, err error)

Put implements Store.

func (*Mock) Watch

func (s *Mock) Watch() <-chan WatchEvent

Watch implements Store.

type NotExistError

type NotExistError struct {
	Key string
}

NotExistError is used when a config doesn't exist.

func (NotExistError) Error

func (e NotExistError) Error() string

Error implements error.

type NotUniqueError

type NotUniqueError struct {
	ScrapeJob string
}

NotUniqueError is used when two scrape jobs have the same name.

func (NotUniqueError) Error

func (e NotUniqueError) Error() string

Error implements error.

type Remote

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

Remote loads instance files from a remote KV store. The KV store can be swapped out in real time.

func NewRemote

func NewRemote(l log.Logger, reg prometheus.Registerer, cfg kv.Config, enable bool) (*Remote, error)

NewRemote creates a new Remote store that uses a Key-Value client to store and retrieve configs. If enable is true, the store will be immediately connected to. Otherwise, it can be lazily loaded by enabling later through a call to Remote.ApplyConfig.

func (*Remote) All

func (r *Remote) All(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)

All retrieves the set of all configs in the store.

func (*Remote) ApplyConfig

func (r *Remote) ApplyConfig(cfg kv.Config, enable bool) error

ApplyConfig applies the config for a kv client.

func (*Remote) Close

func (r *Remote) Close() error

Close closes the Remote store.

func (*Remote) Delete

func (r *Remote) Delete(ctx context.Context, key string) error

Delete deletes a config from the KV store. It returns NotExistError if the config doesn't exist.

func (*Remote) Get

func (r *Remote) Get(ctx context.Context, key string) (instance.Config, error)

Get retrieves an individual config from the KV store.

func (*Remote) List

func (r *Remote) List(ctx context.Context) ([]string, error)

List returns the list of all configs in the KV store.

func (*Remote) Put

func (r *Remote) Put(ctx context.Context, c instance.Config) (bool, error)

Put adds or updates a config in the KV store.

func (*Remote) Watch

func (r *Remote) Watch() <-chan WatchEvent

Watch watches the Store for changes.

type Store

type Store interface {
	// List gets the list of config names.
	List(ctx context.Context) ([]string, error)

	// Get gets an individual config by name.
	Get(ctx context.Context, key string) (instance.Config, error)

	// Put applies a new instance Config to the store.
	// If the config already exists, created will be false to indicate an
	// update.
	Put(ctx context.Context, c instance.Config) (created bool, err error)

	// Delete deletes a config from the store.
	Delete(ctx context.Context, key string) error

	// All retrieves the entire list of instance configs currently
	// in the store. A filtering "keep" function can be provided to ignore some
	// configs, which can significantly speed up the operation in some cases.
	All(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)

	// Watch watches for changed instance Configs.
	// All callers of Watch receive the same Channel.
	//
	// It is not guaranteed that Watch will emit all store events, and Watch
	// should only be used for best-effort quick convergence with the remote
	// store. Watch should always be paired with polling All.
	Watch() <-chan WatchEvent

	// Close closes the store.
	Close() error
}

Store is some interface to retrieving instance configurations.

type Validator

type Validator = func(c *instance.Config) error

Validator valides a config before putting it into the store. Validator is allowed to mutate the config and will only be given a copy.

type WatchEvent

type WatchEvent struct {
	Key    string
	Config *instance.Config
}

WatchEvent is returned by Watch. The Key is the name of the config that was added, updated, or deleted. If the Config was deleted, Config will be nil.

Jump to

Keyboard shortcuts

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