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 GetClientAuthFromString(clientAuth string) (tls.ClientAuthType, error)
- 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 WinCertStoreHandler
- type WindowsCertificateFilter
- type WindowsClientFilter
- type WindowsServerFilter
Constants ¶
This section is empty.
Variables ¶
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.
var ( DefaultLogLevel = func() LogLevel { var lvl LogLevel lvl.RegisterFlags(emptyFlagSet) return lvl }() )
Default configuration structs.
Functions ¶
func GetClientAuthFromString ¶ added in v0.37.0
func GetClientAuthFromString(clientAuth string) (tls.ClientAuthType, error)
func SignalContext ¶
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 string `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 ¶
UnmarshalYAML unmarshals the server config with defaults applied.
type DialContextFunc ¶ added in v0.25.0
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 ¶
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
ListenHostPort splits the ListenAddress into a listen host and listen port. Returns an error if the ListenAddress isn't valid.
func (*GRPCFlags) RegisterFlags ¶
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
ListenHostPort splits the ListenAddress into a listen host and listen port. Returns an error if the ListenAddress isn't valid.
func (*HTTPFlags) RegisterFlags ¶
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
func (*HookLogger) Log ¶ added in v0.29.0
func (hl *HookLogger) Log(kvps ...interface{}) error
Log implements log.Logger.
func (*HookLogger) Set ¶ added in v0.29.0
func (hl *HookLogger) Set(l log.Logger)
Set where HookedLogger should tee logs to. If a nil logger is passed, the HookedLogger is disabled.
type LogLevel ¶ added in v0.31.0
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 ¶
NewLoggerFromLevel creates a new logger from logging.Level and logging.Format.
func (*Logger) ApplyConfig ¶
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 ¶
ApplyConfig applies changes to the Server block.
func (*Server) GRPCAddress ¶
GRPCAddress returns the GRPC net.Addr of this Server.
func (*Server) HTTPAddress ¶
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 ¶
MarshalYAML marshals the name of the cipher suite.
func (*TLSCipher) UnmarshalYAML ¶
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 ¶
TLSCurve holds the ID of a TLS elliptic curve.
func (*TLSCurve) MarshalYAML ¶
MarshalYAML marshals the ID of a TLS elliptic curve into its name.
func (*TLSCurve) UnmarshalYAML ¶
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 WinCertStoreHandler ¶ added in v0.37.0
type WinCertStoreHandler struct { }
func (WinCertStoreHandler) Run ¶ added in v0.37.0
func (w WinCertStoreHandler) Run()
func (WinCertStoreHandler) Stop ¶ added in v0.37.0
func (w WinCertStoreHandler) Stop()
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