Documentation ¶
Overview ¶
package watched provides read access to workload routes backed by a retrying client
The retry methodology we use is to
- divide Recv into an outer receive, which wraps the grpc (inner) watch receives.
- keep an in memory model of the routes upon every successful _outer_ receive.
- keep a buffer encoding a diff against the above model which is returned with priority and in order with outer receive.
- 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.
- 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 ¶
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 ¶
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 ¶
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