client

package
v3.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolMajorVersion = 2
	ProtocolMinorVersion = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	AccountID uuid.UUID
	ClusterID uuid.UUID

	ServerVersion    string
	AgentPermissions string
	// contains filtered or unexported fields
}

Client agent gateway client Client agent gateway client

func InitClient

func InitClient(
	version string,
	startID string,
	accountID, clusterID uuid.UUID,
	secret []byte,
	serverVersion string,
	agentPermissions string,
	gatewayUrl string,
	protoHandshake time.Duration,
	protoWrite time.Duration,
	protoRead time.Duration,
	protoReconnect time.Duration,
	protoBackoff time.Duration,
	sendLogs bool,
) *Client

InitClient inits client

func (*Client) AddListener

func (client *Client) AddListener(kind proto.PacketKind, listener func(in []byte) ([]byte, error))

AddListener adds a listener for a specific packet kind

func (*Client) Connect

func (client *Client) Connect(ctx context.Context, connect chan bool) error

Connect starts the client

func (*Client) IsReady

func (client *Client) IsReady() bool

IsReady returns true if the agent is connected and authenticated

func (*Client) Pipe

func (client *Client) Pipe(pack Package)

Pipe send packages to the agent-gateway with defined priorities and expiration rules

func (*Client) PipeStatus

func (client *Client) PipeStatus(pack Package)

PipeStatus send status packages to the agent-gateway with defined priorities and expiration rules TODO remove

func (*Client) Recover

func (client *Client) Recover()

Recover recover from panic used to send logs before exiting

func (*Client) Send

func (client *Client) Send(kind proto.PacketKind, in interface{}, out interface{}) error

Send sends a packet to the agent-gateway if there is an established connection it internally uses client.send

func (*Client) StartWatchdog

func (client *Client) StartWatchdog(ctx context.Context) error

func (*Client) Sync

func (client *Client) Sync() error

func (*Client) WaitForConnection

func (client *Client) WaitForConnection(timeout time.Duration) bool

WaitForConnection waits for an established connection with the agent gateway it blocks until the agent gateway is connected and the agent is authenticated it takes a timeout parameter to return if not connected returns true if connected false if timeout occurred Example:

WaitForConnection(time.Second * 10)

func (*Client) WithBackoff

func (client *Client) WithBackoff(fn func() error)

func (*Client) WithBackoffLimit

func (client *Client) WithBackoffLimit(fn func() error, limit int) error

func (*Client) Write

func (client *Client) Write(p []byte) (n int, err error)

type DefaultPipeStore

type DefaultPipeStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDefaultPipeStore

func NewDefaultPipeStore() *DefaultPipeStore

func (*DefaultPipeStore) Ack

func (s *DefaultPipeStore) Ack(pack *Package)

func (*DefaultPipeStore) Add

func (s *DefaultPipeStore) Add(pack *Package) int

func (*DefaultPipeStore) Len

func (s *DefaultPipeStore) Len() int

func (*DefaultPipeStore) Peek

func (s *DefaultPipeStore) Peek() *Package

func (*DefaultPipeStore) Pop

func (s *DefaultPipeStore) Pop() *Package

type Package

type Package struct {
	// Kind packet kind
	Kind proto.PacketKind
	// ExpiryTime time afterwards will not try to send packets
	// nil means never expires
	ExpiryTime *time.Time
	// ExpiryCount will expire if this number of packets come afterwards
	// 0 means never
	ExpiryCount int
	// Priority a number to indicate the order to send pending packets
	// the lower the value the more urget it is
	Priority int
	// Retries max number of retries before decreasing priority by one
	// 0 means never
	Retries int

	// Data data to be sent
	Data interface{}
	// contains filtered or unexported fields
}

Package structure used to send packages over the channel

type Pipe

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

Pipe pipe

func NewPipe

func NewPipe(sender PipeSender) *Pipe

NewPipe creates a new pipe

func (*Pipe) Len

func (p *Pipe) Len() int

Len gets the number of pending packages

func (*Pipe) Send

func (p *Pipe) Send(pack Package) int

Send pushes a packet to the pipe to be sent

func (*Pipe) Start

func (p *Pipe) Start(workers int)

Start start multiple workers for sending packages

type PipeSender

type PipeSender interface {
	Send(kind proto.PacketKind, in interface{}, out interface{}) error
}

PipeSender interface for sender

type PipeStore

type PipeStore interface {
	// Add adds a package to be sent, returns the number of dropped packages since the last add
	Add(*Package) int
	// Peek gets the first available package
	// returns the same if called multiple times without ack unless a package expires
	// returns nil if nothing in the queue
	Peek() *Package
	// Acks that a peeked package has been sent, does nothing if the package has expired
	Ack(*Package)
	// Pop is an atomic peek and ack
	// returns nil in case there are no packages
	Pop() *Package
	// Len gets the number of pending packets
	Len() int
}

PipeStore store interface for packageges

type PriorityQueue

type PriorityQueue []*Package

PriorityQueue implements heap.Interface and holds Items.

func (*PriorityQueue) First

func (pq *PriorityQueue) First() interface{}

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

Jump to

Keyboard shortcuts

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