tcpjson

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNoURIs           = "no URIs provided to connect to"
	ErrFailedParsingURI = "failed to parse provided URI"
	ErrFailedDial       = "failed to dial the host:port"
)
View Source
const (

	// TCPWriterHealthCheckName is the name used for the external health check
	TCPWriterHealthCheckName health.CheckType = "TCP_LOGGER_CONNECTION_STATUS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncWriter added in v1.14.0

type AsyncWriter interface {
	io.WriteCloser
	// Drain tries to gracefully drain the remaining buffered messages,
	// blocking until the buffer is empty or the provided context is cancelled.
	Drain(ctx context.Context)
}

func StartAsyncWriter

func StartAsyncWriter(output io.Writer, registry metrics.Registry) AsyncWriter

StartAsyncWriter creates a Writer whose Write method puts the submitted byte slice onto a channel. In a separate goroutine, slices are pulled from the queue and written to the output writer. The Close method stops the consumer goroutine and will cause future writes to fail.

type ConnProvider

type ConnProvider interface {
	// GetConn returns a net.Conn or an error if there is no connection established.
	// It is the caller's responsibility to close the returned net.Conn and
	// gracefully handle any closed connection errors if the net.Conn is shared across clients.
	GetConn() (net.Conn, error)
}

ConnProvider defines the behavior to retrieve an established net.Conn.

func NewTCPConnProvider

func NewTCPConnProvider(uris []string, options ...ConnProviderOption) (ConnProvider, error)

NewTCPConnProvider returns a new ConnProvider that provides TCP connections. The provided uris must not be empty and must be able to be parsed as URIs. Refer to the documentation for url.Parse.

type ConnProviderOption

type ConnProviderOption interface {
	// contains filtered or unexported methods
}

ConnProviderOption can be used to configure a ConnProvider

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) ConnProviderOption

WithTLSConfig configures the ConnProvider to use the provided TLS configuration. If not set, the ConnProvider will use the default TLS config.

type LogEnvelopeMetadata

type LogEnvelopeMetadata struct {
	Deployment     string `json:"deployment"`
	Environment    string `json:"environment"`
	EnvironmentID  string `json:"environmentId"`
	Host           string `json:"host"`
	NodeID         string `json:"nodeId"`
	Service        string `json:"service"`
	ServiceID      string `json:"serviceId"`
	Stack          string `json:"stack"`
	StackID        string `json:"stackId"`
	Product        string `json:"product"`
	ProductVersion string `json:"productVersion"`
}

func GetEnvelopeMetadata

func GetEnvelopeMetadata() (LogEnvelopeMetadata, error)

GetEnvelopeMetadata retrieves all log envelope environment variables and returns the fully populated LogEnvelopeMetadata and a nil error. If any expected environment variables are not found or empty, then an empty LogEnvelopeMetadata will be returned along with an error that contains the missing environment variables.

type TCPWriter

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

func NewTCPWriter

func NewTCPWriter(metadata LogEnvelopeMetadata, provider ConnProvider, options ...WriterOption) *TCPWriter

NewTCPWriter returns an io.WriteCloser that writes logs to a TCP socket and wraps them with the provided envelope metadata. TCP connections are retrieved using the ConnProvider and connection state is managed internally.

func (*TCPWriter) Close

func (d *TCPWriter) Close() error

Close will close any existing client connections and shuts down the writer from any future writes.

func (*TCPWriter) HealthStatus

func (d *TCPWriter) HealthStatus(ctx context.Context) health.HealthStatus

func (*TCPWriter) Write

func (d *TCPWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for use with TCP sockets. The provided input is wrapped in a LogEnvelopeV1 and serialized as JSON before writing to the underlying socket. If there is a connection error before or during writing, the connection will be closed and an error will be returned. If a subsequent Write is called after Close, then this will return immediately with an error.

type WriterOption

type WriterOption interface {
	// contains filtered or unexported methods
}

WriterOption can be used to configure the TCPWriter

Jump to

Keyboard shortcuts

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