datareq

package
v6.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const NotFoundStatus = "unavailable - interface not found"

NotFoundStatus is the status value of an interface that has not been found in the polled interface data.

View Source
const OnlineStatus = "available - server ONLINE"

OnlineStatus is the status value of all interfaces that are associated with an ONLINE server.

Variables

This section is empty.

Functions

func HandleErr

func HandleErr(errorCount threadsafe.Uint, reqPath string, err error)

HandleErr takes an error, and the request type it came from, and logs. It is ok to call with a nil error, in which case this is a no-op.

func MakeDispatchMap

func MakeDispatchMap(
	opsConfig threadsafe.OpsConfig,
	toSession towrap.TrafficOpsSessionThreadsafe,
	localStates peer.CRStatesThreadsafe,
	peerStates peer.CRStatesPeersThreadsafe,
	combinedStates peer.CRStatesThreadsafe,
	statInfoHistory threadsafe.ResultInfoHistory,
	statResultHistory threadsafe.ResultStatHistory,
	statMaxKbpses threadsafe.CacheKbpses,
	healthHistory threadsafe.ResultHistory,
	dsStats threadsafe.DSStatsReader,
	events health.ThreadsafeEvents,
	staticAppData config.StaticAppData,
	healthPollInterval time.Duration,
	lastHealthDurations threadsafe.DurationMap,
	fetchCount threadsafe.Uint,
	healthIteration threadsafe.Uint,
	errorCount threadsafe.Uint,
	toData todata.TODataThreadsafe,
	localCacheStatus threadsafe.CacheAvailableStatus,
	lastStats threadsafe.LastStats,
	unpolledCaches threadsafe.UnpolledCaches,
	monitorConfig threadsafe.TrafficMonitorConfigMap,
) map[string]http.HandlerFunc

MakeDispatchMap returns the map of paths to http.HandlerFuncs for dispatching.

func NewCacheStatFilter

func NewCacheStatFilter(path string, params url.Values, cacheTypes map[tc.CacheName]tc.CacheType) (cache.Filter, error)

NewCacheStatFilter takes the HTTP query parameters and creates a CacheStatFilter which fulfills the `cache.Filter` interface, filtering according to the query parameters passed. Query parameters used are `hc`, `stats`, `wildcard`, `type`, and `hosts`. If `hc` is 0, all history is returned. If `hc` is empty, 1 history is returned. If `stats` is empty, all stats are returned. If `wildcard` is empty, `stats` is considered exact. If `type` is empty, all cache types are returned.

func NewDSStatFilter

func NewDSStatFilter(path string, params url.Values, dsTypes map[tc.DeliveryServiceName]tc.DSTypeCategory) (dsdata.Filter, error)

NewDSStatFilter takes the HTTP query parameters and creates a cache.Filter, filtering according to the query parameters passed. Query parameters used are `hc`, `stats`, `wildcard`, `type`, and `deliveryservices`. If `hc` is 0, all history is returned. If `hc` is empty, 1 history is returned. If `stats` is empty, all stats are returned. If `wildcard` is empty, `stats` is considered exact. If `type` is empty, all types are returned.

func WrapAgeErr

func WrapAgeErr(errorCount threadsafe.Uint, f func() ([]byte, time.Time, error), contentType string) http.HandlerFunc

func WrapBytes

func WrapBytes(f func() []byte, contentType string) http.HandlerFunc

WrapBytes takes a function which cannot error and returns only bytes, and wraps it as a http.HandlerFunc. The errContext is logged if the write fails, and should be enough information to trace the problem (function name, endpoint, request parameters, etc).

func WrapErr

func WrapErr(errorCount threadsafe.Uint, f func() ([]byte, error), contentType string) http.HandlerFunc

WrapErr takes a function which returns bytes and an error, and wraps it as a http.HandlerFunc. If the error is nil, the bytes are written with Status OK. Else, the error is logged, and InternalServerError is returned as the response code. If you need to return a different response code (for example, StatusBadRequest), call wrapRespCode.

