storage

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package storage keeps the divergences that mirrors report to the SPECTRE server, either in memory or in Redis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend string

Backend names where the SPECTRE server keeps divergences.

const (
	BackendMemory Backend = "memory"
	BackendRedis  Backend = "redis"
)

Backends the SPECTRE server can keep divergences in.

type Config

type Config struct {
	Storage  Backend `default:"memory" enum:"memory,redis" help:"Where to keep divergences: memory, which a restart loses, or redis."`
	RedisURL string  `` /* 145-byte string literal not displayed */
}

Config selects where the SPECTRE server keeps divergences.

func (Config) Validate

func (c Config) Validate() error

Validate checks that the selected backend is configured.

type Memory

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

Memory keeps divergences in memory, so a restart loses them. Stored messages are never mutated, so they may be shared.

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty in-memory store.

func (*Memory) Clear

func (m *Memory) Clear(_ context.Context, service, environment string) error

Clear removes the divergences of both directions of a service environment's mirror.

func (*Memory) Close

func (m *Memory) Close() error

Close does nothing, because memory holds no resources.

func (*Memory) List

func (m *Memory) List(_ context.Context) ([]*pb.Divergence, error)

List returns every stored divergence, in no particular order.

func (*Memory) Record

func (m *Memory) Record(_ context.Context, divergence *pb.Divergence) error

Record keeps a divergence unless its source has already reported a later quarantine.

type Redis

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

Redis keeps divergences in a Redis hash, so they outlive the SPECTRE server and are shared by every server using the same Redis database.

func NewRedis

func NewRedis(ctx context.Context, config Config) (*Redis, error)

NewRedis connects to the Redis server the configuration names.

func (*Redis) Clear

func (r *Redis) Clear(ctx context.Context, service, environment string) error

Clear removes the divergences of both directions of a service environment's mirror.

func (*Redis) Close

func (r *Redis) Close() error

Close disconnects from Redis.

func (*Redis) List

func (r *Redis) List(ctx context.Context) ([]*pb.Divergence, error)

List returns every stored divergence, in no particular order.

func (*Redis) Record

func (r *Redis) Record(ctx context.Context, divergence *pb.Divergence) error

Record keeps a divergence unless its source has already reported a later quarantine.

type Store

type Store interface {
	// Record keeps a divergence unless its source has already reported a later quarantine.
	Record(ctx context.Context, divergence *pb.Divergence) error
	// Clear removes the divergences of both directions of a service environment's mirror.
	Clear(ctx context.Context, service, environment string) error
	// List returns every stored divergence, in no particular order.
	List(ctx context.Context) ([]*pb.Divergence, error)
	Close() error
}

Store keeps the latest divergence of each mirror direction. Callers validate divergences before recording them and never mutate stored or listed ones.

func Open

func Open(ctx context.Context, config Config) (Store, error)

Open returns the store the configuration selects.

Jump to

Keyboard shortcuts

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