Documentation
¶
Overview ¶
Package server implements the HTTP and gRPC server used throughout Grafana Agent.
It is a grafana/agent-specific fork of github.com/weaveworks/common/server.
Index ¶
- Variables
- func GoKitLogger(l log.Logger) logging.Interface
- func SignalContext(ctx context.Context, l log.Logger) (context.Context, context.CancelFunc)
- type Config
- type DialContextFunc
- type Flags
- type GRPCConfig
- type GRPCFlags
- type HTTPConfig
- type HTTPFlags
- type HookLogger
- type LogLevel
- type Logger
- type Server
- type TLSCipher
- type TLSConfig
- type TLSCurve
- type TLSVersion
- type WindowsCertificateFilter
- type WindowsClientFilter
- type WindowsServerFilter
Constants ¶
This section is empty.
Variables ¶
var (
DefaultLogLevel = func() LogLevel {
var lvl LogLevel
lvl.RegisterFlags(emptyFlagSet)
return lvl
}()
DefaultLogFormat = func() logging.Format {
var fmt logging.Format
fmt.RegisterFlags(emptyFlagSet)
return fmt
}()
)
Default configuration structs.
var (
DefaultFlags = Flags{
RegisterInstrumentation: true,
GracefulShutdownTimeout: 30 * time.Second,
HTTP: DefaultHTTPFlags,
GRPC: DefaultGRPCFlags,
}
DefaultHTTPFlags = HTTPFlags{
InMemoryAddr: "agent.internal:12345",
ListenNetwork: "tcp",
ListenAddress: "127.0.0.1:12345",
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
}
DefaultGRPCFlags = GRPCFlags{
InMemoryAddr: "agent.internal:12346",
ListenNetwork: "tcp",
ListenAddress: "127.0.0.1:12346",
MaxRecvMsgSize: 4 * 1024 * 1024,
MaxSendMsgSize: 4 * 1024 * 1024,
MaxConcurrentStreams: 100,
MaxConnectionIdle: infinity,
MaxConnectionAge: infinity,
MaxConnectionAgeGrace: infinity,
KeepaliveTime: 2 * time.Hour,
KeepaliveTimeout: 20 * time.Second,
MinTimeBetweenPings: 5 * time.Minute,
}
)
Default options structs.
Functions ¶
func GoKitLogger ¶
func GoKitLogger(l log.Logger) logging.Interface
GoKitLogger creates a logging.Interface from a log.Logger.
func SignalContext ¶
func SignalContext(ctx context.Context, l log.Logger) (context.Context, context.CancelFunc)
SignalContext wraps a ctx which will be canceled if an interrupt is received.
It is invalid to have two simultaneous SignalContexts per binary.
Types ¶
type Config ¶
type Config struct {
LogLevel LogLevel `yaml:"log_level,omitempty"`
LogFormat logging.Format `yaml:"log_format,omitempty"`
GRPC GRPCConfig `yaml:",inline"`
HTTP HTTPConfig `yaml:",inline"`
}
Config holds dynamic configuration options for a Server.
func DefaultConfig ¶
func DefaultConfig() Config
func (*Config) UnmarshalYAML ¶
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML unmarshals the server config with defaults applied.
type DialContextFunc ¶ added in v0.25.0
type DialContextFunc func(ctx context.Context, network string, addr string) (net.Conn, error)
DialContextFunc is a function matching the signature of net.Dialer.DialContext.
type Flags ¶
type Flags struct {
RegisterInstrumentation bool
GracefulShutdownTimeout time.Duration
LogSourceIPs bool
LogSourceIPsHeader string
LogSourceIPsRegex string
GRPC GRPCFlags
HTTP HTTPFlags
}
Flags hold static configuration options for a Server.
func (*Flags) RegisterFlags ¶
func (f *Flags) RegisterFlags(fs *flag.FlagSet)
RegisterFlags registers flags for c to the given FlagSet.
type GRPCConfig ¶
type GRPCConfig struct {
TLSConfig TLSConfig `yaml:"grpc_tls_config,omitempty"`
}
GRPCConfig holds dynamic configuration options for the gRPC server.
type GRPCFlags ¶
type GRPCFlags struct {
UseTLS bool
InMemoryAddr string
ListenNetwork string
ListenAddress string // host:port
ConnLimit int
MaxRecvMsgSize int
MaxSendMsgSize int
MaxConcurrentStreams uint
MaxConnectionIdle time.Duration
MaxConnectionAge time.Duration
MaxConnectionAgeGrace time.Duration
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
MinTimeBetweenPings time.Duration
PingWithoutStreamAllowed bool
}
GRPCFlags hold static configuration options for the gRPC server.
func (GRPCFlags) ListenHostPort ¶ added in v0.26.0
func (f GRPCFlags) ListenHostPort() (host string, port int, err error)
ListenHostPort splits the ListenAddress into a listen host and listen port. Returns an error if the ListenAddress isn't valid.
func (*GRPCFlags) RegisterFlags ¶
func (f *GRPCFlags) RegisterFlags(fs *flag.FlagSet)
RegisterFlags registers flags for c to the given FlagSet.
type HTTPConfig ¶
type HTTPConfig struct {
TLSConfig TLSConfig `yaml:"http_tls_config,omitempty"`
}
HTTPConfig holds dynamic configuration options for the HTTP server.
type HTTPFlags ¶
type HTTPFlags struct {
UseTLS bool
InMemoryAddr string
ListenNetwork string
ListenAddress string // host:port
ConnLimit int
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
}
HTTPFlags hold static configuration options for the HTTP server.
func (HTTPFlags) ListenHostPort ¶ added in v0.26.0
func (f HTTPFlags) ListenHostPort() (host string, port int, err error)
ListenHostPort splits the ListenAddress into a listen host and listen port. Returns an error if the ListenAddress isn't valid.
func (*HTTPFlags) RegisterFlags ¶
func (f *HTTPFlags) RegisterFlags(fs *flag.FlagSet)
RegisterFlags registers flags for c to the given FlagSet.
type HookLogger ¶ added in v0.29.0
type HookLogger struct {
// contains filtered or unexported fields
}
HookLogger is used to temporarily redirect
type LogLevel ¶ added in v0.31.0
type LogLevel struct {
logging.Level `yaml:",inline"`
}
LogLevel wraps the logging.Level type to allow defining IsZero, which is required to make omitempty work when marshalling YAML.
type Logger ¶
type Logger struct {
// HookLogger is used to temporarily hijack logs for support bundles.
HookLogger HookLogger
// contains filtered or unexported fields
}
Logger implements Go Kit's log.Logger interface. It supports being dynamically updated at runtime.
func NewLoggerFromLevel ¶
func NewLoggerFromLevel(lvl logging.Level, fmt logging.Format) *Logger
NewLoggerFromLevel creates a new logger from logging.Level and logging.Format.
func (*Logger) ApplyConfig ¶
func (l *Logger) ApplyConfig(cfg *Config) error
ApplyConfig applies configuration changes to the logger.
type Server ¶
type Server struct {
HTTP *mux.Router
HTTPServer *http.Server
GRPC *grpc.Server
// DialContext creates a connection to the given network/address. If address
// matches the Server's internal HTTP or gRPC address, an internal in-memory
// connection will be opened.
DialContext DialContextFunc
// contains filtered or unexported fields
}
Server wraps an HTTP and gRPC server with some common initialization.
Unless instrumentation is disabled in the Servers config, Prometheus metrics will be automatically generated for the server.
func New ¶
func New(l log.Logger, r prometheus.Registerer, g prometheus.Gatherer, cfg Config, flags Flags) (srv *Server, err error)
New creates a new Server with the given config.
r is used to register Server-specific metrics. If r is nil, no metrics will be registered.
g is used for collecting metrics from the instrumentation handlers, when enabled. If g is nil, a /metrics endpoint will not be registered.
func (*Server) ApplyConfig ¶
func (s *Server) ApplyConfig(cfg Config) error
ApplyConfig applies changes to the Server block.
func (*Server) GRPCAddress ¶
func (s *Server) GRPCAddress() net.Addr
GRPCAddress returns the GRPC net.Addr of this Server.
func (*Server) HTTPAddress ¶
func (s *Server) HTTPAddress() net.Addr
HTTPAddress returns the HTTP net.Addr of this Server.
type TLSCipher ¶
type TLSCipher uint16
TLSCipher holds the ID of a tls.CipherSuite.
func (TLSCipher) MarshalYAML ¶
func (c TLSCipher) MarshalYAML() (interface{}, error)
MarshalYAML marshals the name of the cipher suite.
func (*TLSCipher) UnmarshalYAML ¶
func (c *TLSCipher) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML unmarshals the name of a cipher suite to its ID.
type TLSConfig ¶
type TLSConfig struct {
TLSCertPath string `yaml:"cert_file,omitempty"`
TLSKeyPath string `yaml:"key_file,omitempty"`
ClientAuth string `yaml:"client_auth_type,omitempty"`
ClientCAs string `yaml:"client_ca_file,omitempty"`
CipherSuites []TLSCipher `yaml:"cipher_suites,omitempty"`
CurvePreferences []TLSCurve `yaml:"curve_preferences,omitempty"`
MinVersion TLSVersion `yaml:"min_version,omitempty"`
MaxVersion TLSVersion `yaml:"max_version,omitempty"`
PreferServerCipherSuites bool `yaml:"prefer_server_cipher_suites,omitempty"`
WindowsCertificateFilter *WindowsCertificateFilter `yaml:"windows_certificate_filter,omitempty"`
}
TLSConfig holds dynamic configuration options for TLS.
type TLSCurve ¶
type TLSCurve tls.CurveID
TLSCurve holds the ID of a TLS elliptic curve.
func (*TLSCurve) MarshalYAML ¶
func (c *TLSCurve) MarshalYAML() (interface{}, error)
MarshalYAML marshals the ID of a TLS elliptic curve into its name.
func (*TLSCurve) UnmarshalYAML ¶
func (c *TLSCurve) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML unmarshals the name of a TLS elliptic curve into its ID.
type TLSVersion ¶
type TLSVersion uint16
TLSVersion holds a TLS version ID.
func (*TLSVersion) MarshalYAML ¶
func (tv *TLSVersion) MarshalYAML() (interface{}, error)
MarshalYAML marshals the ID of a TLS version into its name.
func (*TLSVersion) UnmarshalYAML ¶
func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML unmarshals the name of a TLS version into its ID.
type WindowsCertificateFilter ¶ added in v0.25.0
type WindowsCertificateFilter struct {
Server *WindowsServerFilter `yaml:"server,omitempty"`
Client *WindowsClientFilter `yaml:"client,omitempty"`
}
WindowsCertificateFilter represents the configuration for accessing the Windows store
type WindowsClientFilter ¶ added in v0.25.0
type WindowsClientFilter struct {
IssuerCommonNames []string `yaml:"issuer_common_names,omitempty"`
SubjectRegEx string `yaml:"subject_regex,omitempty"`
TemplateID string `yaml:"template_id,omitempty"`
}
WindowsClientFilter is used to select a client root CA certificate
type WindowsServerFilter ¶ added in v0.25.0
type WindowsServerFilter struct {
Store string `yaml:"store,omitempty"`
SystemStore string `yaml:"system_store,omitempty"`
IssuerCommonNames []string `yaml:"issuer_common_names,omitempty"`
TemplateID string `yaml:"template_id,omitempty"`
RefreshInterval time.Duration `yaml:"refresh_interval,omitempty"`
}
WindowsServerFilter is used to select a server certificate