track

package
v4.3.5-dev.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 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

This section is empty.

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 sice 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
}

Config configures basic Tracker parameters.

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults set default values for Config.

type Key

type Key struct {
	Cluster string
	Type    string
	Addr    utils.NetAddr
}

Key uniquely identifies a reversetunnel endpoint.

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 key 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

New configures a new tracker instance.

func (*Tracker) Acquire

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

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

func (*Tracker) Start

func (p *Tracker) Start(key Key)

Start starts tracking for specified key.

func (*Tracker) Stop

func (p *Tracker) Stop(key Key)

Stop stops tracking for specified key.

func (*Tracker) StopAll

func (p *Tracker) StopAll()

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

func (*Tracker) TrackExpected

func (p *Tracker) TrackExpected(lease Lease, proxies ...string)

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

func (*Tracker) WithProxy

func (p *Tracker) WithProxy(work func(), lease Lease, principals ...string) (didWork bool)

WithProxy runs the supplied closure if and only if no other work is currently being done with the proxy identified by principals.

Jump to

Keyboard shortcuts

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