net

package
v2.10.0-dev Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxRetries is the default number of retries for a request.
	DefaultMaxRetries int = 3
	// DefaultBackoff is the default backoff time for a request.
	DefaultBackoff time.Duration = 100 * time.Millisecond
)
View Source
const (
	ContentTypeJSON            = "application/json"
	ContentTypeJSONAlternative = "application/vnd.api+json"
	ContentTypeOctetStream     = "application/octet-stream"
	ContentTypeMessagePack     = "application/msgpack"
	ContentEncodingGzip        = "gzip"
	HeaderContentType          = "Content-Type"
	HeaderContentEncoding      = "Content-Encoding"
	HeaderAcceptEncoding       = "Accept-Encoding"
	HeaderRateLimitReset       = "x-ratelimit-reset"
	HTTPStatusTooManyRequests  = 429
	FormatJSON                 = "json"
	FormatMessagePack          = "msgpack"
)

Constants for common strings

Variables

This section is empty.

Functions

func CloseIdleConnections added in v2.9.0

func CloseIdleConnections()

CloseIdleConnections closes idle connections owned by the shared CI Visibility HTTP client. It is safe to call during shutdown after CI Visibility components have finished sending their final payloads.

Types

type Client

type Client interface {
	GetSettings() (*SettingsResponseData, error)
	GetKnownTests() (*KnownTestsResponseData, error)
	GetCommits(localCommits []string) ([]string, error)
	SendPackFiles(commitSha string, packFiles []string) (bytes int64, err error)
	SendCoveragePayload(ciTestCovPayload io.Reader) error
	SendCoveragePayloadWithFormat(ciTestCovPayload io.Reader, format string) error
	GetSkippableTests() (correlationID string, skippables map[string]map[string][]SkippableResponseDataAttributes, err error)
	GetTestManagementTests() (*TestManagementTestsResponseDataModules, error)
	SendLogs(logsPayload io.Reader) error
}

Client is an interface for sending requests to the Datadog backend.

func NewClient

func NewClient() Client

NewClient creates a new client with the default service name.

func NewClientForCodeCoverage

func NewClientForCodeCoverage() Client

NewClientForCodeCoverage creates a new client for sending code coverage payloads.

func NewClientForLogs added in v2.1.0

func NewClientForLogs() Client

NewClientForLogs creates a new client for sending logs payloads.

func NewClientWithServiceName

func NewClientWithServiceName(serviceName string) Client

NewClientWithServiceName creates a new client with the given service name.

func NewClientWithServiceNameAndSubdomain

func NewClientWithServiceNameAndSubdomain(serviceName, subdomain string) Client

NewClientWithServiceNameAndSubdomain creates a new client with the given service name and subdomain.

type FormFile

type FormFile struct {
	FieldName   string // The name of the form field
	FileName    string // The name of the file
	Content     any    // The content of the file (can be []byte, map, struct, etc.)
	ContentType string // The MIME type of the file (e.g., "application/json", "application/octet-stream")
}

FormFile represents a file to be uploaded in a multipart form request.

type KnownTestsRequestData

type KnownTestsRequestData struct {
	Service        string             `json:"service"`
	Env            string             `json:"env"`
	RepositoryURL  string             `json:"repository_url"`
	Configurations testConfigurations `json:"configurations"`
}

type KnownTestsResponseData

type KnownTestsResponseData struct {
	Tests KnownTestsResponseDataModules `json:"tests"`
}

type KnownTestsResponseDataModules

type KnownTestsResponseDataModules map[string]KnownTestsResponseDataSuites

type KnownTestsResponseDataSuites

type KnownTestsResponseDataSuites map[string][]string

type RequestConfig

type RequestConfig struct {
	Method     string            // HTTP method: GET or POST
	URL        string            // Request URL
	Headers    map[string]string // Additional HTTP headers
	Body       any               // Request body for JSON, MessagePack, or raw bytes
	Format     string            // Format: "json" or "msgpack"
	Compressed bool              // Whether to use gzip compression
	Files      []FormFile        // Files to be uploaded in a multipart form data request
	MaxRetries int               // Maximum number of retries
	Backoff    time.Duration     // Initial backoff duration for retries
}

RequestConfig holds configuration for a request.

type RequestHandler

type RequestHandler struct {
	Client *http.Client
}

