watched

package
v0.0.0-...-ff62bea Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

package watched provides read access to workload routes backed by a retrying client

The retry methodology we use is to

  1. divide Recv into an outer receive, which wraps the grpc (inner) watch receives.
  2. keep an in memory model of the routes upon every successful _outer_ receive.
  3. keep a buffer encoding a diff against the above model which is returned with priority and in order with outer receive.
  4. Upon error of inner receive, we retry-re-call the inner watch, get synced, and then encode the diff buffer. Upon error, we keep retrying with backoff.
  5. The in-memory model is then given an exported interface for getting routes and checking routing key membership

The above guarantees that retries are not visible to the outer Recv until synced. This, in turn, guarantees that we can provide only ADDs until sync.

Index

Constants

View Source
const (
	SignadotEnvPrefix       = "SIGNADOT_"
	BaselineEnvPrefix       = SignadotEnvPrefix + "BASELINE_"
	BaselineKindEnvVar      = BaselineEnvPrefix + "KIND"
	BaselineNamespaceEnvVar = BaselineEnvPrefix + "NAMESPACE"
	BaselineNameEnvVar      = BaselineEnvPrefix + "NAME"
)

Variables

This section is empty.

Functions

func GetRouteServerAddr

func GetRouteServerAddr() string

Types

type Baseline

type Baseline struct {
	Kind      string `json:"kind"`
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
}

Baseline is the type of a baseline workload. We use this instead of the grpc routes.Baseline because it can be used as a map key, whereas the grpc one cannot.

func BaselineFromEnv

func BaselineFromEnv() (*Baseline, error)

BaselineFromEnv grabs the baseline from the environment if possible. Otherwise, it returns nil and a non-nil error.

type BaselineWatched

type BaselineWatched interface {
	// Get returns a workload routing rule associated with
	// the routing key rk for the associated baseline workload.
	Get(rk string) *routesapi.WorkloadRoutingRule

	// RoutesTo returns true if traffic destined to the associated
	// baseline workload with routing key rk should be directed to
	// the sandbox named sbName.
	RoutesTo(rk string, sbName string) bool
}

BaselineWatched wraps watched.Watched with a routesapi.BaselineWorkload.

func BaselineWatchedFromEnv

func BaselineWatchedFromEnv() (BaselineWatched, error)

BaselineWatchedFromEnv attempts to construct a BaselineWatched instance using configuration from the environment, by using BaselineFromEnv and GetRouteServerAddr and calling NewBaselineWatched. The context associated with the watch is the result of calling context.Background and the logger is the result of calling slog.Default. For more control, please use NewBaselineWatched directly.

func NewBaselineWatched

func NewBaselineWatched(ctx context.Context, cfg *Config, b *routesapi.BaselineWorkload) (BaselineWatched, error)

NewBaselineWatched creates a BaselineWatched instance using ctx for the underlying grpc watch rpc, using the routeserver specified in [cfg.Addr], and associated with the baseline specified in b.

type Config

type Config struct {
	Addr string // address of the routeserver
	Log  *slog.Logger
}

Config provides the information to create a Watched or BaselineWatched.

type Watched

type Watched interface {
	// Get returns a [routesapi.WorkloadRoutingRule] which indicates where to direct
	// requests originally destined to baseline workload baseline with routing
	// key rk.  Get returns nil, if no such rule exists.
	Get(baseline *routesapi.BaselineWorkload, rk string) *routesapi.WorkloadRoutingRule

	// RoutesTo indicates whether or not a request originally destined to
	// baseline workload with routing key rk should be delivered to the
	// corresponding sandboxed workload associated with a sandbox name (sbName).
	RoutesTo(baseline *routesapi.BaselineWorkload, rk, sbName string) bool
}

Watched provides an interface

func NewWatched

func NewWatched(ctx context.Context, cfg *Config, q *routesapi.WorkloadRoutingRulesRequest) (Watched, error)

NewWatched creates a Watched. The set of the workload rules returned from the returned Watched corresponds to those specified in q.

Jump to

Keyboard shortcuts

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