server

package
v1.3.191 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	DefaultConfig = Config{
		GRPC:  DefaultGRPCConfig,
		HTTP:  DefaultHTTPConfig,
		Flags: DefaultFlags,
	}

	DefaultHTTPConfig = HTTPConfig{}

	DefaultGRPCConfig = GRPCConfig{}
)

Default configuration structs.

View Source
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

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  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

func (c *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers flags for c to the given FlagSet.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

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

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"`
}

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

func (f GRPCFlags) GetListenAddress() string

GetListenAddress determines the final ListenAddress, where it is either o.ListenAddress or a combination of o.ListenHost and o.ListenPort.

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"`
}

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

func (f HTTPFlags) GetListenAddress() string

GetListenAddress determines the final ListenAddress, where it is either o.ListenAddress or a combination of o.ListenHost and o.ListenPort.

func (*HTTPFlags) RegisterFlags

func (f *HTTPFlags) RegisterFlags(fs *flag.FlagSet)

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 NewLogger

func NewLogger(cfg *Config) *Logger

NewLogger creates a new Logger.

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.

func (*Logger) Log

func (l *Logger) Log(kvps ...interface{}) error

Log logs a log line.

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

func (s *Server) ApplyConfig(cfg Config) error

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) Close

func (s *Server) Close() error

Close forcibly closes the server's listeners.

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.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run the server until en error is received or the given context is canceled. Run may not be re-called after it exits.

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"`
	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

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.

Jump to

Keyboard shortcuts

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