rest

package
v0.0.0-...-298dde5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout - default REST timeout is 10 seconds.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// HealthCheckFn is the function set to test for health.
	// If not set the client will not keep track of health.
	// Calling this returns true or false if the target
	// is online or offline.
	HealthCheckFn func() bool

	// HealthCheckInterval will be the duration between re-connection attempts
	// when a call has failed with a network error.
	HealthCheckInterval time.Duration

	// HealthCheckTimeout determines timeout for each call.
	HealthCheckTimeout time.Duration

	// MaxErrResponseSize is the maximum expected response size.
	// Should only be modified before any calls are made.
	MaxErrResponseSize int64

	// ExpectTimeouts indicates if context timeouts are expected.
	// This will not mark the client offline in these cases.
	ExpectTimeouts bool

	// Avoid metrics update if set to true
	NoMetrics bool

	sync.RWMutex // mutex for lastErr
	// contains filtered or unexported fields
}

Client - http based RPC client.

func NewClient

func NewClient(url *url.URL, tr http.RoundTripper, newAuthToken func(aud string) string) *Client

NewClient - returns new REST client.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (reply io.ReadCloser, err error)

Call - make a REST call with context.

func (*Client) Close

func (c *Client) Close()

Close closes all idle connections of the underlying http client

func (*Client) IsOnline

func (c *Client) IsOnline() bool

IsOnline returns whether the client is likely to be online.

func (*Client) LastConn

func (c *Client) LastConn() time.Time

LastConn returns when the disk was (re-)connected

func (*Client) LastError

func (c *Client) LastError() error

LastError returns previous error

func (*Client) MarkOffline

func (c *Client) MarkOffline(err error) bool

MarkOffline - will mark a client as being offline and spawns a goroutine that will attempt to reconnect if HealthCheckFn is set. returns true if the node changed state from online to offline

type NetworkError

type NetworkError struct {
	Err error
}

NetworkError - error type in case of errors related to http/transport for ex. connection refused, connection reset, dns resolution failure etc. All errors returned by storage-rest-server (ex errFileNotFound, errDiskNotFound) are not considered to be network errors.

func (*NetworkError) Error

func (n *NetworkError) Error() string

func (*NetworkError) Unwrap

func (n *NetworkError) Unwrap() error

Unwrap returns the error wrapped in NetworkError.

type RPCStats

type RPCStats struct {
	Errs uint64

	DialAvgDuration uint64
	DialErrs        uint64
}

RPCStats holds information about the DHCP/TCP metrics and errors

func GetRPCStats

func GetRPCStats() RPCStats

GetRPCStats returns RPC stats, include calls errors and dhcp/tcp metrics

Jump to

Keyboard shortcuts

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