Documentation ¶
Index ¶
- Constants
- Variables
- func FilterContainsString(s string) func(l *Log) bool
- func FilterExactString(s string) func(l *Log) bool
- func FilterMatchAll() func(l *Log) bool
- type Config
- type DBMap
- type Hive
- type IC
- type Log
- type LogFormat
- type LogWriteFailure
- type Query
- type Segment
- type SegmentManager
- func (m *SegmentManager) Close()
- func (m *SegmentManager) CreateNeededSegments(maxBytes int64, maxDuration time.Duration) error
- func (m *SegmentManager) CreateSegment(domain string, timestamp time.Time) (Segment, error)
- func (m *SegmentManager) DeleteMarkedSegments() error
- func (m *SegmentManager) Iterate(domains []string, start, end time.Time, chunkSize int, bufferSize int) []chan []Log
- func (m *SegmentManager) MarkSegmentForDeletion(s Segment) error
- func (m *SegmentManager) ScanDir() ([]Segment, error)
- func (m *SegmentManager) Write(logs []*Log) error
- type SegmentMap
Constants ¶
const SyntheticFailureFlush = "!~!~!~_internal_::thislogshouldfail👎Flush"
SyntheticFailureFlush is an ugly hack that exists because I can't figure out how to force a failure during tests otherwise.
const SyntheticFailureWrite = "!~!~!~_internal_::thislogshouldfail👎Write"
SyntheticFailureWrite is an ugly hack that exists because I can't figure out how to force a failure during tests otherwise.
Variables ¶
var DefaultConfig = Config{ InternalLogLevel: logrus.InfoLevel, InternalLogFormat: LogFormatLogfmt, WritableDomains: []string{"_"}, SegmentMaxDuration: time.Duration(336) * time.Hour, SegmentMaxBytes: 128 * 1024 * 1024, LineMaxBytes: 8 * 1024, FlushAfterItems: 128, FlushAfterDuration: time.Duration(1000) * time.Millisecond, }
DefaultConfig is the default configuration, which will be written to the config database if a config is not found
Functions ¶
func FilterContainsString ¶
FilterContainsString takes a string and returns a filter matching lines containing that string
func FilterExactString ¶
FilterExactString takes a string and returns a filter matching lines with exactly that string
func FilterMatchAll ¶
FilterMatchAll returns a filter matching all logs
Types ¶
type Config ¶
type Config struct { InternalLogLevel logrus.Level InternalLogFormat LogFormat WritableDomains []string SegmentMaxDuration time.Duration SegmentMaxBytes int64 LineMaxBytes int FlushAfterItems int FlushAfterDuration time.Duration }
Config describes the configuration that Loghive needs to function
type Hive ¶
Hive is a running Loghive instance pointed at a storage path
func NewHive ¶
NewHive returns a pointer to a Hive at the given path. Configuration will be loaded from a file found there or populated from defaults.
func (*Hive) Enqueue ¶
Enqueue constructs a Log from the given domain and line, and puts it on the queue to be written
func (*Hive) MarkSegmentForDeletion ¶
MarkSegmentForDeletion will mark a segment to deleted during the next DeleteMarkedSegments
func (*Hive) ValidateQuery ¶
ValidateQuery will return any error with a query's parameters
type IC ¶
IC is short for Internal (Log) Context. This makes it easy to do structured logging when processing logs
type Log ¶
type Log struct { Domain string `json:"domain"` Timestamp time.Time `json:"timestamp"` Line []byte `json:"line"` }
Log is a single log line within a domain
type LogFormat ¶
type LogFormat string
LogFormat describes how internal logs will be formatted
const LogFormatJSON LogFormat = "json"
LogFormatJSON will print JSON logs
const LogFormatLogfmt LogFormat = "logfmt"
LogFormatLogfmt will print Logfmt logs
type LogWriteFailure ¶
type LogWriteFailure struct { Err error `json:"err"` Log Log `json:"log"` Count int `json:"count"` }
LogWriteFailure provides information about why one or more logs were not written
type Query ¶
type Query struct { Domains []string Start time.Time End time.Time Filter func(*Log) bool Results chan *Log }
Query is a set of parameters for querying logs
type Segment ¶
type Segment struct { Path string `json:"path"` Domain string `json:"domain"` Timestamp time.Time `json:"timestamp"` }
Segment is a file that represents a contiguous subset of logs in a domain starting at a timestamp
type SegmentManager ¶
SegmentManager manages connections to Segments in BadgerDBs
func NewSegmentManager ¶
func NewSegmentManager(path string) *SegmentManager
NewSegmentManager creates a new SegmentManager for a specified path
func (*SegmentManager) CreateNeededSegments ¶
func (m *SegmentManager) CreateNeededSegments(maxBytes int64, maxDuration time.Duration) error
CreateNeededSegments checks the latest segment in each domain and if any exceed the given constraints, a new segment is created in that domain
func (*SegmentManager) CreateSegment ¶
CreateSegment creates a SQLite file for a segment and stores its metadata in it
func (*SegmentManager) DeleteMarkedSegments ¶
func (m *SegmentManager) DeleteMarkedSegments() error
DeleteMarkedSegments will delete any segments marked for deletion
func (*SegmentManager) Iterate ¶
func (m *SegmentManager) Iterate(domains []string, start, end time.Time, chunkSize int, bufferSize int) []chan []Log
Iterate takes a list of domains and a range of time, returning a list of channels (one per domain) on which chunks of the requested size will be delivered
func (*SegmentManager) MarkSegmentForDeletion ¶
func (m *SegmentManager) MarkSegmentForDeletion(s Segment) error
MarkSegmentForDeletion will mark a segment to deleted during the next DeleteMarkedSegments
func (*SegmentManager) ScanDir ¶
func (m *SegmentManager) ScanDir() ([]Segment, error)
ScanDir scans the directory at `m.Path` for segment DB files and opens them
func (*SegmentManager) Write ¶
func (m *SegmentManager) Write(logs []*Log) error
Write stores a group of logs in their appropriate segment files, returning any failures