Documentation ¶
Index ¶
- Constants
- Variables
- func AddRequestTime(ctx context.Context, rw http.ResponseWriter, r *http.Request, ...)
- func AddTime(ctx context.Context, now time.Time) context.Context
- func InvalidContentType(w http.ResponseWriter, r *http.Request)
- func RequestTime(ctx context.Context) time.Time
- func ToHTTP(ctx context.Context, c ContextHandler) http.Handler
- type BucketRequestCounter
- type CloseHeader
- type Constructor
- type ConstructorFunc
- type ContextHandler
- type CtxWithFlag
- type FastRequestLimitDuration
- type HTTPConstructor
- type Handler
- type HandlerFunc
- type HeaderCtxFlag
- func (m *HeaderCtxFlag) CreateMiddleware(next ContextHandler) ContextHandler
- func (m *HeaderCtxFlag) FlagStr() string
- func (m *HeaderCtxFlag) HasFlag(ctx context.Context) bool
- func (m *HeaderCtxFlag) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, ...)
- func (m *HeaderCtxFlag) SetFlagStr(headerVal string)
- func (m *HeaderCtxFlag) WithFlag(ctx context.Context) context.Context
- type HeadersInRequest
- type NextConstructor
- type NextHTTP
- type Recorder
- type ReqLatencyCounter
- type Request
- type RequestCounter
- func (m *RequestCounter) Datapoints() []*datapoint.Datapoint
- func (m *RequestCounter) GRPCInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func (m *RequestCounter) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Handler)
- func (m *RequestCounter) Wrap(next http.Handler) http.Handler
- type ServiceState
- func (s *ServiceState) Checker(next http.Handler, incHealthCheck func()) http.Handler
- func (s *ServiceState) GracefulShutdown()
- func (s *ServiceState) Healthy()
- func (s *ServiceState) IsHealthy() bool
- func (s *ServiceState) IsInShutdown() bool
- func (s *ServiceState) IsUnavailable() bool
- func (s *ServiceState) ServiceUnavailable()
- func (s *ServiceState) State() int32
- type VarAdder
Constants ¶
const ( // RespOKStr should be used for response ok in string format RespOKStr = "OK" // Connection is used to set connection Header Connection = "Connection" // Close is used to set the value of Connection Header Close = "Close" )
Variables ¶
var ( // RespOKByte should be used to send response ok in byte RespOKByte = []byte(RespOKStr) )
Functions ¶
func AddRequestTime ¶
func AddRequestTime(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
AddRequestTime is a web context that adds the current time to the request's context
func InvalidContentType ¶
func InvalidContentType(w http.ResponseWriter, r *http.Request)
InvalidContentType is a HTTP handler helper to signal that the content type header is wrong
func RequestTime ¶
RequestTime looks at the context to return the time added with AddTime
Types ¶
type BucketRequestCounter ¶
type BucketRequestCounter struct { ActiveConnections int64 Bucket *sfxclient.RollingBucket }
BucketRequestCounter is a negroni handler that tracks connection stats including p99/etc. It's, ideally, an improvment over reqcounter.go
func (*BucketRequestCounter) Datapoints ¶
func (m *BucketRequestCounter) Datapoints() []*datapoint.Datapoint
Datapoints returns active connections plus wrapped bucket stats
func (*BucketRequestCounter) ServeHTTP ¶
func (m *BucketRequestCounter) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Handler)
type CloseHeader ¶
type CloseHeader struct {
SetCloseHeader int32
}
CloseHeader is used to control when connections should signal they should be closed
func (*CloseHeader) OptionallyAddCloseHeader ¶
func (c *CloseHeader) OptionallyAddCloseHeader(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
OptionallyAddCloseHeader will set Connection: Close on the response if SetCloseHeader is non zero
type Constructor ¶
type Constructor interface {
CreateMiddleware(next ContextHandler) ContextHandler
}
Constructor defines how we creates context handling middleware
type ConstructorFunc ¶
type ConstructorFunc func(next ContextHandler) ContextHandler
ConstructorFunc allows a func to become a Constructor
func (ConstructorFunc) CreateMiddleware ¶
func (c ConstructorFunc) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware calls the underline function
type ContextHandler ¶
type ContextHandler interface {
ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)
}
ContextHandler is just like http.Handler but also takes a context
func FromHTTP ¶
func FromHTTP(f http.Handler) ContextHandler
FromHTTP creates a ContextHandler from a http.Handler by throwing away the context
type CtxWithFlag ¶
type CtxWithFlag struct { CtxFlagger *log.CtxDimensions HeaderName string }
CtxWithFlag adds useful request parameters to the logging context, as well as a random request_id to the request
func (*CtxWithFlag) CreateMiddleware ¶
func (m *CtxWithFlag) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a handler that calls next as the next in the chain
func (*CtxWithFlag) ServeHTTPC ¶
func (m *CtxWithFlag) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
ServeHTTPC adds useful request dims to the next context
type FastRequestLimitDuration ¶
FastRequestLimitDuration is the interface for getting the cutoff time for bad requests.
type HTTPConstructor ¶
HTTPConstructor is generally discouraged but allows us to turn a normal http.Handler constructor into a context constructor
func (HTTPConstructor) CreateMiddleware ¶
func (h HTTPConstructor) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a middleware layer for a HTTPConstructor. It is unsafe to call this ContextHandler from multiple threads. Our Handler layer will make sure this doesn't happen
type Handler ¶
type Handler struct { Ending ContextHandler Chain []Constructor StartingContext context.Context Pool sync.Pool }
Handler turns a stack of HTTP handlers into a single handler that threads a context between each
func NewHandler ¶
func NewHandler(startingContext context.Context, ending ContextHandler) *Handler
NewHandler creates a new handler with no middleware layers
func (*Handler) Add ¶
func (h *Handler) Add(parts ...Constructor) *Handler
Add a middleware layer to this handler
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP passes the default starting context
func (*Handler) ServeHTTPC ¶
ServeHTTPC will pass the request between each middleware layer
type HandlerFunc ¶
HandlerFunc can turn a func() into a ContextHandler
func (HandlerFunc) ServeHTTPC ¶
func (h HandlerFunc) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)
ServeHTTPC calls the underline func
type HeaderCtxFlag ¶
type HeaderCtxFlag struct { HeaderName string // contains filtered or unexported fields }
HeaderCtxFlag sets a debug value in the context if HeaderName is not empty, a flag string has been set to non empty, and the header HeaderName or query string HeaderName is equal to the set flag string
func (*HeaderCtxFlag) CreateMiddleware ¶
func (m *HeaderCtxFlag) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a handler that calls next as the next in the chain
func (*HeaderCtxFlag) FlagStr ¶
func (m *HeaderCtxFlag) FlagStr() string
FlagStr returns the currently set flag header
func (*HeaderCtxFlag) HasFlag ¶
func (m *HeaderCtxFlag) HasFlag(ctx context.Context) bool
HasFlag returns true if WithFlag has been set for this context
func (*HeaderCtxFlag) ServeHTTPC ¶
func (m *HeaderCtxFlag) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
ServeHTTPC calls next with a context flagged if the headers match. Note it checks both headers and query parameters.
func (*HeaderCtxFlag) SetFlagStr ¶
func (m *HeaderCtxFlag) SetFlagStr(headerVal string)
SetFlagStr enabled flag setting for HeaderName if it's equal to headerVal
type HeadersInRequest ¶
HeadersInRequest adds headers to any context with a flag set
func (*HeadersInRequest) CreateMiddleware ¶
func (m *HeadersInRequest) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a handler that calls next as the next in the chain
func (*HeadersInRequest) ServeHTTPC ¶
func (m *HeadersInRequest) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
ServeHTTPC will add headers to rw if ctx has the flag set
type NextConstructor ¶
type NextConstructor func(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
NextConstructor creates a Constructor that calls the given function to forward requests
func (NextConstructor) CreateMiddleware ¶
func (n NextConstructor) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware returns a middleware layer that passes next to n()
type NextHTTP ¶
NextHTTP is like NextConstructor but when the next praameter is a http.Handler
func (NextHTTP) CreateMiddleware ¶
func (n NextHTTP) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a middleware layer that saves the context for the next layer
type Recorder ¶
type Recorder struct {
Queue chan Request
}
Recorder stores into Queue each request that comes across the recorder
func (*Recorder) AsHandler ¶
func (t *Recorder) AsHandler() ContextHandler
AsHandler returns a Recoder that can be a destination handler
func (*Recorder) ServeHTTP ¶
func (t *Recorder) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP stores the request into the Queue
func (*Recorder) ServeHTTPC ¶
func (t *Recorder) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
ServeHTTPC stores the req into Queue and calls next
type ReqLatencyCounter ¶
type ReqLatencyCounter struct {
// contains filtered or unexported fields
}
ReqLatencyCounter hold static data for the request latency tracking.
func NewReqLatencyCounter ¶
func NewReqLatencyCounter(fastRequestDurationLimit FastRequestLimitDuration) ReqLatencyCounter
NewReqLatencyCounter creates a new ReqLatencyCounter
func (*ReqLatencyCounter) ModStats ¶
func (a *ReqLatencyCounter) ModStats(ctx context.Context)
ModStats modifies the metric values for the ReqLatencyCounter.
func (*ReqLatencyCounter) ModStatsTime ¶
func (a *ReqLatencyCounter) ModStatsTime(start time.Time)
ModStatsTime modifies the metric values for the ReqLatencyCounter.
type Request ¶
Request is a request put on the TestHandler queue that records eacn request sent through
type RequestCounter ¶
type RequestCounter struct { TotalConnections int64 ActiveConnections int64 TotalProcessingTimeNs int64 }
RequestCounter is a negroni handler that tracks connection stats
func (*RequestCounter) Datapoints ¶
func (m *RequestCounter) Datapoints() []*datapoint.Datapoint
Datapoints returns stats on total connections, active connections, and total processing time
func (*RequestCounter) GRPCInterceptor ¶ added in v3.3.39
func (m *RequestCounter) GRPCInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
GRPCInterceptor makes a unary GRPC interceptor to track requests.
func (*RequestCounter) ServeHTTP ¶
func (m *RequestCounter) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Handler)
ServeHTTP makes an HTTP handler that tracks the requests.
type ServiceState ¶ added in v3.3.18
type ServiceState struct {
// contains filtered or unexported fields
}
ServiceState is used to control when connections should signal they should be closed
func (*ServiceState) Checker ¶ added in v3.3.18
func (s *ServiceState) Checker(next http.Handler, incHealthCheck func()) http.Handler
Checker will generate response writer based on status and is also used to check if service can accept incoming request.. This comes in handy when the ALB refresh is not kicked in and we want to protect the system Note: next can be set to nil during GET request and it should still work
func (*ServiceState) GracefulShutdown ¶ added in v3.3.18
func (s *ServiceState) GracefulShutdown()
GracefulShutdown sets service state as gracefulShutdown
func (*ServiceState) Healthy ¶ added in v3.3.18
func (s *ServiceState) Healthy()
Healthy sets service state as Healthy
func (*ServiceState) IsHealthy ¶ added in v3.3.18
func (s *ServiceState) IsHealthy() bool
IsHealthy returns true if service is healthy
func (*ServiceState) IsInShutdown ¶ added in v3.3.18
func (s *ServiceState) IsInShutdown() bool
IsInShutdown returns true if service is in graceful shutdown stage
func (*ServiceState) IsUnavailable ¶ added in v3.3.18
func (s *ServiceState) IsUnavailable() bool
IsUnavailable returns true if service is temporarily un-available
func (*ServiceState) ServiceUnavailable ¶ added in v3.3.18
func (s *ServiceState) ServiceUnavailable()
ServiceUnavailable sets service state as Unavailable
func (*ServiceState) State ¶ added in v3.3.18
func (s *ServiceState) State() int32
State returns current service state
type VarAdder ¶
type VarAdder struct { Key interface{} Value interface{} }
VarAdder is a middleware layer that adds to the context Key/Value
func (*VarAdder) Generate ¶
func (i *VarAdder) Generate(next ContextHandler) ContextHandler
Generate creates the next middleware layer for VarAdder