agent

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerLogStreamer

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

ContainerLogStreamer connects and activates container's log stream with io.Writer

func NewContainerLogStreamer

func NewContainerLogStreamer(params ContainerStreamerParams) *ContainerLogStreamer

NewContainerLogStreamer makes log streamer for given container with writers and log emitter

func (*ContainerLogStreamer) Close

func (l *ContainerLogStreamer) Close(ctx context.Context) (err error)

Close kills streamer

func (*ContainerLogStreamer) Name

func (l *ContainerLogStreamer) Name() string

Name of the streamed container

func (*ContainerLogStreamer) Run

func (l *ContainerLogStreamer) Run() error

Run activates streamer, blocking

func (*ContainerLogStreamer) Wait

Wait for stream completion

type ContainerStreamerParams

type ContainerStreamerParams struct {
	ID          string
	Name        string
	LogWriter   io.WriteCloser
	ErrWriter   io.WriteCloser
	LogsEmitter LogsEmitter
}

ContainerStreamerParams defines everything used to construct container's log streamer

type DemoEmitter

type DemoEmitter struct {
	Duration time.Duration
}

DemoEmitter is a emitter for fake logs, no docker involved

func (*DemoEmitter) Logs

func (d *DemoEmitter) Logs(o docker.LogsOptions) error

Logs generates random log messages

type DemoEventNotifier

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

DemoEventNotifier is a fake/replacement for docker notifier

func NewDemoEventNotifier

func NewDemoEventNotifier(ctx context.Context) *DemoEventNotifier

NewDemoEventNotifier makes notifier emitting 3 events

func (*DemoEventNotifier) Channel

func (e *DemoEventNotifier) Channel() (res <-chan Event)

Channel gets eventsCh with all containers events

type DockerClient

type DockerClient interface {
	ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)
	AddEventListener(listener chan<- *docker.APIEvents) error
}

DockerClient defines interface listing containers and subscribing to events

type Event

type Event struct {
	ContainerID   string
	ContainerName string
	Group         string // group is the "path" part of the image tag, i.e. for umputun/system/logger:latest it will be "system"
	TS            time.Time
	Status        bool
}

Event is simplified docker.APIEvents for containers only, exposed to caller

type EventLoop

type EventLoop struct {
	MixOuts       bool
	WriterFactory func(ctx context.Context, containerName, group string) (logWriter, errWriter io.WriteCloser, err error)

	LogEmitter LogEmitter
	Events     Eventer
	// contains filtered or unexported fields
}

EventLoop reacts on messages from Events, adds+activate LogStreamer as well as stop+remove them.

func (*EventLoop) Run

func (l *EventLoop) Run(ctx context.Context)

Run blocking even loop. Receives events from Eventer and makes new log streams. Also deregister terminated streams.

type EventNotifier

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

EventNotifier emits all changes from all containers states

func NewEventNotifier

func NewEventNotifier(dockerClient DockerClient, excludes, includes []string) (*EventNotifier, error)

NewEventNotifier makes EventNotifier publishing all changes to eventsCh

func (*EventNotifier) Channel

func (e *EventNotifier) Channel() (res <-chan Event)

Channel gets eventsCh with all containers events

type Eventer

type Eventer interface {
	Channel() <-chan Event
}

Eventer returns chan with events

type LogEmitter

type LogEmitter interface {
	Logs(opts docker.LogsOptions) error
}

LogEmitter wraps DockerClient with the minimal interface

type LogStreamer

type LogStreamer interface {
	Run() error
	Close(ctx context.Context) error
	Name() string
}

LogStreamer defines runnable interface created on event

type LogsEmitter

type LogsEmitter interface {
	Logs(docker.LogsOptions) error // runs endless loop publishing logs to writers from LogsOptions
}

LogsEmitter wraps DockerClient with the minimal interface to emit logs

type MultiWriter

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

MultiWriter implements WriteCloser for multiple destinations. It is simplified version of stdlib MultiWriter. Ignores write error and don't stop the loop unless all writes failed.

func NewMultiWriterIgnoreErrors

func NewMultiWriterIgnoreErrors(writers ...io.WriteCloser) *MultiWriter

NewMultiWriterIgnoreErrors create WriteCloser for multiple destinations

func (*MultiWriter) Close

func (w *MultiWriter) Close() error

Close all writers, collect errors

func (*MultiWriter) WithExtJSON

func (w *MultiWriter) WithExtJSON(containerName, group string) *MultiWriter

WithExtJSON turn JSON output mode on

func (*MultiWriter) Write

func (w *MultiWriter) Write(p []byte) (n int, err error)

Write to all writers and ignore errors unless they all have errors

Jump to

Keyboard shortcuts

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