server

package
v0.0.0-...-3aa9839 Latest Latest
Warning

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

Go to latest
Published: May 18, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BindAddress describes the local IP address and port to bind the server
	// listen socket to. For example, "0.0.0.0:8080".
	BindAddress string
	// EnableProfiling can be used to enable Go profiling and set up HTTP
	// endpoints that, for example, can be queried with
	//    go tool pprof <binary> http://<host>:<port>/debug/pprof/heap
	EnableProfiling bool
}

Config describes a configuration for a HTTPServer.

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields
}

HTTPServer represents a HTTP/REST API server for a particular LogStore.

func NewHTTP

func NewHTTP(serverConfig *Config, logStore logstore.LogStore) *HTTPServer

NewHTTP creates a new HTTP (REST API) server with a given configuration and backing LogStore. The LogStore is assumed to already be in a connected state.

func (*HTTPServer) Start

func (s *HTTPServer) Start() error

Start starts the HTTP server. If successful, this method will block until the server is stopped.

func (*HTTPServer) Stop

func (s *HTTPServer) Stop() error

Stop shuts down the HTTP server.

type MetricDimensions

type MetricDimensions struct {
	// Method is the HTTP method used: GET/POST/...
	Method string
	// Path is the requested path e.g., /write
	Path string
	// StatusCode is the response code, e.g.: 200
	StatusCode int
}

MetricDimensions represent the dimensions over which request metrics are categorized. Each data point for a given metric (for example, total_requests) will be categorized into these dimensions, making it a data point in a time-series (a metric and a particular set of metric dimension values).

total_requests{method=POST,path=/write,statusCode=200} 6
total_requests{method=GET,path=/metrics,statusCode=200} 5

type MetricsMiddleware

type MetricsMiddleware struct {
	TotalRequests   map[MetricDimensions]int64
	SumResponseTime map[MetricDimensions]float64
	AvgResponseTime map[MetricDimensions]float64
	// contains filtered or unexported fields
}

MetricsMiddleware is a "middleware" intended to be added as an interceptor handler that is invoked prior and after a request is dispatched to its handler. It collects metrics about the request handling.

func NewMetricsMiddleware

func NewMetricsMiddleware() *MetricsMiddleware

NewMetricsMiddleware creates a new metricsMiddleware.

func (*MetricsMiddleware) Intercept

func (mw *MetricsMiddleware) Intercept(nextHandler http.Handler) http.Handler

Intercept is called by gorilla mux prior to passing the request through to the handling function `nextHandler`. Here, we time the request handling, log the request, and update the metric counters.

func (*MetricsMiddleware) Metrics

func (mw *MetricsMiddleware) Metrics() *bytes.Buffer

Metrics returns a byte buffer containing a snapshot of the collected metrics thus far.

Jump to

Keyboard shortcuts

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