cmd

package
v0.0.0-...-72724d7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// LogKeyTraceID constant extracted value of the trace id field name
	LogKeyTraceID = "pps_trace_id"
	// LogKeySpanID constant extracted value of the span id field name
	LogKeySpanID = "pps_span_id"
	// LogKeyTraceSeq constant extracted value of the span seq field name
	LogKeyTraceSeq = "pps_trace_seq"
	// LogKeyCertKey constant extracted value of the cert key field name
	LogKeyCertKey = "pps_cert_key"
	// LogKeyCertSerial constant extracted value of the cert serial field name
	LogKeyCertSerial = "pps_cert_serial"
	// BaggageKeyCertKey constant extracted value of the cert serial field name
	BaggageKeyCertKey = "pps_cert_key"
	// BaggageKeyCertSerial constant extracted value of the cert serial field name
	BaggageKeyCertSerial = "pps_cert_serial"
)
View Source
const PathHealth = "/health"

PathHealth indicates the health endpoint.

Variables

View Source
var (
	// ErrNoDriver is returned when no database driver is found in config
	ErrNoDriver = fmt.Errorf("no driver found in configuration")
	// ErrMalformedRetriever is returned when a retriever configuration is not valid
	ErrMalformedRetriever = fmt.Errorf("malformed retriever")
)
View Source
var (
	// ErrInterrupt is returned when interrupt signal is caught
	ErrInterrupt = fmt.Errorf("interrupt")
)
View Source
var HealthHandler = http.HandlerFunc(func(ctx *http.Context) error {
	_, _ = ctx.Response.WriteString("OK")
	return nil
})

HealthHandler is used for serving the application status for telegraf or other monitoring systems.

Functions

func AuthJSONMiddleware

func AuthJSONMiddleware(matching func(ctx *http.Context) bool) http.Middleware

AuthJSONMiddleware transform text response into JSON response

func HTTPErrorLogger

func HTTPErrorLogger(logger zerolog.Logger) *log.Logger

HTTPErrorLogger creates a logger for HTTP errors piping to Prometheus

func LoggingMiddleware

func LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc

LoggingMiddleware logs start and end of incoming requests along the respons code.

func RegisterDefaultHealth

func RegisterDefaultHealth(server *http.Server)

RegisterDefaultHealth registers a default health endpoint to http server.

func StartServers

func StartServers(logger zerolog.Logger, servers ...Server) error

StartServers starts multiple Server instances. It listen on os.Interrupt in order to stops all the servers managed.

func TracingMiddleware

func TracingMiddleware(next http.HandlerFunc) http.HandlerFunc

TracingMiddleware is responsible for handling the tracing lifecycle. Initialize it when request come and closing when request is done.

Types

type Configuration

type Configuration struct {
	Debug            bool
	Hostname         string
	Port             int
	PrometheusConfig `mapstructure:"prometheus"`
	Logging          struct {
		Level string
		Type  string
	}
	TLS   *TLSConfig `mapstructure:"tls"`
	Flags struct {
		NoGraphite bool `mapstructure:"no_graphite"`
	}
}

Configuration is a the basic structure of fields for the yubistack modules

func (Configuration) InitOpenTracing

func (c Configuration) InitOpenTracing(serviceName string) error

InitOpenTracing creates a tracer from configuration and set it up globally

func (*Configuration) NewGraphite

func (c *Configuration) NewGraphite(logger zerolog.Logger) (*Graphite, error)

NewGraphite creates a new instance of the Graphite structure with sensible defaults

func (Configuration) ServerOptions

func (c Configuration) ServerOptions() []http.ServerOption

ServerOptions returns the default options with want to pass to the server structure

func (Configuration) Zerolog

func (c Configuration) Zerolog() zerolog.Logger

Zerolog wraps the functionality for logging with different levels.

type DBConfig

type DBConfig struct {
	Mysql  mysql.Config
	Sqlite sqlite.Config
}

DBConfig is a substructure for configuring the database connections

func (DBConfig) NewDB

func (c DBConfig) NewDB(logger zerolog.Logger) (db *sql.DB, driver string, err error)

NewDB transform a DBConfig on an initialize sql.DB connection This function tries multiple drivers to create the effective connection and return an error if something goes wrong.

type ErrMultipleDrivers

type ErrMultipleDrivers []string

ErrMultipleDrivers is returned when there is more than one driver for a specific connection

func (ErrMultipleDrivers) Error

func (e ErrMultipleDrivers) Error() string

Error implement the error interface

type Graphite

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

Graphite structure holds our metrics and is responsible to push it remotely

func (*Graphite) Init

func (g *Graphite) Init() error

Init initializes the graphite registry and starts the goroutines to publish GO's debug and runtime stats

