events

package
v0.0.0-...-892de5e Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEventsDataDir occurs when events are trying to be  flushed, but the events data directory
	// does not yet exist
	ErrEventsDataDir = errors.New("unable to flush, events data directory does not exist")

	// ErrFileLocked occurs if the current file or dir is locked for processing
	ErrFileLocked = errors.New("file is currently locked")
)
View Source
var EventNowFunc = time.Now

EventNowFunc function is used to get the current time and can be overridden for testing.

View Source
var GlobalCollector = NewCollector()

GlobalCollector is an instance of a collector where all events should be sent via the CloseEventAndAdd function

Functions

func CheckFilenameMD5

func CheckFilenameMD5(data []byte, path string) (bool, error)

CheckFilenameMD5 is the fileNamingFunc used when instantiating a FileBackedProc

func MD5FileNamer

func MD5FileNamer(bytes []byte) string

MD5FileNamer names files after the base64 url encoding of the md5 hash of the contents of the file

func MD5Str

func MD5Str(bytes []byte) string

MD5Str returns the standard base64 encoding of the md5 hash with padding

func MD5StrUrl

func MD5StrUrl(bytes []byte) string

MD5StrUrl returns the base64 url encoding of the md5 hash with the padding removed

func NewContextForEvent

func NewContextForEvent(ctx context.Context, evt *Event) context.Context

NewContextForEvent creates a new context with the event provided

Types

type Collector

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

Collector collects and stores Events later to be sent to an Emitter.

func NewCollector

func NewCollector() *Collector

NewCollector creates a new instance of a collector

func (*Collector) Close

func (c *Collector) Close() []*eventsapi.ClientEvent

Close waits for any remaining events to finish collection and then returns a slice of ClientEvents to be passed to an emitter.

func (*Collector) CloseEventAndAdd

func (c *Collector) CloseEventAndAdd(evt *Event)

CloseEventAndAdd closes the supplied event and adds it to the collection of events. This method is thread safe.

type Counter

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

Counter is a metric for counting

func NewCounter

func NewCounter(metricID eventsapi.MetricID) *Counter

NewCounter creates a new counter

func (*Counter) Add

func (c *Counter) Add(addend int32)

Add a positive or negative value to the current count.

func (*Counter) AsClientEventMetric

func (c *Counter) AsClientEventMetric() *eventsapi.ClientEventMetric

AsClientEventMetrics gets the eventsapi.ClientEventMetric encoding of a metric

func (*Counter) Dec

func (c *Counter) Dec()

Dec decrements a counter. This method happens atomically.

func (*Counter) Inc

func (c *Counter) Inc()

Inc incements a counter. This method happens atomically.

type Emitter

type Emitter interface {
	// LogEvents takes a batch of events and processes them
	LogEvents(version string, evts []*eventsapi.ClientEvent) error
}

Emitter is an interface used for processing a batch of events

type Event

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

Event is an event to be added to a collector and logged

func GetEventFromContext

func GetEventFromContext(ctx context.Context) *Event

GetEventFromContext retrieves the event from the context if one exists.

func NewEvent

func NewEvent(ceType eventsapi.ClientEventType) *Event

NewEvent creates an Event of a given type. The event creation time is recorded as the start time for the event. When the event is passed to a collector's CloseEventAndAdd method the end time of the event is recorded

func (*Event) AddMetric

func (evt *Event) AddMetric(em EventMetric)

AddMetric adds a metric to the event. This method is thread safe.

func (*Event) SetAttribute

func (evt *Event) SetAttribute(attID eventsapi.AttributeID, attVal string)

SetAttribute adds an attribute to the event. This method is thread safe

type EventMetric

type EventMetric interface {
	// AsClientEventMetrics gets the eventsapi.ClientEventMetric encoding of a metric
	AsClientEventMetric() *eventsapi.ClientEventMetric
}

EventMetric is an interface for getting the eventsapi.ClientEventMetric encoding of a metric

type FileBackedProc

type FileBackedProc struct {
	CheckingFunc fileCheckingFunc
	LockPath     string
	// contains filtered or unexported fields
}

FileBackedProc writes events requests to files in an events data dir

func NewFileBackedProc

func NewFileBackedProc(fs filesys.Filesys, userHomeDir string, doltDir string, nf fileNamingFunc, cf fileCheckingFunc) *FileBackedProc