func WrapErrCode

func WrapErrCode(errorCount threadsafe.Uint, reqPath string, body []byte, err error) ([]byte, int)

WrapErrCode calls the WrapErrStatusCode function with a hardcoded 500. This is a convenience function for callers that do not want to provide a status code.

func WrapErrStatusCode

func WrapErrStatusCode(errorCount threadsafe.Uint, reqPath string, body []byte, statusCode int, err error) ([]byte, int)

WrapErrStatusCode takes the body, err, status code, and log context (errorCount, reqPath). It logs and deals with any error, and returns the appropriate bytes and response code for the `srvhttp`. It notably returns InternalServerError status on any error, for security reasons.

func WrapParams

func WrapParams(f SrvFunc, contentType string) http.HandlerFunc

WrapParams takes a SrvFunc and wraps it as an http.HandlerFunc. Note if the SrvFunc returns 0 bytes, an InternalServerError is returned, and the response code is ignored, for security reasons. If an error response code is necessary, return bytes to that effect, for example, "Bad Request". DO NOT return informational messages regarding internal server errors; these should be logged, and only a 500 code returned to the client, for security reasons.

Types

type APIPeerStates

type APIPeerStates struct {
	tc.CommonAPIData
	Peers map[tc.TrafficMonitorName]map[tc.CacheName][]CacheState `json:"peers"`
}

APIPeerStates contains the data to be returned for an API call to get the peer states of a Traffic Monitor. This contains common API data returned by most endpoints, and a map of peers, to caches' states.

type CacheInterfaceStatus

type CacheInterfaceStatus struct {
	Status        string  `json:"status"`
	StatusPoller  string  `json:"status_poller"`
	BandwidthKbps float64 `json:"bandwidth_kbps"`
	Available     bool    `json:"available"`
}

CacheInterfaceStatus represents the status of a single network interface of a cache server.

type CacheStatFilter

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

CacheStatFilter fulfills the cache.Filter interface, for filtering stats. See the `NewCacheStatFilter` documentation for details on which query parameters are used to filter.

func (*CacheStatFilter) UseCache

func (f *CacheStatFilter) UseCache(name tc.CacheName) bool

UseCache returns whether the given cache is in the filter.

func (*CacheStatFilter) UseInterfaceStat

func (f *CacheStatFilter) UseInterfaceStat(statName string) bool

func (*CacheStatFilter) UseStat

func (f *CacheStatFilter) UseStat(statName string) bool

UseStat returns whether the given stat is in the filter.

func (*CacheStatFilter) WithinStatHistoryMax

func (f *CacheStatFilter) WithinStatHistoryMax(n uint64) bool

WithinStatHistoryMax returns whether the given history index is less than the max history of this filter.

type CacheStatSummary

type CacheStatSummary struct {
	// InterfaceStats is a map of network interface names to a map of statistic
	// names to their summaries.
	InterfaceStats map[string]map[string]StatSummaryStat `json:"interfaceStats"`
	// Stats is a map of statistic names to summaries of those statistics.
	Stats map[string]StatSummaryStat `json:"stats"`
}

CacheStatSummary is a summary of a cache server's measured statistics and the measured statistics of its network interfaces.

type CacheState

type CacheState struct {
	Value         bool `json:"value"`
	Ipv4Available bool `json:"ipv4Available"`
	Ipv6Available bool `json:"ipv6Available"`
}

CacheState represents the available state of a cache.

type CacheStatus

