requests

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeSeriePointToTime added in v0.3.0

func TimeSeriePointToTime(v uint64) time.Time

Types

type ByteContent

type ByteContent struct {
	Content     []byte `json:"content,omitempty"`
	ContentType string `json:"contentType,omitempty"`
}

func (ByteContent) MarshalJSON

func (c ByteContent) MarshalJSON() ([]byte, error)

type ByteHashMap

type ByteHashMap map[[32]byte]ByteContent

func (ByteHashMap) Add

func (bm ByteHashMap) Add(contentType string, body []byte) *Hash

func (ByteHashMap) MarshalJSON

func (c ByteHashMap) MarshalJSON() ([]byte, error)

type CompactRequestStatistics

type CompactRequestStatistics struct {
	Stats
	// required: true
	StartTime         time.Time
	TotalRequests     int `json:"total_requests"`
	CompletedRequests int `json:"completed_requests`
	RunID             string
	TimeSeries        *TimeSeriesMap
	ResponseHashMap   ByteHashMap `json:"response_hash_map,omitempty"`
	Requests          map[ErrorType]CompactStat
}

func NewCompactRequestStatistics

func NewCompactRequestStatistics(runID string, ts *TimeSeriesMap) CompactRequestStatistics

func (*CompactRequestStatistics) AddStat

func (rs *CompactRequestStatistics) AddStat(stat RequestStat)

This is only for use will the original RequestStat

func (*CompactRequestStatistics) Calculate

func (rs *CompactRequestStatistics) Calculate()

func (*CompactRequestStatistics) RecalculateAll

func (rs *CompactRequestStatistics) RecalculateAll()

type CompactStat

type CompactStat struct {
	ErrorType    `json:"errorType,omitempty"`
	ResponseHash *Hash  `json:"response_hash,omitempty"`
	StatusCode   int16  `json:"status_code,omitempty"`
	Error        string `json:"error,omitempty"`
}

type Durationable

type Durationable time.Duration

type Endpoint

type Endpoint struct {
	// Required: true
	Url     string      `json:"url,omitempty"`
	Headers http.Header `json:"headers,omitempty"`
	// contains filtered or unexported fields
}

func NewEndpoint

func NewEndpoint(l logger.AppLogger, url string, ts TimeSeriePusher) Endpoint

func NewEndpointWithClient

func NewEndpointWithClient(l logger.AppLogger, url string, ts TimeSeriePusher, client HttpClient) Endpoint

func NewMockedEndpoint

func NewMockedEndpoint(l logger.AppLogger, url string) Endpoint

func (*Endpoint) DoRequest

func (g *Endpoint) DoRequest(l logger.AppLogger, r *http.Request, stat RequestStat, okStatusCodes []int) (*http.Response, RequestStat, error)

func (*Endpoint) RunQuery

func (g *Endpoint) RunQuery(startTime time.Time, query Request, okStatusCodes []int) (*http.Response, RequestStat, error)

type Error

type Error struct {
	Message string `json:"message"`
}

type ErrorType

type ErrorType string
var (
	GQLError        ErrorType = "GQLError"
	NonOK           ErrorType = "NonOK"
	ServerTestError ErrorType = "ServerTestError"
	Unknwon         ErrorType = "UnknownError"
)

type GqlResponse

type GqlResponse struct {
	Errors []Error                `json:"errors,omitempty"`
	Data   map[string]interface{} `json:"data,omitempty"`
}

type Hash

type Hash [32]byte

func (Hash) MarshalJSON

func (c Hash) MarshalJSON() ([]byte, error)

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type MockHttpClient

type MockHttpClient struct{}

func (MockHttpClient) Do

func (m MockHttpClient) Do(req *http.Request) (*http.Response, error)

type Request

type Request struct {
	// Will only be used if Query is unset.
	Body      interface{}            `json:"body,omitempty"`
	Query     string                 `json:"query,omitempty"`
	Variables map[string]interface{} `json:"variables,omitempty"`
	Headers   map[string]string      `json:"-"`
	// For some reason, the server does not like operationName.
	OperationName string `json:"operationName,omitempty"` //`json:"operationName"`
	Method        string `json:"method,omitempty"`
}

type RequestStat

type RequestStat struct {
	ErrorType   `json:"errorType,omitempty"`
	RawResponse []byte    `json:"rawResponse,omitempty"`
	ContentType string    `json:"-"`
	Start       time.Time `json:"-"`
	RequestID   string
	Duration    time.Duration `json:"duration,omitempty"`
	CompactStat
	// contains filtered or unexported fields
}

func NewStat

func NewStat(offset time.Duration, ts TimeSeriePusher) RequestStat

func (*RequestStat) End

func (r *RequestStat) End(body []byte, errorType ErrorType, err error) RequestStat

type RequestStats

type RequestStats []RequestStat

func (RequestStats) Calculate

func (r RequestStats) Calculate() Stats

type Serie added in v0.3.0

type Serie [2]uint64

type Stats

type Stats struct {
	Total   time.Duration
	Min     time.Duration
	Max     time.Duration
	Average time.Duration
}

func (*Stats) MarshalJSON

func (c *Stats) MarshalJSON() ([]byte, error)

type TimeSeriePusher added in v0.3.0

type TimeSeriePusher interface {
	Push(label string, t time.Time, v float64)
}

type TimeSeries added in v0.3.0

type TimeSeries struct {
	tsz.Series
}

func NewTimeSeries added in v0.3.0

func NewTimeSeries(startTime time.Time) *TimeSeries

func (*TimeSeries) Expand added in v0.3.0

func (ts *TimeSeries) Expand() *TimeSeriesExpanded

func (*TimeSeries) Push added in v0.3.0

func (ts *TimeSeries) Push(t time.Time, v float64)

Each push must be in order!

type TimeSeriesExpanded added in v0.3.0

type TimeSeriesExpanded struct {
	StartTime time.Time
	Series    []Serie
}

func (TimeSeriesExpanded) DropResolution added in v0.3.0

func (tse TimeSeriesExpanded) DropResolution(maxResolution int) TimeSeriesExpanded

This is probably terrible for performance, but still better than serving 500000 items to the client... With a real timeseries-database this kind of operation would be a lot less expensive

type TimeSeriesMap added in v0.3.0

type TimeSeriesMap struct {
	Map       map[string]*TimeSeries
	StartTime time.Time
	// contains filtered or unexported fields
}

func NewTimeSeriesWithLabel added in v0.3.0

func NewTimeSeriesWithLabel(startTime time.Time) TimeSeriesMap

func (*TimeSeriesMap) Expand added in v0.3.0

func (tsm *TimeSeriesMap) Expand() map[string]*TimeSeriesExpanded

func (*TimeSeriesMap) MarshalJSON added in v0.3.0

func (s *TimeSeriesMap) MarshalJSON() ([]byte, error)

func (*TimeSeriesMap) Push added in v0.3.0

func (tsm *TimeSeriesMap) Push(label string, t time.Time, value float64)

Jump to

Keyboard shortcuts

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