Documentation ¶
Overview ¶
Package transaction defines the transaction of the forwarder
Index ¶
- Constants
- Variables
- func GetClientTrace(log log.Component) *httptrace.ClientTrace
- type BytesPayload
- type BytesPayloads
- type Destination
- type Endpoint
- type HTTPAttemptHandler
- type HTTPCompletionHandler
- type HTTPTransaction
- func (t *HTTPTransaction) GetCreatedAt() time.Time
- func (t *HTTPTransaction) GetDestination() Destination
- func (t *HTTPTransaction) GetEndpointName() string
- func (t *HTTPTransaction) GetKind() Kind
- func (t *HTTPTransaction) GetPayloadSize() int
- func (t *HTTPTransaction) GetPointCount() int
- func (t *HTTPTransaction) GetPriority() Priority
- func (t *HTTPTransaction) GetTarget() string
- func (t *HTTPTransaction) Process(ctx context.Context, config config.Component, log log.Component, ...) error
- func (t *HTTPTransaction) SerializeTo(log log.Component, serializer TransactionsSerializer) error
- func (t *HTTPTransaction) SetDefaultHandlers()
- type Kind
- type Priority
- type SortByCreatedTimeAndPriority
- type Transaction
- type TransactionsSerializer
Constants ¶
const ( // Series is the transaction type for metrics series Series = iota // Sketches is the transaction type for distribution sketches Sketches // ServiceChecks is the transaction type for service checks ServiceChecks // Events is the transaction type for events Events // CheckRuns is the transaction type for agent check runs CheckRuns // Metadata is the transaction type for metadata payloads Metadata // Process is the transaction type for live-process monitoring payloads Process )
const ( // AllRegions indicates the transaction should be sent to all regions (default behavior) AllRegions = iota // PrimaryOnly indicates the transaction should be sent to the primary region during MRF PrimaryOnly // SecondaryOnly indicates the transaction should be sent to the secondary region during MRF SecondaryOnly )
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") )
Functions ¶
func GetClientTrace ¶
func GetClientTrace(log log.Component) *httptrace.ClientTrace
GetClientTrace is an httptrace.ClientTrace instance that traces the events within HTTP client requests.
Types ¶
type BytesPayload ¶
type BytesPayload struct { Destination Destination // contains filtered or unexported fields }
BytesPayload is a payload stored as bytes. It contains metadata about the payload.
func NewBytesPayload ¶
func NewBytesPayload(payload []byte, pointCount int) *BytesPayload
NewBytesPayload creates a new instance of BytesPayload.
func NewBytesPayloadWithoutMetaData ¶
func NewBytesPayloadWithoutMetaData(payload []byte) *BytesPayload
NewBytesPayloadWithoutMetaData creates a new instance of BytesPayload without metadata.
func (*BytesPayload) GetContent ¶
func (p *BytesPayload) GetContent() []byte
GetContent returns the content of the payload
func (*BytesPayload) GetPointCount ¶
func (p *BytesPayload) GetPointCount() int
GetPointCount returns the number of points in this payload
func (*BytesPayload) Len ¶
func (p *BytesPayload) Len() int
Len returns the length as bytes of the payload
type BytesPayloads ¶
type BytesPayloads []*BytesPayload
BytesPayloads is a collection of BytesPayload
func NewBytesPayloadsWithoutMetaData ¶
func NewBytesPayloadsWithoutMetaData(payloads []*[]byte) BytesPayloads
NewBytesPayloadsWithoutMetaData creates BytesPayloads without metadata.
type Destination ¶ added in v0.56.0
type Destination int
Destination indicates which regions the transaction should be sent to
func (Destination) String ¶ added in v0.56.0
func (d Destination) String() string
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 *BytesPayload // 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 Kind Kind Destination Destination }
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) GetDestination ¶ added in v0.56.0
func (t *HTTPTransaction) GetDestination() Destination
GetDestination returns the region(s) this transaction should be sent to.
func (*HTTPTransaction) GetEndpointName ¶
func (t *HTTPTransaction) GetEndpointName() string
GetEndpointName returns the name of the endpoint used by the transaction
func (*HTTPTransaction) GetKind ¶
func (t *HTTPTransaction) GetKind() Kind
GetKind returns the transaction kind
func (*HTTPTransaction) GetPayloadSize ¶
func (t *HTTPTransaction) GetPayloadSize() int
GetPayloadSize returns the size of the payload.
func (*HTTPTransaction) GetPointCount ¶
func (t *HTTPTransaction) GetPointCount() int
GetPointCount gets the number of points in the payload of this transaction.
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 ¶
func (t *HTTPTransaction) Process(ctx context.Context, config config.Component, log log.Component, client *http.Client) error
Process sends the Payload of the transaction to the right Endpoint and Domain.
func (*HTTPTransaction) SerializeTo ¶
func (t *HTTPTransaction) SerializeTo(log log.Component, 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, config config.Component, log log.Component, client *http.Client) error GetCreatedAt() time.Time GetTarget() string GetPriority() Priority GetKind() Kind GetEndpointName() string GetPayloadSize() int GetPointCount() int GetDestination() Destination // 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(log.Component, TransactionsSerializer) error }
Transaction represents the task to process for a Worker.
type TransactionsSerializer ¶
type TransactionsSerializer interface {
Add(transaction *HTTPTransaction) error
}
TransactionsSerializer serializes Transaction instances.