Documentation
¶
Overview ¶
Package fluent sends structured events using Fluent Forward Protocol v1.
A Client owns its connection, retry loop, bounded buffer, and batching worker. Send waits for delivery. Submit and TrySubmit transfer ownership of encoded entries to the client and return a Receipt for the eventual result.
Index ¶
- Variables
- type Auth
- type BufferConfig
- type Client
- func (c *Client) Abort()
- func (c *Client) Flush(ctx context.Context) error
- func (c *Client) Send(ctx context.Context, tag string, entries ...Entry) error
- func (c *Client) Shutdown(ctx context.Context) error
- func (c *Client) Stats() Stats
- func (c *Client) Submit(ctx context.Context, tag string, entries ...Entry) (*Receipt, error)
- func (c *Client) TrySubmit(tag string, entries ...Entry) (*Receipt, error)
- type Config
- type Connector
- type Entry
- type Error
- type Failure
- type FailureHandler
- type HeaderProvider
- type Operation
- type Option
- type PartialDeliveryError
- type Receipt
- type Record
- type RetryConfig
- type Stats
- type TLSConfig
- type TimeoutConfig
- type WebSocketConfig
- type WebSocketHandshakeError
- type WebSocketHeader
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosed = errors.New("fluent client closed") ErrQueueFull = errors.New("fluent buffer full") ErrTooLarge = errors.New("fluent request exceeds buffer limits") ErrInvalidTag = errors.New("invalid fluent tag") ErrInvalidRecord = errors.New("invalid fluent record") ErrDeliveryUnknown = errors.New("fluent delivery status unknown") ErrACKMismatch = errors.New("fluent ACK mismatch") ErrAuthRejected = errors.New("fluent authentication rejected") ErrServerVerification = errors.New("fluent server verification failed") ErrProtocol = errors.New("invalid fluent protocol message") )
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
Username string `json:"username" desc:"Username for Forward authentication"`
Password string `json:"password" desc:"Password for Forward authentication"`
Hostname string `json:"hostname" desc:"Client hostname used during Forward authentication"`
}
Auth configures the Forward Protocol shared-key handshake.
type BufferConfig ¶ added in v0.3.260716
type BufferConfig struct {
MaxEvents int `json:"max-events" desc:"Maximum number of unfinished events"`
MaxBytes int `json:"max-bytes" desc:"Maximum encoded bytes held by unfinished events"`
BatchMaxEvents int `json:"batch-max-events" desc:"Maximum number of events in one wire batch"`
BatchMaxBytes int `json:"batch-max-bytes" desc:"Maximum encoded bytes in one wire batch"`
BatchWait time.Duration `json:"batch-wait" desc:"Maximum wait for collecting an automatic batch"`
}
BufferConfig bounds accepted but unfinished work and controls automatic batching. MaxBytes counts encoded record data and protocol overhead.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a concurrency-safe Fluent Forward client.
func New ¶
New creates a lazy client. Runtime options are applied in order before final validation. The first batch establishes the connection.
func (*Client) Abort ¶ added in v0.3.260716
func (c *Client) Abort()
Abort immediately cancels in-flight work and rejects pending work. It does not wait for a custom Connector that violates context cancellation.
func (*Client) Send ¶
Send submits entries and waits for their delivery. ctx controls admission, delivery, and waiting. Synchronous requests are not combined with requests from other callers.
func (*Client) Shutdown ¶
Shutdown stops admission, drains accepted work, and closes the connection. If ctx expires, remaining work is aborted before Shutdown returns.
type Config ¶
type Config struct {
// Enabled is an application-level switch provided for config and flag
// binding. This package intentionally does not inspect it; callers decide
// whether to construct and use a Client.
Enabled bool `json:"enabled" desc:"Enable Fluent client in the calling application"`
Endpoint string `json:"endpoint" desc:"Fluent endpoint using tcp, tls, unix, ws, or wss"`
Auth *Auth `json:"auth" desc:"Forward authentication settings"`
TagPrefix string `json:"tag-prefix" desc:"Prefix added to every event tag"`
ACK bool `json:"ack" desc:"Require Forward acknowledgements"`
Buffer BufferConfig `json:"buffer" desc:"Buffer and automatic batching settings"`
Retry RetryConfig `json:"retry" desc:"Delivery retry settings"`
Timeout TimeoutConfig `json:"timeout" desc:"Connection and I/O timeout settings"`
CompressionThreshold int `json:"compression-threshold" desc:"Minimum packed bytes required for gzip compression"`
TLS TLSConfig `json:"tls" desc:"TLS and mutual TLS settings"`
WebSocket WebSocketConfig `json:"websocket" desc:"WebSocket upgrade settings"`
}
Config contains all file-friendly client settings. Endpoint selects a built-in transport using tcp, tls, unix, ws, or wss. Runtime Go objects are supplied to New through Option values.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a complete client configuration targeting Fluent's conventional local TCP endpoint. ParseConfig overlays JSON on this value so omitted fields retain their defaults.
func ParseConfig ¶ added in v0.7.260825
ParseConfig decodes a strict JSON configuration over DefaultConfig and validates the result. Durations use time.ParseDuration syntax, such as "250ms" or "3s".
type Connector ¶ added in v0.3.260716
Connector establishes a complete transport connection. Implementations must honor context cancellation for the entire connection setup.
type Entry ¶
Entry is one structured event. A zero Time is replaced once, during submission, so retries preserve the original timestamp.
type Error ¶ added in v0.3.260716
Error adds stable operation metadata while preserving the underlying error.
type Failure ¶ added in v0.3.260716
Failure describes the final failure of an asynchronously submitted request.
type FailureHandler ¶ added in v0.3.260716
type FailureHandler func(Failure)
FailureHandler observes final asynchronous delivery failures. Calls are serialized on a separate goroutine and must return promptly.
type HeaderProvider ¶ added in v0.3.260716
HeaderProvider returns headers for each WebSocket connection attempt. The returned headers override static headers with the same names.
func BearerToken ¶ added in v0.3.260716
func BearerToken(provider func(context.Context) (string, error)) HeaderProvider
BearerToken adapts a rotating token provider into a HeaderProvider.
type Operation ¶ added in v0.3.260716
type Operation string
Operation identifies the failed client operation.
type Option ¶ added in v0.3.260716
type Option interface {
// contains filtered or unexported methods
}
Option configures code-only runtime dependencies. File-friendly settings belong in Config. Options are applied in order before final validation.
func WithConnector ¶ added in v0.4.260716
WithConnector replaces the built-in Endpoint transport. Endpoint remains the error-context label. Built-in TLS, WebSocket, and NetDialer settings cannot be combined with a custom Connector.
func WithFailureHandler ¶ added in v0.3.260716
func WithFailureHandler(handler FailureHandler) Option
WithFailureHandler observes final asynchronous delivery failures.
func WithHeaderProvider ¶ added in v0.4.260716
func WithHeaderProvider(provider HeaderProvider) Option
WithHeaderProvider supplies dynamic headers for ws:// or wss:// endpoints.
func WithNetDialer ¶ added in v0.4.260716
WithNetDialer supplies a custom net.Dialer for a built-in transport.
func WithTLSConfig ¶ added in v0.4.260716
WithTLSConfig supplies a native TLS configuration for tls:// or wss:// endpoints. It cannot be combined with Config.TLS file settings.
type PartialDeliveryError ¶ added in v0.3.260716
PartialDeliveryError reports that earlier entries from one request completed before a later wire batch failed. The completed prefix must not be retried blindly in unconfirmed mode.
func (*PartialDeliveryError) Error ¶ added in v0.3.260716
func (e *PartialDeliveryError) Error() string
func (*PartialDeliveryError) Unwrap ¶ added in v0.3.260716
func (e *PartialDeliveryError) Unwrap() error
type Receipt ¶
type Receipt struct {
// contains filtered or unexported fields
}
Receipt represents the eventual result of an accepted asynchronous request.
type Record ¶ added in v0.3.260716
Record is a Forward Protocol record. Its top level is always a map with string keys; nested values must be supported by MessagePack.
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int `json:"max-attempts" desc:"Maximum number of delivery attempts"`
MinBackoff time.Duration `json:"min-backoff" desc:"Minimum delay between delivery attempts"`
MaxBackoff time.Duration `json:"max-backoff" desc:"Maximum delay between delivery attempts"`
}
RetryConfig configures the total number of attempts and exponential backoff.
type Stats ¶ added in v0.3.260716
type Stats struct {
PendingEvents int
PendingBytes int
SubmittedEntries uint64
DeliveredEntries uint64
FailedRequests uint64
Retries uint64
Connections uint64
RejectedRequests uint64
FailureNotificationsDropped uint64
}
Stats is a point-in-time snapshot of client activity.
type TLSConfig ¶ added in v0.4.260716
type TLSConfig struct {
CAFile string `json:"ca-file" desc:"PEM file containing trusted server certificate authorities"`
CertificateFile string `json:"certificate-file" desc:"PEM client certificate file for mutual TLS"`
KeyFile string `json:"key-file" desc:"PEM client private key file for mutual TLS"`
ServerName string `json:"server-name" desc:"TLS server name used for certificate verification"`
MinVersion string `json:"min-version" desc:"Minimum TLS version: 1.2 or 1.3"`
InsecureSkipVerify bool `json:"insecure-skip-verify" desc:"Skip TLS server certificate verification"`
}
TLSConfig contains file-friendly TLS and mTLS settings.
type TimeoutConfig ¶
type TimeoutConfig struct {
Connect time.Duration `json:"connect" desc:"Timeout for complete transport connection setup"`
Handshake time.Duration `json:"handshake" desc:"Timeout for the Forward authentication handshake"`
Write time.Duration `json:"write" desc:"Timeout for writing one wire batch"`
ACK time.Duration `json:"ack" desc:"Timeout for receiving one Forward acknowledgement"`
}
TimeoutConfig configures each connection, Forward handshake, write, and ACK operation. A zero duration disables that individual timeout.
type WebSocketConfig ¶
type WebSocketConfig struct {
Header []WebSocketHeader `json:"header" desc:"Static HTTP headers sent during the WebSocket upgrade"`
}
WebSocketConfig contains WebSocket-specific connection settings.
type WebSocketHandshakeError ¶ added in v0.3.260716
WebSocketHandshakeError reports a failed HTTP upgrade. Body is bounded by the WebSocket implementation and omitted from Error to avoid accidental logging of sensitive response content.
func (*WebSocketHandshakeError) Error ¶ added in v0.3.260716
func (e *WebSocketHandshakeError) Error() string
func (*WebSocketHandshakeError) Temporary ¶ added in v0.3.260716
func (e *WebSocketHandshakeError) Temporary() bool
func (*WebSocketHandshakeError) Unwrap ¶ added in v0.3.260716
func (e *WebSocketHandshakeError) Unwrap() error
type WebSocketHeader ¶ added in v0.6.260716
type WebSocketHeader struct {
Name string `json:"name" desc:"HTTP header name"`
Values []string `json:"values" desc:"HTTP header values"`
}
WebSocketHeader describes one static HTTP header sent during the WebSocket upgrade. Values preserves repeated header values without exposing a map to file/CLI configuration decoders.