func (*Graphite) MiddleWare

func (g *Graphite) MiddleWare(handler http.HandlerFunc) http.HandlerFunc

MiddleWare creates a pluggable http.Middleware to catch responses and build metrics

type HistVec

type HistVec = prometheus.HistogramVec

HistVec is an alias for prometheus.HistogramVec

type JournaldLevelWriter

type JournaldLevelWriter struct {
	io.Writer
}

JournaldLevelWriter is a structure to write down to systemd journal format

func (*JournaldLevelWriter) WriteLevel

func (jlw *JournaldLevelWriter) WriteLevel(level zerolog.Level, p []byte) (n int, err error)

WriteLevel makes JournalLevelWriter a zerolog writer and convert log entry to journald format

type Prometheus

type Prometheus struct {
	zerolog.Logger

	Metrics map[string]*prometheus.HistogramVec
	// contains filtered or unexported fields
}

Prometheus is the structure we use to deal with Prometheus

func (*Prometheus) ListenAndServe

func (p *Prometheus) ListenAndServe() error

ListenAndServe listens on the TCP network address and serve Prometheus metrics

func (*Prometheus) Middleware

func (p *Prometheus) Middleware(next http.HandlerFunc) http.HandlerFunc

Middleware creates a middleware out of the current structure. It allows us to plug in our server and infer metrics from requests.

func (*Prometheus) Shutdown

func (p *Prometheus) Shutdown(ctx context.Context) error

Shutdown stops the server in a clean fashion

type PrometheusConfig

type PrometheusConfig struct {
	Prefix   string
	Hostname string
	Port     int
}

PrometheusConfig is a structure to configure our prometheus instance

func (PrometheusConfig) Prometheus

func (c PrometheusConfig) Prometheus(options ...func(*Prometheus)) *Prometheus

Prometheus function creates an instance of Prometheus structure from config

func (PrometheusConfig) YKAuth

func (c PrometheusConfig) YKAuth() *HistVec

YKAuth function creates the HistogramVectors for the YKAuth module

func (PrometheusConfig) YKKSM

func (c PrometheusConfig) YKKSM() *HistVec

YKKSM function creates the HistogramVectors for the YKKSM module

func (PrometheusConfig) YKVal

func (c PrometheusConfig) YKVal() *HistVec

YKVal function creates the HistogramVectors for the YKVal module

type Server

type Server interface {
	ListenAndServe() error
	Shutdown(context.Context) error
}

Server interface is used as a task by the runner, it performs a start and stop

func NewServer

func NewServer(options []http.ServerOption, middlewares []http.Middleware, handlers map[string]http.Handler) Server

NewServer is an util function to create a server with options

type TLSConfig

type TLSConfig struct {
	Port     int
	CertFile string `mapstructure:"cert_file"`
	KeyFile  string `mapstructure:"key_file"`
}

TLSConfig is a substructure for configuring TLS

func (*TLSConfig) ServerOptions

func (c *TLSConfig) ServerOptions() []http.ServerOption

ServerOptions is transforming a TLSConfig into a slice of http.ServerOption

type YKAuthConfig

type YKAuthConfig struct {
	ClientID  uint64 `mapstructure:"client_id"`
	SyncLevel string `mapstructure:"sync_level"`
	Timeout   int
	DBConfig  `mapstructure:",squash"`
}

YKAuthConfig contains YKAuth specific configuration fields

func (YKAuthConfig) YKAuth

func (c YKAuthConfig) YKAuth(
	fetcher http.ClientLoaderFactory, val YKValFactory, logger zerolog.Logger,
) (YKAuthFactory, error)

YKAuth transform a YKAuthConfig into a YKAuthFactory

type YKAuthFactory

type YKAuthFactory func(logger zerolog.Logger) *ykauth.YKAuth

YKAuthFactory is currying a YKAuth creation to inject a logger on each request

type YKKSMConfig

type YKKSMConfig struct {
	PrivateKey string `mapstructure:"private_key"`
	Retrievers []map[string]string
	DBConfig   `mapstructure:",squash"`
}

YKKSMConfig contains YKKSM specific configuration fields

func (YKKSMConfig) YKKSM

YKKSM transform a YKKSMConfig into a http.DecrypterFactory

type YKValConfig

type YKValConfig struct {
	Servers  []string
	DBConfig `mapstructure:",squash"`
}

YKValConfig contains YKVal specific configuration fields

func (YKValConfig) YKVal

YKVal transform a YKValConfig into a pkg.ClientLoaderFactory and YKValFactory

type YKValFactory

type YKValFactory func(logger zerolog.Logger) *ykval.YKVal

YKValFactory is currying a YKVal creation to inject a logger on each request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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