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
- Variables
- type API
- func (a API) GetConfig(ctx context.Context, req *consolev1.GetConfigRequest) (*consolev1.GetConfigResponse, error)
- func (a API) ListRevisions(ctx context.Context, req *consolev1.ListRevisionsRequest) (*consolev1.ListRevisionsResponse, error)
- func (a API) Rollback(ctx context.Context, req *consolev1.RollbackRequest) (*consolev1.RollbackResponse, error)
- func (a API) SaveRevision(ctx context.Context, req *consolev1.SaveRevisionRequest) (*consolev1.SaveRevisionResponse, error)
- func (a API) ValidateOverride(_ context.Context, req *consolev1.ValidateOverrideRequest) (*consolev1.ValidateOverrideResponse, error)
- func (a API) WatchConfig(req *consolev1.WatchConfigRequest, ...) error
- type Manager
- func (m *Manager) API() API
- func (m *Manager) Current(ctx context.Context, service string) (Revision, bool, error)
- func (m *Manager) Err() error
- func (m *Manager) Get(ctx context.Context, service string, revision int64) (Revision, error)
- func (m *Manager) Kick()
- func (m *Manager) List(ctx context.Context, service string, before int64, size int) ([]Revision, error)
- func (m *Manager) Register(r grpc.ServiceRegistrar)
- func (m *Manager) Rollback(ctx context.Context, service string, revision int64, comment string) (Saved, error)
- func (m *Manager) Save(ctx context.Context, service string, values map[string]string, comment string) (Saved, error)
- func (m *Manager) Sync(ctx context.Context, service string) error
- func (m *Manager) Validate(service string, values map[string]string) ([]Violation, error)
- func (m *Manager) View(ctx context.Context, service string) (*consolev1.ServiceConfig, error)
- type Option
- type Revision
- type Saved
- type Settings
- type Violation
Constants ¶
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).
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.
const DefaultAuthor = "admin"
DefaultAuthor is the author of a revision saved outside a console session: v0 has one operator (§11.3).
const SessionMetadata = "bp-console-session"
SessionMetadata is the gRPC metadata the console puts the operator's session in (§11.1).
Variables ¶
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.
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 ¶
func (a API) GetConfig(ctx context.Context, req *consolev1.GetConfigRequest) (*consolev1.GetConfigResponse, error)
GetConfig implements ConfigService.
func (API) ListRevisions ¶
func (a API) ListRevisions( ctx context.Context, req *consolev1.ListRevisionsRequest, ) (*consolev1.ListRevisionsResponse, error)
ListRevisions implements ConfigService.
func (API) Rollback ¶
func (a API) Rollback(ctx context.Context, req *consolev1.RollbackRequest) (*consolev1.RollbackResponse, error)
Rollback implements ConfigService.
func (API) SaveRevision ¶
func (a API) SaveRevision( ctx context.Context, req *consolev1.SaveRevisionRequest, ) (*consolev1.SaveRevisionResponse, error)
SaveRevision implements ConfigService.
func (API) ValidateOverride ¶
func (a API) ValidateOverride( _ context.Context, req *consolev1.ValidateOverrideRequest, ) (*consolev1.ValidateOverrideResponse, error)
ValidateOverride implements ConfigService.
func (API) WatchConfig ¶
func (a API) WatchConfig( req *consolev1.WatchConfigRequest, stream grpc.ServerStreamingServer[consolev1.WatchConfigResponse], ) error
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 ¶
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) Err ¶
Err is the reconciler's last error while passes keep failing; nil after a pass succeeds.
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 ¶
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.
type Option ¶
type Option func(*Manager)
Option configures New.
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 ¶
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_*.