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 Flags
- type GRPCConfig
- type GRPCFlags
- type HTTPConfig
- type HTTPFlags
- type Logger
- type Server
- type TLSCipher
- type TLSConfig
- type TLSCurve
- type TLSVersion
Constants ¶
This section is empty.
Variables ¶
var ( DefaultConfig = Config{ GRPC: DefaultGRPCConfig, HTTP: DefaultHTTPConfig, Flags: DefaultFlags, } DefaultHTTPConfig = HTTPConfig{} DefaultGRPCConfig = GRPCConfig{} )
Default configuration structs.
var ( DefaultFlags = Flags{ RegisterInstrumentation: true, GracefulShutdownTimeout: 30 * time.Second, HTTP: DefaultHTTPFlags, GRPC: DefaultGRPCFlags, } DefaultHTTPFlags = HTTPFlags{ ListenNetwork: "tcp", ListenHost: "127.0.0.1", ListenPort: 12345, ReadTimeout: 30 * time.Second, WriteTimeout: 30 * time.Second, IdleTimeout: 120 * time.Second, } DefaultGRPCFlags = GRPCFlags{ ListenNetwork: "tcp", ListenHost: "127.0.0.1", ListenPort: 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 ¶
GoKitLogger creates a logging.Interface from a log.Logger.
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 logging.Level `yaml:"log_level"` LogFormat logging.Format `yaml:"log_format"` GRPC GRPCConfig `yaml:",inline"` HTTP HTTPConfig `yaml:",inline"` // Flags is a DEPRECATED field holding static coniguration options. // It will be removed from YAML and only be exposed by command-line flags in // v0.26.0. // // Updating any field found in Flags will cause updating the Server to fail. Flags Flags `yaml:",inline"` }
Config holds dynamic configuration options for a Server.
func (*Config) RegisterFlags ¶
RegisterFlags registers flags for c to the given FlagSet.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML unmarshals the server config with defaults applied.
type Flags ¶
type Flags struct { RegisterInstrumentation bool `yaml:"register_instrumentation"` GracefulShutdownTimeout time.Duration `yaml:"graceful_shutdown_timeout"` LogSourceIPs bool `yaml:"log_source_ips_enabled"` LogSourceIPsHeader string `yaml:"log_source_ips_header"` LogSourceIPsRegex string `yaml:"log_source_ips_regex"` GRPC GRPCFlags `yaml:",inline"` HTTP HTTPFlags `yaml:",inline"` }
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"`
}
GRPCConfig holds dynamic configuration options for the gRPC server.
type GRPCFlags ¶
type GRPCFlags struct { UseTLS bool `yaml:"-"` ListenNetwork string `yaml:"grpc_listen_network"` ListenAddress string `yaml:"-"` // host:port, takes precedence over ListenHost:ListenPort ListenHost string `yaml:"grpc_listen_address"` ListenPort int `yaml:"grpc_listen_port"` ConnLimit int `yaml:"grpc_listen_conn_limit"` MaxRecvMsgSize int `yaml:"grpc_server_max_recv_msg_size"` MaxSendMsgSize int `yaml:"grpc_server_max_send_msg_size"` MaxConcurrentStreams uint `yaml:"grpc_server_max_concurrent_streams"` MaxConnectionIdle time.Duration `yaml:"grpc_server_max_connection_idle"` MaxConnectionAge time.Duration `yaml:"grpc_server_max_connection_age"` MaxConnectionAgeGrace time.Duration `yaml:"grpc_server_max_connection_age_grace"` KeepaliveTime time.Duration `yaml:"grpc_server_keepalive_time"` KeepaliveTimeout time.Duration `yaml:"grpc_server_keepalive_timeout"` MinTimeBetweenPings time.Duration `yaml:"grpc_server_min_time_between_pings"` PingWithoutStreamAllowed bool `yaml:"grpc_server_ping_without_stream_allowed"` }
GRPCFlags hold static configuration options for the gRPC server.
func (GRPCFlags) GetListenAddress ¶
GetListenAddress determines the final ListenAddress, where it is either o.ListenAddress or a combination of o.ListenHost and o.ListenPort.
func (*GRPCFlags) RegisterFlags ¶
RegisterFlags registers flags for c to the given FlagSet.
type HTTPConfig ¶
type HTTPConfig struct {
TLSConfig TLSConfig `yaml:"http_tls_config"`
}
HTTPConfig holds dynamic configuration options for the HTTP server.
type HTTPFlags ¶
type HTTPFlags struct { UseTLS bool `yaml:"-"` ListenNetwork string `yaml:"http_listen_network"` ListenAddress string `yaml:"-"` // host:port, takes precedence over ListenHost:ListenPort ListenHost string `yaml:"http_listen_address"` ListenPort int `yaml:"http_listen_port"` ConnLimit int `yaml:"http_listen_conn_limit"` ReadTimeout time.Duration `yaml:"http_server_read_timeout"` WriteTimeout time.Duration `yaml:"http_server_write_timeout"` IdleTimeout time.Duration `yaml:"http_server_idle_timeout"` }
HTTPFlags hold static configuration options for the HTTP server.
func (HTTPFlags) GetListenAddress ¶
GetListenAddress determines the final ListenAddress, where it is either o.ListenAddress or a combination of o.ListenHost and o.ListenPort.
func (*HTTPFlags) RegisterFlags ¶
RegisterFlags registers flags for c to the given FlagSet.
type Logger ¶
type Logger struct {
// 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 // 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) (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. ApplyConfig will fail if the cfg.Flags field has been changed.
v0.26.0 will remove YAML support for cfg.Flags and remove it out of the Config struct to simplify dynamic updating.
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"` TLSKeyPath string `yaml:"key_file"` ClientAuth string `yaml:"client_auth_type"` ClientCAs string `yaml:"client_ca_file"` CipherSuites []TLSCipher `yaml:"cipher_suites"` CurvePreferences []TLSCurve `yaml:"curve_preferences"` MinVersion TLSVersion `yaml:"min_version"` MaxVersion TLSVersion `yaml:"max_version"` PreferServerCipherSuites bool `yaml:"prefer_server_cipher_suites"` }
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.