cmd

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package cmd implements utilities related to setting up command line applications in elasticsearch-asg.

Index

Constants

View Source
const Namespace = "elasticsearchasg"

Namespace is the namespace to be used for Prometheus metrics throughout elasticsearch-asg.

Variables

This section is empty.

Functions

func BuildPromFQName

func BuildPromFQName(subsystem, name string) string

func GracefulShutdown

func GracefulShutdown(s *http.Server, timeout time.Duration) error

GracefulShutdown shutsdown a server, giving open connections up to the timeout duration to close before forceably stopping the server. If timeout <= 0, the server will wait indefinitely for connections to close.

func NewHealthchecksHandler

func NewHealthchecksHandler(r prometheus.Registerer, appName string) healthcheck.Handler

NewHealthchecksHandler returns a new healthcheck.Handler, configured with a basic liveness check and Prometheus healthcheck status metrics for a given app name.

func SetGlobalLogger

func SetGlobalLogger(logger *zap.Logger) func()

SetGlobalLogger both sets the zap global logger, and redirects the output from the standard library's package-global logger to the supplied logger at the debug level. It returns a teardown function to reset the global loggers.

func SetGlobalLoggerAt

func SetGlobalLoggerAt(logger *zap.Logger, stdLogLevel zapcore.Level) func()

SetGlobalLogger both sets the zap global logger, and redirects the output from the standard library's package-global logger to the supplied logger at the specified level. It returns a teardown function to reset the global loggers.

func WithInterrupt

func WithInterrupt(ctx context.Context) (context.Context, context.CancelFunc)

WithInterrupt returns a Context that will be canceled if a SIGINT or SIGTERM is received.

Types

type AWSFlags

type AWSFlags struct {
	// Name of AWS region to use.
	Region string

	// Name of a shared AWS credentials profile to use.
	Profile string

	// Max number of retries to attempt on connection error.
	MaxRetries int
}

AWSFlags represents a set of flags for connecting to AWS.

func NewAWSFlags

func NewAWSFlags(app Flagger, maxRetries int) *AWSFlags

NewAWSFlags returns a new BaseFlags.

func (*AWSFlags) AWSConfig

func (f *AWSFlags) AWSConfig(opts ...external.Config) aws.Config

AWSConfig returns a aws.Config configure based on the default AWS config and these flags.

type ElasticsearchFlags

type ElasticsearchFlags struct {
	// URL(s) of Elasticsearch nodes to connect to.
	URLs []*url.URL

	// Exponential backoff retries flags.
	Retry struct {
		// Initial backoff duration.
		Init time.Duration

		// Max backoff duration.
		Max time.Duration
	}
}

ElasticsearchFlags represents a base set of flags for connecting to Elasticsearch.

func NewElasticsearchFlags

func NewElasticsearchFlags(app Flagger, retryInit, retryMax time.Duration) *ElasticsearchFlags

NewElasticsearchFlags returns a new BaseFlags.

func (*ElasticsearchFlags) NewElasticsearchClient

func (f *ElasticsearchFlags) NewElasticsearchClient(options ...elastic.ClientOptionFunc) (*elastic.Client, error)

NewElasticsearchClient returns a new Elasticsearch client configured with the URL and retry flag values, plus any other options passed in.

type Flagger

type Flagger interface {
	Flag(name string, help string) *kingpin.FlagClause
	Arg(name string, help string) *kingpin.ArgClause
}

Flagger defines command line flags and args. Examples: kingpin.Application and kingping.CmdClause.

type LoggingFlags

type LoggingFlags struct {
	LogLevel zapcore.Level // Logging level.
}

LoggingFlags represents a set of flags for setting up logging.

func NewLoggingFlags

func NewLoggingFlags(app Flagger, logLevel string) *LoggingFlags

NewLoggingFlags returns a new LoggingFlags.

func (*LoggingFlags) NewLogger

func (f *LoggingFlags) NewLogger() *zap.Logger

NewLogger returns a new logger based on the LogLevel flag.

type ServerFlags

type ServerFlags struct {
	Port        uint16 // Port to serve health checks, Prometheus metrics, and anything else on.
	LivePath    string // HTTP path to serve the liveness healthcheck at.
	ReadyPath   string // HTTP path to serve the readiness healthcheck at.
	MetricsPath string // HTTP path to serve Prometheus metrics at.
}

ServerFlags represents a set of flags for setting up a server with healthchecks and Prometheus metrics.

func NewServerFlags

func NewServerFlags(app Flagger, port int) *ServerFlags

NewServerFlags returns a new ServerFlags.

func (*ServerFlags) ConfigureMux

ConfigureMux sets a mux to serve healthchecks and Prometheus metrics based on the path flags in f.

func (*ServerFlags) NewServer

func (f *ServerFlags) NewServer(h http.Handler) *http.Server

NewServer returns a new HTTP server configured to listen on the port defined by the Port flag.

Jump to

Keyboard shortcuts

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