xhttp

package
v0.81.8 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

README

xhttp

Internal HTTP client used by output plugins that talk to remote HTTP services (elasticsearch, http, loki, splunk). Built on top of fasthttp

Circuit breaker

Helps multi-endpoint output plugins keep sending data when some endpoints are down. Failed endpoints are marked as banned for a while so requests stop going to them, and get unbanned automatically after ban period.

Ban and restore

Client keeps full and live endpoint lists. getEndpoint picks random endpoint from live list.

If request fails with network error or HTTP 429, 502, 503, 504, endpoint is removed from the available list and marked as "banned until now + ban_period".

Background goroutine runs every reconnect_interval and restores endpoints with expired ban period.

All endpoints banned

getEndpoint doesn't return nil. Round-robins over all endpoints including banned. Banned endpoint may be back up, so trying it may succeed before restore tick. Ban stays, restore loop removes it after ban_period.

Disabled circuit breaker

The breaker is off when:

  • ban_period = 0
  • single endpoint is configured

Configuration

Configured via output plugin that uses xhttp.

ban_period duration default=10s

Period for which addresses will be banned in case of unavailability.


reconnect_interval duration default=5s

Interval for checking banned endpoints.


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error)

func (*Client) DoTimeout

func (c *Client) DoTimeout(
	method, contentType string,
	body []byte,
	timeout time.Duration,
	processResponse func([]byte) error,
) (int, error)

type ClientConfig

type ClientConfig struct {
	Endpoints             []string
	ConnectionTimeout     time.Duration
	AuthHeader            string
	CustomHeaders         map[string]string
	GzipCompressionLevel  string
	TLS                   *ClientTLSConfig
	KeepAlive             *ClientKeepAliveConfig
	BanPeriod             time.Duration
	ReconnectInterval     time.Duration
	Logger                *zap.Logger
	BannedEndpointsMetric *metric.Gauge
}

type ClientKeepAliveConfig

type ClientKeepAliveConfig struct {
	MaxConnDuration     time.Duration
	MaxIdleConnDuration time.Duration
}

type ClientTLSConfig

type ClientTLSConfig struct {
	CACert             string
	InsecureSkipVerify bool
}

Jump to

Keyboard shortcuts

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