Documentation ¶
Overview ¶
Package report provides functionality for collecting and sending reports.
It defines the behavior of a report collector and provides implementations of the Collector interface. It also defines a report type and a HasSuccess interface that is implemented by the report type. The report type is used to represent a connectivity test report. The HasSuccess interface is used to determine the success status of a report. This will be used to control SamplingCollector behavior. The report package also defines a BadRequestError type that is used to represent an error that occurs when a sending the report to remote collector fails.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadRequestError ¶
type BadRequestError struct {
Err error
}
BadRequestError represents an error that occurs when a request fails.
func (BadRequestError) Error ¶
func (e BadRequestError) Error() string
Error returns the error message associated with the BadRequestError.
func (BadRequestError) Unwrap ¶
func (e BadRequestError) Unwrap() error
Unwrap returns the underlying error wrapped by the BadRequestError.
type Collector ¶
Collector is an interface that defines the behavior of a report collector. Implementations of this interface should be able to collect a report in a given context.
type FallbackCollector ¶
type FallbackCollector struct {
Collectors []Collector
}
FallbackCollector is a type that represents a collector that falls back to multiple collectors.
func (*FallbackCollector) Collect ¶
func (c *FallbackCollector) Collect(ctx context.Context, report Report) error
Collect implements Collector interface on FallbackCollector type that collects a report using the provided context and report data. It iterates over a list of collectors and attempts to collect the report using each collector. If any of the collectors succeeds in collecting the report, operation aborts, and it returns nil. If all collectors fail to collect the report, it returns an error indicating the failure.
type HasSuccess ¶
type HasSuccess interface {
IsSuccess() bool
}
HasSuccess is an interface that represents an object that has a success status.
type RemoteCollector ¶
RemoteCollector represents a collector that communicates with a remote endpoint.
func (*RemoteCollector) Collect ¶
func (c *RemoteCollector) Collect(ctx context.Context, report Report) error
Collect sends the given report to the remote collector. It marshals the report into JSON format and sends it using the [sendReport] method. If there is an error encoding the JSON or sending the report, it returns the error. Otherwise, it returns nil.
type RetryCollector ¶
RetryCollector represents a collector that supports retrying failed operations.
func (*RetryCollector) Collect ¶
func (c *RetryCollector) Collect(ctx context.Context, report Report) error
Collect collects the report by making multiple attempts with retries. It uses the provided context and report to call the underlying collector's [Collect] method. If a BadRequestError is encountered during the collection, it breaks the retry loop. It sleeps for a specified duration between retries. Returns an error if the maximum number of retries is exceeded.
type SamplingCollector ¶
type SamplingCollector struct { Collector Collector SuccessFraction float64 FailureFraction float64 }
SamplingCollector represents a collector that randomly samples and collects a report.
func (*SamplingCollector) Collect ¶
func (c *SamplingCollector) Collect(ctx context.Context, report Report) error
Collect collects the given report based on the sampling rate defined in the SamplingCollector. It checks if the report implements the HasSuccess interface and determines the sampling rate based on the success status. If the randomly generated number is less than the sampling rate, the report is collected using the underlying collector. Otherwise, the report is not sent. It returns an error if there is an issue collecting the report. Sampling rate of 1.0 means report is always sent, and 0.0 means report is never sent.
type WriteCollector ¶
WriteCollector represents a collector that writes the report to an io.Writer.