config

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config provides types and functions to collect, validate and apply user-provided settings.

Index

Constants

View Source
const (
	HTTPServerReadHeaderTimeout time.Duration = 20 * time.Second
	HTTPServerReadTimeout       time.Duration = 1 * time.Minute
	HTTPServerWriteTimeout      time.Duration = 2 * time.Minute
)

Timeout settings applied to our instance of http.Server

View Source
const (

	// NotifyMgrTeamsTimeout is the timeout setting applied to each Microsoft
	// Teams notification attempt. This value does NOT take into account the
	// number of configured retries and retry delays. The final value timeout
	// applied to each notification attempt should be based on those
	// calculations. The GetTimeout method does just that.
	NotifyMgrTeamsTimeout time.Duration = 10 * time.Second

	// NotifyMgrEmailTimeout is the timeout setting applied to each email
	// notification attempt. This value does NOT take into account the number
	// of configured retries and retry delays. The final value timeout applied
	// to each notification attempt should be based on those calculations. The
	// GetTimeout method does just that.
	NotifyMgrEmailTimeout time.Duration = 30 * time.Second

	// NotifyStatsMonitorDelay limits notification stats logging to no more
	// often than this duration. This limiter is to keep from logging the
	// details so often that the information simply becomes noise.
	NotifyStatsMonitorDelay time.Duration = 120 * time.Second

	// NotifyQueueMonitorDelay limits notification queue stats logging to no
	// more often than this duration. This limiter is to keep from logging the
	// details so often that the information simply becomes noise.
	NotifyQueueMonitorDelay time.Duration = 15 * time.Second

	// NotifyMgrTeamsNotificationDelay is the delay between Microsoft Teams
	// notification attempts. This delay is intended to help prevent
	// unintentional abuse of remote services.
	NotifyMgrTeamsNotificationDelay time.Duration = 5 * time.Second

	// NotifyMgrEmailNotificationDelay is the delay between email notification
	// attempts. This delay is intended to help prevent unintentional abuse of
	// remote services.
	NotifyMgrEmailNotificationDelay time.Duration = 5 * time.Second
)

Timing-related settings (delays, timeouts) used by our notification manager and child goroutines to concurrently process notification requests.

View Source
const (
	TCPReservedPort            int = 0
	TCPSystemPortStart         int = 1
	TCPSystemPortEnd           int = 1023
	TCPUserPortStart           int = 1024
	TCPUserPortEnd             int = 49151
	TCPDynamicPrivatePortStart int = 49152
	TCPDynamicPrivatePortEnd   int = 65535
)

TCP port ranges http://www.iana.org/assignments/port-numbers Port numbers are assigned in various ways, based on three ranges: System Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private Ports (49152-65535)

View Source
const (

	// LogLevelFatal is used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	LogLevelFatal string = "fatal"

	// LogLevelError is for errors that should definitely be noted.
	LogLevelError string = "error"

	// LogLevelWarn is for non-critical entries that deserve eyes.
	LogLevelWarn string = "warn"

	// LogLevelInfo is for general application operational entries.
	LogLevelInfo string = "info"

	// LogLevelDebug is for debug-level messages and is usually enabled
	// when debugging. Very verbose logging.
	LogLevelDebug string = "debug"
)

Log levels

View Source
const (
	// LogFormatCLI provides human-friendly CLI output
	LogFormatCLI string = "cli"

	// LogFormatJSON provides JSON output
	LogFormatJSON string = "json"

	// LogFormatLogFmt provides logfmt plain-text output
	LogFormatLogFmt string = "logfmt"

	// LogFormatText provides human-friendly colored output
	LogFormatText string = "text"

	// LogFormatDiscard discards all logs
	LogFormatDiscard string = "discard"
)

apex/log Handlers --------------------------------------------------------- cli - human-friendly CLI output discard - discards all logs es - Elasticsearch handler graylog - Graylog handler json - JSON output handler kinesis - AWS Kinesis handler level - level filter handler logfmt - logfmt plain-text formatter memory - in-memory handler for tests multi - fan-out to multiple handlers papertrail - Papertrail handler text - human-friendly colored output delta - outputs the delta between log calls and spinner

View Source
const (

	// LogOutputStdout represents os.Stdout
	LogOutputStdout string = "stdout"

	// LogOutputStderr represents os.Stderr
	LogOutputStderr string = "stderr"
)
View Source
const HTTPServerShutdownTimeout time.Duration = 30 * time.Second