RequestHandler handles HTTP requests with retries and different formats.

func NewRequestHandler

func NewRequestHandler() *RequestHandler

NewRequestHandler creates a new RequestHandler with a default HTTP client.

func NewRequestHandlerWithClient

func NewRequestHandlerWithClient(client *http.Client) *RequestHandler

NewRequestHandlerWithClient creates a new RequestHandler with a custom http.Client

func (*RequestHandler) CloseIdleConnections added in v2.9.0

func (rh *RequestHandler) CloseIdleConnections()

CloseIdleConnections closes idle connections owned by the request handler's HTTP client. Active requests are left running by the standard library.

func (*RequestHandler) SendRequest

func (rh *RequestHandler) SendRequest(config RequestConfig) (*Response, error)

SendRequest sends an HTTP request based on the provided configuration.

type Response

type Response struct {
	Body         []byte // Response body in raw format
	Format       string // Format of the response (json or msgpack)
	StatusCode   int    // HTTP status code
	CanUnmarshal bool   // Whether the response body can be unmarshalled
	Compressed   bool   // Whether to use gzip compression
}

Response represents the HTTP response with deserialization capabilities and status code.

func (*Response) Unmarshal

func (r *Response) Unmarshal(target any) error

Unmarshal deserializes the response body into the provided target based on the response format.

type SettingsRequestData

type SettingsRequestData struct {
	Service        string             `json:"service,omitempty"`
	Env            string             `json:"env,omitempty"`
	RepositoryURL  string             `json:"repository_url,omitempty"`
	Branch         string             `json:"branch,omitempty"`
	Sha            string             `json:"sha,omitempty"`
	Configurations testConfigurations `json:"configurations"`
}

type SettingsResponseData

type SettingsResponseData struct {
	CodeCoverage        bool `json:"code_coverage"`
	EarlyFlakeDetection struct {
		Enabled         bool `json:"enabled"`
		SlowTestRetries struct {
			TenS    int `json:"10s"`
			ThirtyS int `json:"30s"`
			FiveM   int `json:"5m"`
			FiveS   int `json:"5s"`
		} `json:"slow_test_retries"`
		FaultySessionThreshold int `json:"faulty_session_threshold"`
	} `json:"early_flake_detection"`
	FlakyTestRetriesEnabled bool `json:"flaky_test_retries_enabled"`
	ItrEnabled              bool `json:"itr_enabled"`
	RequireGit              bool `json:"require_git"`
	TestsSkipping           bool `json:"tests_skipping"`
	KnownTestsEnabled       bool `json:"known_tests_enabled"`
	ImpactedTestsEnabled    bool `json:"impacted_tests_enabled"`
	TestManagement          struct {
		Enabled             bool `json:"enabled"`
		AttemptToFixRetries int  `json:"attempt_to_fix_retries"`
	} `json:"test_management"`
	SubtestFeaturesEnabled bool `json:"-"`
}

type SkippableResponseDataAttributes

type SkippableResponseDataAttributes struct {
	Suite          string             `json:"suite"`
	Name           string             `json:"name"`
	Parameters     string             `json:"parameters"`
	Configurations testConfigurations `json:"configurations"`
}

type TestManagementTestsResponseDataModules

type TestManagementTestsResponseDataModules struct {
	Modules map[string]TestManagementTestsResponseDataSuites `json:"modules"`
}

type TestManagementTestsResponseDataSuites

type TestManagementTestsResponseDataSuites struct {
	Suites map[string]TestManagementTestsResponseDataTests `json:"suites"`
}

type TestManagementTestsResponseDataTestProperties

type TestManagementTestsResponseDataTestProperties struct {
	Properties TestManagementTestsResponseDataTestPropertiesAttributes `json:"properties"`
}

type TestManagementTestsResponseDataTestPropertiesAttributes

type TestManagementTestsResponseDataTestPropertiesAttributes struct {
	Quarantined  bool `json:"quarantined"`
	Disabled     bool `json:"disabled"`
	AttemptToFix bool `json:"attempt_to_fix"`
}

type TestManagementTestsResponseDataTests

type TestManagementTestsResponseDataTests struct {
	Tests map[string]TestManagementTestsResponseDataTestProperties `json:"tests"`
}

Jump to

Keyboard shortcuts

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