Documentation ¶
Index ¶
- Constants
- Variables
- func AuthJSONMiddleware(matching func(ctx *http.Context) bool) http.Middleware
- func HTTPErrorLogger(logger zerolog.Logger) *log.Logger
- func LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc
- func RegisterDefaultHealth(server *http.Server)
- func StartServers(logger zerolog.Logger, servers ...Server) error
- func TracingMiddleware(next http.HandlerFunc) http.HandlerFunc
- type Configuration
- type DBConfig
- type ErrMultipleDrivers
- type Graphite
- type HistVec
- type JournaldLevelWriter
- type Prometheus
- type PrometheusConfig
- type Server
- type TLSConfig
- type YKAuthConfig
- type YKAuthFactory
- type YKKSMConfig
- type YKValConfig
- type YKValFactory
Constants ¶
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" )
const PathHealth = "/health"
PathHealth indicates the health endpoint.
Variables ¶
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") )
var ( // ErrInterrupt is returned when interrupt signal is caught ErrInterrupt = fmt.Errorf("interrupt") )
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 ¶
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 ¶
RegisterDefaultHealth registers a default health endpoint to http server.
func StartServers ¶
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 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 ¶
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 ¶
JournaldLevelWriter is a structure to write down to systemd journal format
func (*JournaldLevelWriter) WriteLevel ¶
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.
type PrometheusConfig ¶
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 ¶
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 ¶
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 ¶
func (c YKKSMConfig) YKKSM(logger zerolog.Logger) (ykksm.DecrypterFactory, error)
YKKSM transform a YKKSMConfig into a http.DecrypterFactory
type YKValConfig ¶
YKValConfig contains YKVal specific configuration fields
func (YKValConfig) YKVal ¶
func (c YKValConfig) YKVal(decrypter ykksm.DecrypterFactory, logger zerolog.Logger) (http.ClientLoaderFactory, YKValFactory, error)
YKVal transform a YKValConfig into a pkg.ClientLoaderFactory and YKValFactory