HTTPServerShutdownTimeout is used by the graceful shutdown process to control how long the shutdown process should wait before forcefully terminating.

View Source
const MyAppName string = "bounce"

MyAppName is the public name of this application

View Source
const MyAppURL string = "https://github.com/atc0005/bounce"

MyAppURL is the location of the repo for this application

View Source
const NotifyMgrQueueDepth int = 5

NotifyMgrQueueDepth is the number of items allowed into the queue/channel at one time. Senders with items for the notification "pipeline" that do not fit within the allocated space will block until space in the queue opens. Best practice for channels advocates that a smaller number is better than a larger one, so YMMV if this is set either too high or too low.

Brief testing (as of this writing) shows that a depth as low as 1 works for our purposes, but results in a greater number of stalled goroutines waiting to place items into the queue.

View Source
const NotifyMgrServicesShutdownTimeout time.Duration = 2 * time.Second

NotifyMgrServicesShutdownTimeout is used by the NotifyMgr to determine how long it should wait for results from each notifier or notifier "service" before continuing on with the shutdown process.

Variables

This section is empty.

Functions

func Branding

func Branding() string

Branding is responsible for emitting application name, version and origin

func GetTimeout added in v0.4.0

func GetTimeout(baseTimeout time.Duration, schedule time.Time, retries int, retriesDelay int) time.Duration

GetTimeout accepts the next scheduled notification, the number of message submission retries and the delay between each attempt and returns the timeout value for the entire message submission process, including the initial attempt and all retry attempts.

This overall timeout value is computed using multiple values; (1) the base timeout value for a single message submission attempt, (2) the next scheduled notification (which was created using the configured delay we wish to force between message submission attempts), (3) the total number of retries allowed, (4) the delay between retry attempts

func MessageTrailer added in v0.4.0

func MessageTrailer() string

MessageTrailer generates a branded "footer" for use with notifications.

func Usage

func Usage(flagSet *flag.FlagSet) func()

Usage is a custom override for the default Help text provided by the flag package. Here we prepend some additional metadata to the existing output.

Types

type Config

type Config struct {

	// LocalIPAddress is the IP Address that this application should listen on
	// for incoming requests
	LocalIPAddress string

	// LogLevel is the chosen logging level
	LogLevel string

	// LogOutput is one of the standard application outputs, stdout or stderr
	// FIXME: Needs better description
	LogOutput string

	// LogFormat controls which output format is used for log messages
	// generated by this application. This value is from a smaller subset
	// of the formats supported by the third-party leveled-logging package
	// used by this application.
	LogFormat string

	// WebhookURL is the full URL used to submit messages to the Teams channel
	// This URL is in the form of https://outlook.office.com/webhook/xxx or
	// https://outlook.office365.com/webhook/xxx. This URL is REQUIRED in
	// order for this application to function and needs to be created in
	// advance by adding/configuring a Webhook Connector in a Microsoft Teams
	// channel that you wish to submit messages to using this application.
	WebhookURL string

	// Retries is the number of attempts that this application will make
	// to deliver messages before giving up.
	Retries int

	// RetriesDelay is the number of seconds to wait between retry attempts.
	RetriesDelay int

	// LocalTCPPort is the TCP port that this application should listen on for
	// incoming requests
	LocalTCPPort int

	// ColorizedJSONIndent controls how many spaces are used when indenting
	// colorized JSON output. If ColorizedJSON is not enabled, this setting
	// has no effect.
	ColorizedJSONIndent int

	// ColorizedJSON indicates whether JSON output should be colorized.
	// Coloring the output could aid in in quick visual evaluation of incoming
	// payloads
	ColorizedJSON bool
}

Config represents the application configuration as specified via command-line flags

func NewConfig

func NewConfig() (*Config, error)

NewConfig is a factory function that produces a new Config object based on user provided flag values.

func (Config) NotifyEmail added in v0.4.0

func (c Config) NotifyEmail() bool

NotifyEmail indicates whether or not notifications should be generated and sent via email to specified recipients.

func (Config) NotifyTeams added in v0.4.0

func (c Config) NotifyTeams() bool

NotifyTeams indicates whether or not notifications should be sent to a Microsoft Teams channel.

func (*Config) String

func (c *Config) String() string

Jump to

Keyboard shortcuts

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