report

package
v0.0.0-...-2318bba Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

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

type Collector interface {
	Collect(context.Context, Report) error
}

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

type RemoteCollector struct {
	HttpClient   *http.Client
	CollectorURL *url.URL
}

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 Report

type Report any

Report is an alias for any type of report.

type RetryCollector

type RetryCollector struct {
	Collector    Collector
	MaxRetry     int
	InitialDelay time.Duration
}

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

type WriteCollector struct {
	Writer io.Writer
}

WriteCollector represents a collector that writes the report to an io.Writer.

func (*WriteCollector) Collect

func (c *WriteCollector) Collect(ctx context.Context, report Report) error

Collect writes the report to the underlying io.Writer. It returns an error if there was a problem writing the report.

Jump to

Keyboard shortcuts

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