env

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: 22 Imported by: 0

Documentation

Overview

Package env contains common command line and initialization code for SCION services. If something is specific to one app, it should go into that app's code and not here.

During initialization, SIGHUPs are masked. To call a function on each SIGHUP, pass the function when calling Init.

Index

Constants

View Source
const (
	DefaultLoggingLevel = "info"
	// Default max size of log files in MiB
	DefaultLoggingFileSize = 50
	// Default max age of log file in days
	DefaultLoggingFileMaxAge = 7
	// Default file name for topology file (only the last element of the path)
	DefaultTopologyPath = "topology.json"

	// SciondInitConnectPeriod is the default total amount of time spent
	// attempting to connect to sciond on start.
	SciondInitConnectPeriod = 20 * time.Second

	// ShutdownGraceInterval is the time applications wait after issuing a
	// clean shutdown signal, before forcerfully tearing down the application.
	ShutdownGraceInterval = 5 * time.Second
)

Variables

View Source
var (
	// The value is generated by tools/git-version.
	StartupVersion string
)

Startup* variables are set during link time.

Functions

func AddFlags added in v0.4.0

func AddFlags()

AddFlags adds the config and sample flags.

func CheckFlags added in v0.4.0

func CheckFlags(sampler config.Sampler) (int, bool)

CheckFlags checks whether the config or help-config flags have been set. In case the help-config flag is set, the config flag is ignored and a commented sample config is written to stdout.

The first return value is the return code of the program. The second value indicates whether the program can continue with its execution or should exit.

func ConfigFile added in v0.4.0

func ConfigFile() string

ConfigFile returns the config file path passed through the flag.

func InitLogging

func InitLogging(cfg *Logging) error

InitLogging initializes logging and sets the root logger Log.

func LogAppStarted added in v0.4.0

func LogAppStarted(svcType, elemId string) error

LogAppStarted should be called by applications as soon as logging is initialized.

func LogAppStopped added in v0.4.0

func LogAppStopped(svcType, elemId string)

func ReloadTopology added in v0.4.0

func ReloadTopology(topologyPath string)

func SetupEnv

func SetupEnv(reloadF func())

SetupEnv initializes a basic environment for applications. If reloadF is not nil, the application will call reloadF whenever it receives a SIGHUP signal.

func Usage added in v0.4.0

func Usage()

Usage outputs run-time help to stdout.

func VersionInfo added in v0.4.0

func VersionInfo() string

VersionInfo returns build version information (build date, build version, build chain).

Types

type Features added in v0.4.0

type Features struct {
}

Add feature flags to this structure as needed. Feature flags are always boolean. Don't use any other types here!

func (*Features) ConfigName added in v0.4.0

func (cfg *Features) ConfigName() string

func (*Features) InitDefaults added in v0.4.0

func (cfg *Features) InitDefaults()

func (*Features) Sample added in v0.4.0

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

func (*Features) Validate added in v0.4.0

func (cfg *Features) Validate() error

type General

type General struct {
	// ID is the SCION element ID. This is used to choose the relevant
	// portion of the topology file for some services.
	ID string
	// ConfigDir for loading extra files (currently, only topology.json)
	ConfigDir string
	// Topology is the file path for the local topology JSON file.
	Topology string
	// ReconnectToDispatcher can be set to true to enable transparent dispatcher
	// reconnects.
	ReconnectToDispatcher bool
}

func (*General) ConfigName added in v0.4.0

func (cfg *General) ConfigName() string

func (*General) InitDefaults added in v0.4.0

func (cfg *General) InitDefaults()

InitDefaults sets the default value for Topology if not already set.

func (*General) Sample added in v0.4.0

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

func (*General) Validate added in v0.4.0

func (cfg *General) Validate() error

type Logging

type Logging struct {
	config.NoValidator
	File struct {
		// Path is the location of the logging file. If unset, no file logging
		// is performed.
		Path string
		// Level of file logging (defaults to lib/log default).
		Level string
		// Size is the max size of log file in MiB (defaults to lib/log default).
		Size uint
		// MaxAge is the max age of log file in days (defaults to lib/log default).
		MaxAge uint
		// MaxBackups is the max number of log files to retain (defaults to lib/log default).
		MaxBackups uint
		// FlushInterval specifies how frequently to flush to the log file,
		// in seconds (defaults to lib/log default).
		FlushInterval *int
	}

	Console struct {
		// Level of console logging (defaults to lib/log default).
		Level string
	}
}

func (*Logging) ConfigName added in v0.4.0

func (cfg *Logging) ConfigName() string

func (*Logging) InitDefaults added in v0.4.0

func (cfg *Logging) InitDefaults()

InitDefaults populates unset fields in cfg to their default values (if they have one).

func (*Logging) Sample added in v0.4.0

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

type Metrics

type Metrics struct {
	config.NoDefaulter
	config.NoValidator
	// Prometheus contains the address to export prometheus metrics on. If
	// not set, metrics are not exported.
	Prometheus string
}

func (*Metrics) ConfigName added in v0.4.0

func (cfg *Metrics) ConfigName() string

func (*Metrics) Sample added in v0.4.0

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

func (*Metrics) StartPrometheus added in v0.1.1

func (cfg *Metrics) StartPrometheus()

type QUIC added in v0.4.0

type QUIC struct {
	ResolutionFraction float64
	Address            string
	CertFile           string
	KeyFile            string
}

QUIC contains configuration for control-plane speakers.

func (*QUIC) ConfigName added in v0.4.0

func (cfg *QUIC) ConfigName() string

func (*QUIC) Sample added in v0.4.0

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

type SciondClient added in v0.4.0

type SciondClient struct {
	// Path is the sciond path. It defaults to sciond.DefaultSCIONDPath.
	Path string
	// InitialConnectPeriod is the maximum amount of time spent attempting to
	// connect to sciond on start.
	InitialConnectPeriod util.DurWrap
}

SciondClient contains information for running snet with sciond.

func (*SciondClient) ConfigName added in v0.4.0

func (cfg *SciondClient) ConfigName() string

func (*SciondClient) InitDefaults added in v0.4.0

func (cfg *SciondClient) InitDefaults()

func (*SciondClient) Sample added in v0.4.0

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

func (*SciondClient) Validate added in v0.4.0

func (cfg *SciondClient) Validate() error

type Tracing added in v0.4.0

type Tracing struct {
	// Enabled enables tracing for this service.
	Enabled bool
	// Enable debug mode.
	Debug bool
	// Agent is the address of the local agent that handles the reported
	// traces. (default: localhost:6831)
	Agent string
}

Tracing contains configuration for tracing.

func (*Tracing) ConfigName added in v0.4.0

func (cfg *Tracing) ConfigName() string

func (*Tracing) InitDefaults added in v0.4.0

func (cfg *Tracing) InitDefaults()

func (*Tracing) NewTracer added in v0.4.0

func (cfg *Tracing) NewTracer(id string) (opentracing.Tracer, io.Closer, error)

NewTracer creates a new Tracer for the given configuration. In case tracing is disabled this still returns noop-objects for convenience of the caller.

func (*Tracing) Sample added in v0.4.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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