type CacheStatus struct {
	Type        *string  `json:"type,omitempty"`
	LoadAverage *float64 `json:"load_average,omitempty"`
	// QueryTimeMilliseconds is the time it took this app to perform a complete
	// query and process the data, end-to-end, for the latest health query.
	QueryTimeMilliseconds *int64 `json:"query_time_ms,omitempty"`
	// HealthTimeMilliseconds is the time it took to make the HTTP request and
	// get back the full response, for the latest health query.
	HealthTimeMilliseconds *int64 `json:"health_time_ms,omitempty"`
	// StatTimeMilliseconds is the time it took to make the HTTP request and get
	// back the full response, for the latest stat query.
	StatTimeMilliseconds *int64 `json:"stat_time_ms,omitempty"`
	// StatSpanMilliseconds is the length of time between completing the most
	// recent two stat queries. This can be used as a rough gauge of the
	// end-to-end query processing time.
	StatSpanMilliseconds *int64 `json:"stat_span_ms,omitempty"`
	// HealthSpanMilliseconds is the length of time between completing the most
	// recent two health queries. This can be used as a rough gauge of the
	// end-to-end query processing time.
	HealthSpanMilliseconds *int64 `json:"health_span_ms,omitempty"`

	Status                *string  `json:"status,omitempty"`
	StatusPoller          *string  `json:"status_poller,omitempty"`
	BandwidthKbps         *float64 `json:"bandwidth_kbps,omitempty"`
	BandwidthCapacityKbps *float64 `json:"bandwidth_capacity_kbps,omitempty"`
	ConnectionCount       *int64   `json:"connection_count,omitempty"`
	IPv4Available         *bool    `json:"ipv4_available,omitempty"`
	IPv6Available         *bool    `json:"ipv6_available,omitempty"`
	CombinedAvailable     *bool    `json:"combined_available,omitempty"`

	Interfaces *map[string]CacheInterfaceStatus `json:"interfaces,omitempty"`
}

CacheStatus contains summary stat data about the given cache.

type DSStatFilter

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

DSStatFilter fulfills the cache.Filter interface, for filtering stats. See the `NewDSStatFilter` documentation for details on which query parameters are used to filter.

func (*DSStatFilter) UseDeliveryService

func (f *DSStatFilter) UseDeliveryService(name tc.DeliveryServiceName) bool

UseDeliveryService returns whether the given delivery service is in this filter.

func (*DSStatFilter) UseStat

func (f *DSStatFilter) UseStat(statName string) bool

UseStat returns whether the given stat is in this filter.

func (*DSStatFilter) WithinStatHistoryMax

func (f *DSStatFilter) WithinStatHistoryMax(n int) bool

WithinStatHistoryMax returns whether the given history index is less than the max history of this filter.

type Durations

type Durations []time.Duration

func (Durations) Len

func (s Durations) Len() int

func (Durations) Less

func (s Durations) Less(i, j int) bool

func (Durations) Swap

func (s Durations) Swap(i, j int)

type JSONEvents

type JSONEvents struct {
	Events []health.Event `json:"events"`
}

JSONEvents represents the structure we wish to serialize to JSON, for Events.

type JSONStats

type JSONStats struct {
	Stats Stats `json:"stats"`
}

type PeerStateFilter

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

PeerStateFilter fulfills the cache.Filter interface, for filtering stats. See the `NewPeerStateFilter` documentation for details on which query parameters are used to filter.

func NewPeerStateFilter

func NewPeerStateFilter(path string, params url.Values, cacheTypes map[tc.CacheName]tc.CacheType) (*PeerStateFilter, error)

NewPeerStateFilter takes the HTTP query parameters and creates a cache.Filter, filtering according to the query parameters passed. Query parameters used are `hc`, `stats`, `wildcard`, `typep`, and `hosts`. The `stats` param filters caches. The `hosts` param filters peer Traffic Monitors. The `type` param filters cache types (edge, mid). If `hc` is 0, all history is returned. If `hc` is empty, 1 history is returned. If `stats` is empty, all stats are returned. If `wildcard` is empty, `stats` is considered exact. If `type` is empty, all cache types are returned.

func (*PeerStateFilter) UseCache

func (f *PeerStateFilter) UseCache(name tc.CacheName) bool

UseCache returns whether the given cache is in this filter.