NewFileBackedProc creates a new FileBackedProc

func (*FileBackedProc) EventsDirExists

func (fbp *FileBackedProc) EventsDirExists() bool

EventsDirExists returns true iff the events data dir exists

func (*FileBackedProc) GetEventsDirPath

func (fbp *FileBackedProc) GetEventsDirPath() string

GetEventsDirPath returns the path to the events data dir

func (*FileBackedProc) GetFileSys

func (fbp *FileBackedProc) GetFileSys() filesys.Filesys

GetFileSys returns the current filesys being used

func (*FileBackedProc) WriteEvents

func (fbp *FileBackedProc) WriteEvents(version string, evts []*eventsapi.ClientEvent) error

WriteEvents writes events requests to the events data dir

type FileEmitter

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

FileEmitter saves event requests to files

func NewFileEmitter

func NewFileEmitter(userHomeDir string, doltDir string) *FileEmitter

NewFileEmitter creates a new file emitter

func (*FileEmitter) LogEvents

func (fe *FileEmitter) LogEvents(version string, evts []*eventsapi.ClientEvent) error

LogEvents implements the Emitter interface and writes events requests to files

type Flusher

type Flusher interface {
	Flush(ctx context.Context) error
}

Flusher flushes events to a destination

type GrpcEmitter

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

GrpcEmitter sends events to a GRPC service implementing the eventsapi

func NewGrpcEmitter

func NewGrpcEmitter(conn *grpc.ClientConn) *GrpcEmitter

NewGrpcEmitter creates a new GrpcEmitter

func (*GrpcEmitter) LogEvents

func (em *GrpcEmitter) LogEvents(version string, evts []*eventsapi.ClientEvent) error

func (*GrpcEmitter) SendLogEventsRequest

func (em *GrpcEmitter) SendLogEventsRequest(ctx context.Context, req *eventsapi.LogEventsRequest) error

SendLogEventsRequest sends a request using the grpc client

type GrpcEventFlusher

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

GrpcEventFlusher parses dolt event logs sends the events to the events server

func NewGrpcEventFlusher

func NewGrpcEventFlusher(fs filesys.Filesys, userHomeDir string, doltDir string, grpcEmitter *GrpcEmitter) *GrpcEventFlusher

NewGrpcEventFlusher creates a new GrpcEventFlusher

func (*GrpcEventFlusher) Flush

func (egf *GrpcEventFlusher) Flush(ctx context.Context) error

Flush satisfies the Flusher interface and calls this Flusher's flush method on each events file

type IOFlusher

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

IOFlusher parses event files and writes them to stdout

func NewIOFlusher

func NewIOFlusher(fs filesys.Filesys, userHomeDir string, doltDir string) *IOFlusher

NewIOFlusher creates a new IOFlusher

func (*IOFlusher) Flush

func (iof *IOFlusher) Flush(ctx context.Context) error

Flush satisfies the Flusher interface and calls this Flusher's flush method on each events file

type NullEmitter

type NullEmitter struct{}

NullEmitter is an emitter that drops events

func (NullEmitter) LogEvents

func (ne NullEmitter) LogEvents(version string, evts []*eventsapi.ClientEvent) error

LogEvents takes a batch of events and processes them. In this case it just drops them

type Timer

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

Timer a timer is used to time how long something ran for.

func NewTimer

func NewTimer(metricID eventsapi.MetricID) *Timer

NewTimer creates a new timer and records the start time using the EventNowFunc

func (*Timer) AsClientEventMetric

func (t *Timer) AsClientEventMetric() *eventsapi.ClientEventMetric

AsClientEventMetrics gets the eventsapi.ClientEventMetric encoding of a metric

func (*Timer) Restart

func (t *Timer) Restart()

Restart clears the timers end time and sets a new start time using the EventNowFunc

func (*Timer) Stop

func (t *Timer) Stop() *Timer

Stop sets the end time using the EventNowFunc

type WriterEmitter

type WriterEmitter struct {
	// Wr the writer to log events to
	Wr io.Writer
}

WriterEmitter is an emitter that writes the text encoding of the events to it's writer

func (WriterEmitter) LogEvents

func (we WriterEmitter) LogEvents(version string, evts []*eventsapi.ClientEvent) error

LogEvents takes a batch of events and processes them. In this case the text encoding of the events is written to the writer

Jump to

Keyboard shortcuts

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