secondsight

package module
v0.0.0-...-92ec7ce Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

secondsight: structured docker log viewer

Usage

It is a simple web server. You can modify port number by using PORT environment variable.

$ go get gitlab.com/osaki-lab/secondsight/cmd/secondsight
$ ./secondsight

This tool watches Docker's status via /var/run/docker.sock socket.

License

Apache2

Credits

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContainerNotFound = errors.New("container not found")
View Source
var ErrDir = errors.New("path is dir")

Functions

func NewWebSocketConnection

func NewWebSocketConnection(w http.ResponseWriter, r *http.Request, logStore *LogStore) (*WebSocketConnection, *ClientConnection, error)

func NotFoundHandler

func NotFoundHandler(fallback string) func(w http.ResponseWriter, r *http.Request)

Types

type ClientConnection

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

ClientConnection is a backbone of client side API

WebSocketConnection is built on ClientConnection

func NewClientConnection

func NewClientConnection(receiver Receiver, logStore *LogStore) *ClientConnection

func (*ClientConnection) Disconnect

func (c *ClientConnection) Disconnect(containerID string)

func (*ClientConnection) Listen

func (c *ClientConnection) Listen(channelName string, filterSrc map[string]string) error

func (*ClientConnection) RetrieveChannels

func (c *ClientConnection) RetrieveChannels()

func (*ClientConnection) RetrieveLogs

func (c *ClientConnection) RetrieveLogs(containerID string) error

type ClientConnections

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

func NewClientConnections

func NewClientConnections() *ClientConnections

func (*ClientConnections) Loop

func (c *ClientConnections) Loop(callback func(*ClientConnection))

func (*ClientConnections) ReceiveLogUpdate

func (c *ClientConnections) ReceiveLogUpdate(channelName string)

func (*ClientConnections) Register

func (c *ClientConnections) Register(ctx context.Context, conn *ClientConnection)

type Container

type Container struct {
	LogOffset int
	// contains filtered or unexported fields
}

type ContainerConfig

type ContainerConfig struct {
	Name      string      `json:"name"`
	Active    bool        `json:"active"`
	ID        string      `json:"id"`
	Path      string      `json:"-"`
	CreatedAt Timestamp   `json:"createdAt"`
	UseTTY    bool        `json:"-"`
	Extra     [][2]string `json:"extra"`
}

type ContainerList

type ContainerList struct {
	Containers []*ContainerConfig `json:"containers"`
}

type Direction

type Direction int
const (
	NewToOld Direction = 0
	OldTONew Direction = 1
	Both     Direction = 2
)

type Docker

type Docker interface {
	Events(ctx context.Context) (<-chan Event, error)
	Close() error
}

func NewDocker

func NewDocker() (Docker, error)

type DockerEventType

type DockerEventType string
const (
	ContainerStartEvent   DockerEventType = "start"
	ContainerRunningEvent DockerEventType = "running"
	ContainerDieEvent     DockerEventType = "die"
)

type DummyReceiver

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

DummyReceiver is a mock object of ClientConnection

func (*DummyReceiver) GetEvents

func (d *DummyReceiver) GetEvents() []ReceivedEvent

func (*DummyReceiver) ReceiveChannelUpdate

func (d *DummyReceiver) ReceiveChannelUpdate(channels []string, containers []*ContainerConfig)

func (*DummyReceiver) ReceiveLogUpdate

func (d *DummyReceiver) ReceiveLogUpdate(channelName string, logs []LogEntry, scrollID int)

func (*DummyReceiver) ReceiveOldLogs

func (d *DummyReceiver) ReceiveOldLogs(channelName string, logs []LogEntry, scrollID int)

type Event

type Event struct {
	EventType   DockerEventType
	ContainerID string
	Config      *ContainerConfig
	LogStream   <-chan LogEntry
}

type EventType

type EventType int

EventType is for DummyReceiver's event

const (
	LogUpdateEvent EventType = iota + 1
	ReceiveOldLogsEvent
	ChannelUpdateEvent
)

type FilterFunc

type FilterFunc func(entry interface{}) bool

type JsonMessage

type JsonMessage struct {
	Command    string             `json:"cmd"`
	Channel    string             `json:"chan,omitempty"`
	Query      map[string]string  `json:"query,omitempty"`
	Logs       []LogEntry         `json:"logs,omitempty"`
	Containers []*ContainerConfig `json:"containers,omitempty"`
	Channels   []string           `json:"channels,omitempty"`
	Count      int                `json:"count,omitempty"`
	ScrollID   int                `json:"scrollID,omitempty"`
}

