idiscovery

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package idiscovery fetches the topology from the discovery service.

Client packages can start a periodic.Runner with StartRunners that periodically fetches the static and dynamic topology from the discovery service. The received topology is set in itopo.

Initially, the runners try to fetch the topology every second for the configured InitialPeriod until a fetch succeeded. If no fetch is successful after the InitialPeriod, the FailAction is taken. 'Fatal' causes the process to exit. 'Continue' logs a warning, the process continues its execution.

By default changes to the semi-mutable section of static topologies is not allowed. It can be enabled by providing a custom topo handler.

The periodic.Runner for the static topology can be instructed to write updated versions to the file system. To enable this, set the filename in StaticConfig.

A periodic.Task with a customized TopoHandler can be created with NewFetcher, when the client package requires more control.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDynamicFetchInterval is the default time between two dynamic topology queries.
	DefaultDynamicFetchInterval = 5 * time.Second
	// DefaultStaticFetchInterval is the default time between two static topology queries.
	DefaultStaticFetchInterval = 5 * time.Minute
	// DefaultFetchTimeout is the default timeout for a query.
	DefaultFetchTimeout = 1 * time.Second
	// DefaultInitialConnectPeriod is the default total amount of time spent attempting
	// to connect to the discovery service on start.
	DefaultInitialConnectPeriod = 20 * time.Second
)

Functions

func NewFetcher

func NewFetcher(handler TopoHandler, params discovery.FetchParams,
	filename string, client *http.Client, caller string) (*task, error)

NewFetcher creates a periodic.Task that fetches the topology from the discovery service and calls the provided handler on the received topology. If the handler indicates an update, and filename is set, the topology is written.

Types

type Config

type Config struct {
	// Static contains the parameters for fetching the static
	// topology from the discovery service.
	Static StaticConfig
	// Dynamic contains the parameters for fetching the dynamic
	// topology from the discovery service.
	Dynamic FetchConfig
}

func (*Config) ConfigName

func (cfg *Config) ConfigName() string

func (*Config) InitDefaults

func (cfg *Config) InitDefaults()

func (*Config) Sample

func (cfg *Config) Sample(dst io.Writer, path config.Path, ctx config.CtxMap)

func (*Config) Validate

func (cfg *Config) Validate() error

type ConnectParams

type ConnectParams struct {
	// InitialPeriod indicates for how long the process tries to get a valid
	// response from the discovery service until FailAction is executed.
	InitialPeriod util.DurWrap
	// FailAction indicates the action that should be taken if no topology can
	// be fetched from the discovery service within the InitialPeriod.
	FailAction FailAction
}

func (*ConnectParams) ConfigName

func (cfg *ConnectParams) ConfigName() string

func (*ConnectParams) InitDefaults

func (cfg *ConnectParams) InitDefaults()

func (*ConnectParams) Sample

func (cfg *ConnectParams) Sample(dst io.Writer, path config.Path, _ config.CtxMap)

func (*ConnectParams) Validate

func (cfg *ConnectParams) Validate() error

type FailAction

type FailAction string
const (
	// FailActionFatal indicates that the process exits on error.
	FailActionFatal FailAction = "Fatal"
	// FailActionContinue indicates that the process continues on error.
	FailActionContinue FailAction = "Continue"
)

func (*FailAction) UnmarshalText

func (f *FailAction) UnmarshalText(text []byte) error

func (*FailAction) Validate

func (f *FailAction) Validate() error

type FetchConfig

type FetchConfig struct {
	// Enable indicates whether the discovery service is queried
	// for updated topologies.
	Enable bool
	// Interval specifies the time between two queries.
	Interval util.DurWrap
	// Timeout specifies the timeout for a single query.
	Timeout util.DurWrap
	// Https indicates whether https must be used to fetch the topology.
	Https bool
	// Connect contains the parameters for the initial connection
	// check to the discovery service.
	Connect ConnectParams
}

func (*FetchConfig) ConfigName

func (cfg *FetchConfig) ConfigName() string

func (*FetchConfig) InitDefaults

func (cfg *FetchConfig) InitDefaults()

func (*FetchConfig) Sample

func (cfg *FetchConfig) Sample(dst io.Writer, path config.Path, ctx config.CtxMap)

func (*FetchConfig) Validate

func (cfg *FetchConfig) Validate() error

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner periodically fetches the topology from the discovery service. On start up, every second a request is sent, until the configured initial period has passed, or a topology has been fetched successfully.

func (*Runner) Kill

func (r *Runner) Kill()

Kill stops the periodic execution of the Runner.

type Runners

type Runners struct {
	// Static periodically fetches the static topology and sets it in itopo.
	Static *Runner
	// Dynamic periodically fetches the dynamic topology and sets it in itopo.
	Dynamic *Runner
	// Cleaner periodically cleans the expired dynamic topology in itopo.
	Cleaner *periodic.Runner
}

func StartRunners

func StartRunners(cfg Config, file discovery.File, handlers TopoHandlers,
	client *http.Client, caller string) (Runners, error)

StartRunners starts the runners for the specified configuration. In case the topo handler function is not set, StartRunners defaults to setting the topology in itopo.

func (*Runners) Kill

func (r *Runners) Kill()

Kill kills all runners.

type StaticConfig

type StaticConfig struct {
	FetchConfig
	// Filename indicates the file that the static topology is written to on updates.
	// The empty string indicates that the static topology is not written.
	Filename string
}

func (*StaticConfig) ConfigName

func (cfg *StaticConfig) ConfigName() string

func (*StaticConfig) InitDefaults

func (cfg *StaticConfig) InitDefaults()

func (*StaticConfig) Sample

func (cfg *StaticConfig) Sample(dst io.Writer, path config.Path, ctx config.CtxMap)

type TopoHandler

type TopoHandler func(topo *topology.Topo) (bool, error)

TopoHandler handles a topology fetched from the discovery service, and returns whether the provided topology is an update.

type TopoHandlers

type TopoHandlers struct {
	// Static handles the static topology.
	Static TopoHandler
	// Dynamic handles the dynamic topology.
	Dynamic TopoHandler
}

TopoHandlers contains custom topology handlers.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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