track

package
v11.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package track provides a simple interface for tracking known proxies by endpoint/name and correctly handling expiration and exclusivity. The provided Tracker type wraps a workpool.Pool, updating per-key counts as new proxies are discovered and/or old proxies are expired.

Index

Constants

View Source
const (
	// DefaultProxyExpiry is the default amount of time a tracker will attempt
	// to successfully connect to a proxy before giving up
	DefaultProxyExpiry = 3 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ProxyExpiry is the duration an entry will be held since the last
	// successful connection to, or message about, a given proxy.
	ProxyExpiry time.Duration
	// TickRate is the rate at which expired entries are cleared from
	// the cache of known proxies.
	TickRate time.Duration
	// ClusterName is the name of the tracked cluster.
	ClusterName string
}

Config configures basic Tracker parameters.

func (*Config) CheckAndSetDefaults

func (c *Config) CheckAndSetDefaults() error

CheckAndSetDefaults set default values for Config.

type Lease

type Lease = workpool.Lease

type Tracker

type Tracker struct {
	Config
	// contains filtered or unexported fields
}

Tracker is a helper for tracking proxies located behind reverse tunnels and triggering agent spawning as needed. Tracker wraps a workpool.Pool instance and manages a cache of proxies which *may* exist. As proxies are discovered, or old proxies expire, the target counts are automatically updated for the associated address in the workpool. Agents can attempt to "claim" exclusivity for a given proxy, ensuring that multiple agents are not run against the same proxy.

func New

func New(ctx context.Context, c Config) (*Tracker, error)

New configures a new tracker instance.

func (*Tracker) Acquire

func (t *Tracker) Acquire() <-chan Lease

Acquire grants access to the Acquire channel of the embedded work group.

func (*Tracker) Claim

func (t *Tracker) Claim(principals ...string) (unclaim func(), ok bool)

Claim attempts to claim a lease based on the given principals returning a function to unclaim and if the claim was successful.

func (*Tracker) Start

func (t *Tracker) Start()

Start starts tracking for specified proxy address.

func (*Tracker) Stop

func (t *Tracker) Stop()

Stop stops tracking for specified proxy address.

func (*Tracker) StopAll

func (t *Tracker) StopAll()

StopAll permanently deactivates this tracker and cleans up all background goroutines.

func (*Tracker) TrackExpected

func (t *Tracker) TrackExpected(proxies ...string)

TrackExpected starts/refreshes tracking for expected proxies. Called by agents when gossip messages are received.

Jump to

Keyboard shortcuts

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