Documentation ¶
Index ¶
- type Badger
- func (b *Badger) AddMessage(t time.Time, m Message) error
- func (b *Badger) Close() error
- func (b *Badger) ListMessages(from, to time.Time, filter Filter, after []byte, limit uint) (Batch, error)
- func (b *Badger) StreamMessages(ctx context.Context, from time.Time, filter Filter, limit uint) (Batch, chan Message, error)
- type Batch
- type Filter
- type FlatMapping
- type Message
- type MessageID
- type StoredMessage
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 (*Badger) AddMessage ¶
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) 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 ¶
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 ¶
StoredMessage describes a previously stored message retrieved from the DB, as a consequence of which, it has a proper identifier.