func (*PeerStateFilter) UsePeer

func (f *PeerStateFilter) UsePeer(name tc.TrafficMonitorName) bool

UsePeer returns whether the given Traffic Monitor peer is in this filter.

func (*PeerStateFilter) WithinStatHistoryMax

func (f *PeerStateFilter) WithinStatHistoryMax(n int) bool

WithinStatHistoryMax returns whether the given history index is less than the max history of this filter.

type SrvFunc

type SrvFunc func(params url.Values, path string) ([]byte, int)

SrvFunc is a function which takes URL parameters, and returns the requested data, and a response code. Note it does not take the full http.Request, and does not have the path. SrvFunc functions should be called via dispatch, and any additional data needed should be closed via a lambda. TODO split params and path into 2 separate wrappers? TODO change to simply take the http.Request?

type StatSummary

type StatSummary struct {
	Caches map[string]CacheStatSummary `json:"caches"`
	tc.CommonAPIData
}

type StatSummaryStat

type StatSummaryStat struct {
	// Average is the stat's value's arithmetic mean within the time period.
	Average float64 `json:"average"`
	// DataPointCount is the number of measurements of the stat that have been
	// cataloged in the stat's history.
	DataPointCount int64 `json:"dpCount"`
	// End is the final value of the stat at the time of the most recent
	// measurement.
	End float64 `json:"end"`
	// EndTime is the time of the most recent measurement, and defines the end
	// point of the time period.
	EndTime int64 `json:"endTime"`
	// High is the stat's maximum value within the time period.
	High float64 `json:"high"`
	// Low is the stat's minimum value within the time period.
	Low float64 `json:"low"`
	// Start is the initial value of the stat at the time of the first
	// measurement.
	Start float64 `json:"start"`
	// StartTime is the time of the first measurement, and defines the beginning
	// of the time period.
	StartTime int64 `json:"startTime"`
}

StatSummaryStat represents a summary of a stat's values and changes over a period of time.

type Stats

type Stats struct {
	MaxMemoryMB                 uint64  `json:"Max Memory (MB),string"`
	GitRevision                 string  `json:"git-revision"`
	ErrorCount                  uint64  `json:"Error Count,string"`
	Uptime                      uint64  `json:"uptime,string"`
	FreeMemoryMB                uint64  `json:"Free Memory (MB),string"`
	TotalMemoryMB               uint64  `json:"Total Memory (MB),string"`
	Version                     string  `json:"version"`
	DeployDir                   string  `json:"deploy-dir"`
	FetchCount                  uint64  `json:"Fetch Count,string"`
	QueryIntervalDelta          int     `json:"Query Interval Delta,string"`
	IterationCount              uint64  `json:"Iteration Count,string"`
	Name                        string  `json:"name"`
	BuildTimestamp              string  `json:"buildTimestamp"`
	QueryIntervalTarget         int     `json:"Query Interval Target,string"`
	QueryIntervalActual         int     `json:"Query Interval Actual,string"`
	SlowestCache                string  `json:"Slowest Cache"`
	LastQueryInterval           int     `json:"Last Query Interval,string"`
	Microthreads                int     `json:"Goroutines"`
	LastGC                      string  `json:"Last Garbage Collection"`
	MemAllocBytes               uint64  `json:"Memory Bytes Allocated"`
	MemTotalBytes               uint64  `json:"Total Bytes Allocated"`
	MemSysBytes                 uint64  `json:"System Bytes Allocated"`
	OldestPolledPeer            string  `json:"Oldest Polled Peer"`
	OldestPolledPeerMs          int64   `json:"Oldest Polled Peer Time (ms)"`
	QueryInterval95thPercentile int64   `json:"Query Interval 95th Percentile (ms)"`
	GCCPUFraction               float64 `json:"gc-cpu-fraction"`
}

Stats contains statistics data about this running app. Designed to be returned via an API endpoint.

Jump to

Keyboard shortcuts

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