Documentation ¶
Index ¶
- Variables
- type Endpoint
- type HTTPAttemptHandler
- type HTTPCompletionHandler
- type HTTPTransaction
- func (t *HTTPTransaction) GetCreatedAt() time.Time
- func (t *HTTPTransaction) GetEndpointName() string
- func (t *HTTPTransaction) GetPayloadSize() int
- func (t *HTTPTransaction) GetPriority() Priority
- func (t *HTTPTransaction) GetTarget() string
- func (t *HTTPTransaction) Process(ctx context.Context, client *http.Client) error
- func (t *HTTPTransaction) SerializeTo(serializer TransactionsSerializer) error
- func (t *HTTPTransaction) SetDefaultHandlers()
- type Priority
- type SortByCreatedTimeAndPriority
- type Transaction
- type TransactionsSerializer
Constants ¶
This section is empty.
Variables ¶
var ( // ForwarderExpvars is the root for expvars in the forwarder. ForwarderExpvars = expvar.NewMap("forwarder") // TransactionsExpvars the transactions Expvars TransactionsExpvars = expvar.Map{} // TransactionsDropped is the number of transaction dropped. TransactionsDropped = expvar.Int{} // TransactionsDroppedByEndpoint is the number of transaction dropped by endpoint. TransactionsDroppedByEndpoint = expvar.Map{} // TransactionsSuccessByEndpoint is the number of transaction succeeded by endpoint. TransactionsSuccessByEndpoint = expvar.Map{} // TlmTxDropped is a telemetry counter that counts the number transaction dropped. TlmTxDropped = telemetry.NewCounter("transactions", "dropped", []string{"domain", "endpoint"}, "Transaction drop count") )
var Trace = &httptrace.ClientTrace{ DNSDone: func(dnsInfo httptrace.DNSDoneInfo) { if dnsInfo.Err != nil { transactionsDNSErrors.Add(1) tlmTxErrors.Inc("unknown", "unknown", "dns_lookup_failure") log.Debugf("DNS Lookup failure: %s", dnsInfo.Err) return } connectionDNSSuccess.Add(1) tlmConnectEvents.Inc("dns_lookup_success") log.Tracef("DNS Lookup success, addresses: %s", dnsInfo.Addrs) }, WroteRequest: func(wroteInfo httptrace.WroteRequestInfo) { if wroteInfo.Err != nil { transactionsWroteRequestErrors.Add(1) tlmTxErrors.Inc("unknown", "unknown", "writing_failure") log.Debugf("Request writing failure: %s", wroteInfo.Err) } }, ConnectDone: func(network, addr string, err error) { if err != nil { transactionsConnectionErrors.Add(1) tlmTxErrors.Inc("unknown", "unknown", "connection_failure") log.Debugf("Connection failure: %s", err) return } connectionConnectSuccess.Add(1) tlmConnectEvents.Inc("connection_success") log.Tracef("New successful connection to address: %q", addr) }, TLSHandshakeDone: func(tlsState tls.ConnectionState, err error) { if err != nil { transactionsTLSErrors.Add(1) tlmTxErrors.Inc("unknown", "unknown", "tls_handshake_failure") log.Errorf("TLS Handshake failure: %s", err) } }, }
Trace is an httptrace.ClientTrace instance that traces the events within HTTP client requests.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint struct { // Route to hit in the HTTP transaction Route string // Name of the endpoint for the telemetry metrics Name string }
Endpoint is an endpoint
type HTTPAttemptHandler ¶
type HTTPAttemptHandler func(transaction *HTTPTransaction)
HTTPAttemptHandler is an event handler that will get called each time this transaction is attempted
type HTTPCompletionHandler ¶
type HTTPCompletionHandler func(transaction *HTTPTransaction, statusCode int, body []byte, err error)
HTTPCompletionHandler is an event handler that will get called after this transaction has completed
type HTTPTransaction ¶
type HTTPTransaction struct { // Domain represents the domain target by the HTTPTransaction. Domain string // Endpoint is the API Endpoint used by the HTTPTransaction. Endpoint Endpoint // Headers are the HTTP headers used by the HTTPTransaction. Headers http.Header // Payload is the content delivered to the backend. Payload *[]byte // ErrorCount is the number of times this HTTPTransaction failed to be processed. ErrorCount int CreatedAt time.Time // Retryable indicates whether this transaction can be retried Retryable bool // StorableOnDisk indicates whether this transaction can be stored on disk StorableOnDisk bool // AttemptHandler will be called with a transaction before the attempting to send the request // This field is not restored when a transaction is deserialized from the disk (the default value is used). AttemptHandler HTTPAttemptHandler // CompletionHandler will be called with a transaction after it has been successfully sent // This field is not restored when a transaction is deserialized from the disk (the default value is used). CompletionHandler HTTPCompletionHandler Priority Priority }
HTTPTransaction represents one Payload for one Endpoint on one Domain.
func NewHTTPTransaction ¶
func NewHTTPTransaction() *HTTPTransaction
NewHTTPTransaction returns a new HTTPTransaction.
func (*HTTPTransaction) GetCreatedAt ¶
func (t *HTTPTransaction) GetCreatedAt() time.Time
GetCreatedAt returns the creation time of the HTTPTransaction.
func (*HTTPTransaction) GetEndpointName ¶
func (t *HTTPTransaction) GetEndpointName() string
GetEndpointName returns the name of the endpoint used by the transaction
func (*HTTPTransaction) GetPayloadSize ¶
func (t *HTTPTransaction) GetPayloadSize() int
GetPayloadSize returns the size of the payload.
func (*HTTPTransaction) GetPriority ¶
func (t *HTTPTransaction) GetPriority() Priority
GetPriority returns the priority
func (*HTTPTransaction) GetTarget ¶
func (t *HTTPTransaction) GetTarget() string
GetTarget return the url used by the transaction
func (*HTTPTransaction) Process ¶
Process sends the Payload of the transaction to the right Endpoint and Domain.
func (*HTTPTransaction) SerializeTo ¶
func (t *HTTPTransaction) SerializeTo(serializer TransactionsSerializer) error
SerializeTo serializes the transaction using TransactionsSerializer
func (*HTTPTransaction) SetDefaultHandlers ¶
func (t *HTTPTransaction) SetDefaultHandlers()
SetDefaultHandlers sets the default handlers for AttemptHandler and CompletionHandler
type Priority ¶
type Priority int
Priority defines the priority of a transaction Transactions with priority `TransactionPriorityNormal` are dropped from the retry queue before dropping transactions with priority `TransactionPriorityHigh`.
type SortByCreatedTimeAndPriority ¶
type SortByCreatedTimeAndPriority struct {
HighPriorityFirst bool
}
SortByCreatedTimeAndPriority sorts transactions by creation time and priority
func (SortByCreatedTimeAndPriority) Sort ¶
func (s SortByCreatedTimeAndPriority) Sort(transactions []Transaction)
Sort sorts transactions by creation time and priority
type Transaction ¶
type Transaction interface { Process(ctx context.Context, client *http.Client) error GetCreatedAt() time.Time GetTarget() string GetPriority() Priority GetEndpointName() string GetPayloadSize() int // This method serializes the transaction to `TransactionsSerializer`. // It forces a new implementation of `Transaction` to define how to // serialize the transaction to `TransactionsSerializer` as a `Transaction` // must be serializable in domainForwarder. SerializeTo(TransactionsSerializer) error }
Transaction represents the task to process for a Worker.
type TransactionsSerializer ¶
type TransactionsSerializer interface {
Add(transaction *HTTPTransaction) error
}
TransactionsSerializer serializes Transaction instances.