storage

package
v0.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Badger

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

Badger is the realtime storage implementation using BadgerDB.

func NewBadger

func NewBadger(opts badger.Options) (*Badger, error)

NewBadger opens a new badger DB using the specified options.

func (*Badger) AddMessage

func (b *Badger) AddMessage(t time.Time, m Message) error

AddMessage adds a new message to the storage and sends it to any fitting realtime consumers. :TODO: batch message additions for higher throughput

func (*Badger) Close

func (b *Badger) Close() error

Close releases the ID sequence and closes the DB.

func (*Badger) ListMessages

func (b *Badger) ListMessages(from, to time.Time, filter Filter, after []byte, limit uint) (Batch, error)

ListMessages returns a batched, reversed (latest to earliest) list of all of the log messages in the interval [from, to]. Nil may be passed here for a filter, in which case no filtering occurs. If after is set to a non-empty sequence, the iteration is started from "after" instead of "from".

func (*Badger) StreamMessages

func (b *Badger) StreamMessages(ctx context.Context, from time.Time, filter Filter, limit uint,
) (Batch, chan Message, error)

StreamMessages should be used when messages need to be streamed in real-time starting from some timestamp. Like ListMessages, a Batch is returned consisting of the latest messages after "from", meaning that, if there are lots of such messages, only a small part is returned in the Batch and its Next field is set, which can then be used with ListMessages like usual. New messages that arrive after the batch are passed through the returned channel until the passed context is done.

type Batch

type Batch struct {
	Messages []StoredMessage
	Next     []byte
}

Batch is a paginated batch of messages. Next is nil if there are no more messages to be retrieved, otherwise it is an internal key of the next item to be retrieved.

type Filter

type Filter func(Message, FlatMapping) bool

Filter can (optionally) be passed to List* methods of the storage to filter out the logs which are returned. Note: Filters should be thread-safe since they can be called from multiple goroutines at once.

type FlatMapping

type FlatMapping func(key string) (value string, ok bool)

FlatMapping describes an unnested map[string]any, allowing for fast access.

type Message

type Message []byte

Message is a single log message. Log messages *SHOULD* be JSON-formatted to enable field-specific search, however it isn't enforced, and non-field searches are still possible.

type MessageID

type MessageID []byte

MessageID is an opaque message identifier. Currently, it is generated as "logs:{timestamp}:{sequence_number}", but this shouldn't be relied on. Overall, message IDs are returned for proper pagination and display on the clientside.

type StoredMessage

type StoredMessage struct {
	M  Message
	ID MessageID
}

StoredMessage describes a previously stored message retrieved from the DB, as a consequence of which, it has a proper identifier.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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