poller

package
v5.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPollerType = PollerTypeHTTP
View Source
const PollerTypeHTTP = "http"
View Source
const PollerTypeNOOP = "noop"

Variables

This section is empty.

Functions

func AddPollerType

func AddPollerType(name string, globalInit PollerGlobalInitFunc, init PollerInitFunc, poller PollerFunc)

AddPollerType adds a poller with the given name, and the given init and poll funcs. The globalInit and init funcs may be nil; poller MUST NOT be nil.

func File

func File(filename string, result func([]byte, error)) (chan<- struct{}, error)

FilePoller starts a goroutine polling the given file for changes. When changes occur, including an initial read, the result callback is called asynchronously. Returns a kill chan, which will kill the file poller when written to.

func GetGlobalContexts

func GetGlobalContexts(cfg config.Config, appData config.StaticAppData) map[string]interface{}

GetGlobalContexts returns the global contexts corresponding to the registered pollers

Types

type CachePollInfo

type CachePollInfo struct {
	NoKeepAlive     bool
	Interval        time.Duration
	ID              string
	PollingProtocol config.PollingProtocol
	PollConfig
}

type CachePoller

type CachePoller struct {
	Config         CachePollerConfig
	ConfigChannel  chan CachePollerConfig
	TickChan       chan uint64
	GlobalContexts map[string]interface{}
	Handler        handler.Handler
}

func NewCache

func NewCache(
	interval time.Duration,
	tick bool,
	handler handler.Handler,
	cfg config.Config,
	appData config.StaticAppData,
	pollingProtocol config.PollingProtocol,
) CachePoller

NewHTTP creates and returns a new CachePoller. If tick is false, CachePoller.TickChan() will return nil. TODO: rename to not "http", since it's now pluggable

func (CachePoller) Poll

func (p CachePoller) Poll()

type CachePollerConfig

type CachePollerConfig struct {
	Urls            map[string]PollConfig
	Interval        time.Duration
	NoKeepAlive     bool
	PollingProtocol config.PollingProtocol
}

type HTTPPollCtx

type HTTPPollCtx struct {
	Client       *http.Client
	UserAgent    string
	NoKeepAlive  bool
	URL          string
	URLv6        string
	Host         string
	PollerID     string
	HTTPHeader   http.Header
	FormatAccept string
}

type HTTPPollGlobalCtx

type HTTPPollGlobalCtx struct {
	Client       *http.Client
	UserAgent    string
	FormatAccept string
}

type MonitorCfg

type MonitorCfg struct {
	CDN string
	Cfg tc.TrafficMonitorConfigMap
}

type MonitorConfigPoller

type MonitorConfigPoller struct {
	Session          towrap.TrafficOpsSessionThreadsafe
	SessionChannel   chan towrap.TrafficOpsSessionThreadsafe
	ConfigChannel    chan MonitorCfg
	OpsConfigChannel chan handler.OpsConfig
	Interval         time.Duration
	IntervalChan     chan time.Duration
	OpsConfig        handler.OpsConfig
}

func NewMonitorConfig

func NewMonitorConfig(interval time.Duration) MonitorConfigPoller

Creates and returns a new CachePoller. If tick is false, CachePoller.TickChan() will return nil

func (MonitorConfigPoller) Poll

func (p MonitorConfigPoller) Poll()

type PollConfig

type PollConfig struct {
	URL      string
	URLv6    string
	Host     string
	Timeout  time.Duration
	Format   string
	PollType string
}

type PollerConfig

type PollerConfig struct {
	URL         string
	URLv6       string
	Host        string
	Timeout     time.Duration
	NoKeepAlive bool
	PollerID    string
}

PollerConfig is the data given to cache pollers when they're initialized.

type PollerFunc

type PollerFunc func(ctx interface{}, url string, host string, pollID uint64) ([]byte, time.Time, time.Duration, error)

PollerFunc polls a cache. It takes the global context created by this Poller's GlobalInit, and the poller-specific context created by this poller's Init. It returns the response bytes, the time the request finished, the length of time the request took, and any error. If the PollerFunc needs the global context object, the Init func should embed it in the context object it returns. If Init is nil, the global context will be given to the poller.

type PollerGlobalInitFunc

type PollerGlobalInitFunc func(cfg config.Config, appData config.StaticAppData) interface{}

PollerGlobalInit performs global initialization, and returns a global context object. For example, a poller might create a threadsafe client object, which can be used concurrently by all pollers.

type PollerInitFunc

type PollerInitFunc func(cfg PollerConfig, globalCtx interface{}) interface{}

PollerInit performs initialization for a specific poller. It takes the global context created by the poller's GlobalInit. For example, a poller might create a template client in its GlobalInit, and then use that to create a non-threadsafe client for each concurrent poller.

type PollerType

type PollerType struct {
	GlobalInit PollerGlobalInitFunc
	Init       PollerInitFunc
	Poll       PollerFunc
}

Poller is a particular type of cache stat poller. Examples are HTTP, TCP, or NFS files. It only polls and returns bytes received, it does not do any parsing. For stat parsing, see traffic_monitor/cache/stats_types.go.

Jump to

Keyboard shortcuts

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