JsonMessage is response via client/server

Basic Command is Here:

(client)channels: RetrieveLogs channel information (client)connect: RetrieveLogs logs and keep listening (client)disconnect: Stop receive update (client)logs: Get old logs (server)channels: Channel information (server)old-logs: Log requested (server)update: New arrival logs (server)close: Channel is closed

type LogEntry

type LogEntry struct {
	Type    LogEventType `json:"t"`
	Content interface{}  `json:"c"` // StructLogEntry or StatEntry
}

type LogEventType

type LogEventType string
const (
	StatLogEvent    LogEventType = "s"
	StructLogEvent  LogEventType = "l"
	TraceLogEvent   LogEventType = "t"
	MetricsLogEvent LogEventType = "m"
)

type LogStore

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

func NewLogStore

func NewLogStore(connections *ClientConnections) *LogStore

func (*LogStore) AppendLog

func (ls *LogStore) AppendLog(containerID string, logEntry LogEntry) error

func (*LogStore) ConnectToDocker

func (ls *LogStore) ConnectToDocker(ctx context.Context, d Docker) error

func (*LogStore) Iterate

func (ls *LogStore) Iterate(callback func(containerID string, container *Container))

func (*LogStore) RegisterContainer

func (ls *LogStore) RegisterContainer(cc *ContainerConfig)

func (*LogStore) Search

func (ls *LogStore) Search(containerID string, searchFrom, count int, opt Option) (result []LogEntry, scrollIDs ScrollIDs, err error)

func (*LogStore) SetContainerState

func (ls *LogStore) SetContainerState(containerID string, running bool) error

type LogType

type LogType string
const (
	StdOutLog LogType = "stdout"
	StdErrLog LogType = "stderr"
)

type Option

type Option struct {
	Direction Direction
	Match     FilterFunc
}

type ReceivedEvent

type ReceivedEvent struct {
	Type        EventType
	ChannelName string
	Logs        []LogEntry
	ScrollID    int
	Channels    []string
	Containers  []*ContainerConfig
}

ReceivedEvent is record of DummyReceiver

func (ReceivedEvent) String

func (r ReceivedEvent) String() string

type Receiver

type Receiver interface {
	ReceiveLogUpdate(channelName string, logs []LogEntry, scrollID int)
	ReceiveOldLogs(channelName string, logs []LogEntry, scrollID int)
	ReceiveChannelUpdate(channels []string, containers []*ContainerConfig)
}

Receiver is struct to interface physical connection and this library

type ScrollIDs

type ScrollIDs struct {
	ToOld int `json:"to_old,omitempty"`
	ToNew int `json:"to_new,omitempty"`
}

type SerializedString

type SerializedString string

func (SerializedString) MarshalJSON

func (s SerializedString) MarshalJSON() ([]byte, error)

type Severity

type Severity uint
const (
	TraceLevel    Severity = 1
	DebugLevel    Severity = 2
	InfoLevel     Severity = 3
	WarningLevel  Severity = 4
	ErrorLevel    Severity = 5
	CriticalLevel Severity = 6
)

func ParseLevel

func ParseLevel(src string, defaultLevel Severity) Severity

func (Severity) String

func (s Severity) String() string

type StatEntry

type StatEntry struct {
	Timestamp Timestamp `json:"ts"`
	CPU       float64   `json:"c"`
	Memory    uint64    `json:"m"`
}

type StructLogEntry

type StructLogEntry struct {
	TraceID   string           `json:"tid"`
	SpanID    string           `json:"sid"`
	Timestamp Timestamp        `json:"ts"`
	Severity  Severity         `json:"s"`
	Log       SerializedString `json:"l"`
}

type Timestamp

type Timestamp int64

func TimestampFromTime

func TimestampFromTime(t time.Time) Timestamp

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

type WebSocketConnection

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

func (WebSocketConnection) ReceiveChannelUpdate

func (c WebSocketConnection) ReceiveChannelUpdate(channels []string, containers []*ContainerConfig)

func (WebSocketConnection) ReceiveLogUpdate

func (c WebSocketConnection) ReceiveLogUpdate(channelName string, logs []LogEntry, scrollID int)

func (WebSocketConnection) ReceiveOldLogs

func (c WebSocketConnection) ReceiveOldLogs(channelName string, logs []LogEntry, scrollID int)

func (WebSocketConnection) Wait

func (c WebSocketConnection) Wait()

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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