config

package
v0.6.103 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package config is backplane's side of Live configuration (§5.2, §5.3): overrides of the Live fields of a service kept as revisions in PostgreSQL — the source of truth — and delivered to Consul KV config/<service>/, which is only the channel the SDK reads.

An override maps Live paths of the service's manifest (config.live, "greeter.suffix") to JSON values; a Live field is replaced whole, and only Live paths may be set. Saving validates the override on the effective configuration of every live instance by its schema (schemapb, CEL included), stores the next revision and writes KV in one Consul transaction with config/<service>/_revision. The reconciler keeps KV equal to PostgreSQL: at start, on a timer and on every change under config/, it rewrites what differs — a lost Consul, a replica that lagged, a manual edit in the Consul UI.

Manager is the component: the reconciler runs under its node; its API serves backplane.console.v1.ConfigService.

Index

Constants

View Source
const (
	// Root of every service's overrides.
	Root = "config/"
	// RevisionKey, under config/<service>/, is the revision of the values
	// next to it (the SDK reads it with them and never applies it).
	RevisionKey = "_revision"
)

Consul KV layout (§5.3, §17).

View Source
const (
	CodeNotLive     = "NOT_LIVE"
	CodeInvalidJSON = "INVALID_JSON"
	CodeNull        = "NULL_VALUE"
	CodeUndeclared  = "UNDECLARED"
)

Codes of violations found before the schema: the rest are schemapb's ErrorCode names without the ERROR_CODE_ prefix.

View Source
const DefaultAuthor = "admin"

DefaultAuthor is the author of a revision saved outside a console session: v0 has one operator (§11.3).

View Source
const SessionMetadata = "bp-console-session"

SessionMetadata is the gRPC metadata the console puts the operator's session in (§11.1).

Variables

View Source
var (
	ErrNotSynced  = errors.New("config: the registry has not synced with consul yet")
	ErrNoService  = errors.New("config: unknown service")
	ErrNoManifest = errors.New("config: the service has no manifest")
	ErrNoRevision = errors.New("config: no such revision")
)

Errors of saving.

View Source
var ErrInterval = errors.New("live_config.reconcile_interval must be positive")

ErrInterval: the reconcile interval is not positive.

Functions

This section is empty.

Types

type API

type API struct {
	consolev1.UnimplementedConfigServiceServer
	// contains filtered or unexported fields
}

API is the Manager as backplane.console.v1.ConfigService.

func (API) GetConfig

GetConfig implements ConfigService.

func (API) ListRevisions

ListRevisions implements ConfigService.

func (API) Rollback

Rollback implements ConfigService.

func (API) SaveRevision

SaveRevision implements ConfigService.

func (API) ValidateOverride

ValidateOverride implements ConfigService.

func (API) WatchConfig

WatchConfig implements ConfigService: the configuration now, then again whenever it differs — the registry changed (instances, manifests, applied revisions) or a revision was saved here or on another replica.

type Manager

type Manager struct {
	deps.Component
	// contains filtered or unexported fields
}

Manager keeps overrides: revisions in PostgreSQL, delivery to Consul KV, the reconciler and the console API. It holds state and goroutines: share it by pointer.

func New

func New(
	parent deps.Scope, s Settings, client *api.Client, st deps.Dependency[*store.Store], src registry.Source,
	opts ...Option,
) *Manager

New creates the component under parent: revisions in st, delivery through client, instances and manifests from src.

func (*Manager) API

func (m *Manager) API() API

API serves m to the console.

func (*Manager) Current

func (m *Manager) Current(ctx context.Context, service string) (Revision, bool, error)

Current is the service's current revision; ok is false before the first.

func (*Manager) Err

func (m *Manager) Err() error

Err is the reconciler's last error while passes keep failing; nil after a pass succeeds.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, service string, revision int64) (Revision, error)

Get is one revision of the service.

func (*Manager) Kick

func (m *Manager) Kick()

Kick asks the reconciler for a pass now.

func (*Manager) List

func (m *Manager) List(ctx context.Context, service string, before int64, size int) ([]Revision, error)

List pages through the service's revisions, newest first: at most size below before (0: from the newest).

func (*Manager) Register

func (m *Manager) Register(r grpc.ServiceRegistrar)

Register registers the API on r.

func (*Manager) Rollback

func (m *Manager) Rollback(ctx context.Context, service string, revision int64, comment string) (Saved, error)

Rollback saves the values of an older revision as the next one.

func (*Manager) Save

func (m *Manager) Save(ctx context.Context, service string, values map[string]string, comment string) (Saved, error)

Save validates the override and saves it as the service's next revision, then delivers it to Consul KV. Rejected: nothing is saved.

func (*Manager) Sync

func (m *Manager) Sync(ctx context.Context, service string) error

Sync makes config/<service>/ equal to the service's current revision: KV is read first, PostgreSQL second, and the write is conditional on _revision being what was read — a concurrent writer (another replica, a save) makes it start over.

func (*Manager) Validate

func (m *Manager) Validate(service string, values map[string]string) ([]Violation, error)

Validate checks an override (Live path -> JSON text) without saving it.

func (*Manager) View

func (m *Manager) View(ctx context.Context, service string) (*consolev1.ServiceConfig, error)

View is the service's configuration as the console shows it: the latest manifest's schema and Live paths, the current revision and every instance with a state.

type Option

type Option func(*Manager)

Option configures New.

func Author

func Author(fn func(ctx context.Context) string) Option

Author names the author of a revision from the request's context; default: the console session in SessionMetadata, else DefaultAuthor.

func WaitTime

func WaitTime(d time.Duration) Option

WaitTime bounds one blocking query on config/ (default 5m).

type Revision

type Revision struct {
	Service  string
	Revision int64
	// Values: Live path -> JSON value, as saved.
	Values map[string]json.RawMessage
	// KV: Live path -> the string delivered to Consul KV.
	KV         map[string]string
	Author     string
	Comment    string
	CreatedAt  time.Time
	RollbackOf int64 // 0: not a rollback
}

Revision is one saved override.

type Saved

type Saved struct {
	Revision    Revision
	Violations  []Violation
	DeliveryErr error
}

Saved is the outcome of a save: the revision, or the violations it was rejected with; DeliveryErr says why a saved revision is not in KV yet.

type Settings

type Settings struct {
	// How often the reconciler compares KV with PostgreSQL besides at
	// start and on KV changes.
	ReconcileInterval time.Duration `json:"reconcile_interval" schemapb:"default=30s"`
}

Settings of the configuration component: BACKPLANE_LIVE_CONFIG_*.

func (Settings) Validate

func (s Settings) Validate() error

Validate checks what the schema does not.

type Violation

type Violation struct {
	Path     string
	Instance string
	Code     string
	Message  string
}

Violation is one reason an override is rejected: at a path, on an instance's effective configuration ("" when it does not depend on one or no instance is live).

func (Violation) String

func (v Violation) String() string

Jump to

Keyboard shortcuts

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