timesrs

package module
v0.0.0-...-eff10b5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2018 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

CircleCI

go-timeseries

Architecture

Pipeline are a series of aggregations performed in sequence over an Event that generates a set of data that will be stored using a Storage abstraction.

Event is an occurrence that happens and need to be measured.

Aggregations are Operations that will aggregate information about a specific event and will be kept in the system.

Operation is a transformation that will be performed in the database by the Storage.

Granularity is the measure of time that specifies how precise a datetime is.

Storage is the abstraction that will receive the data aggregated and spread through an database to

Documentation

Index

Constants

View Source
const (
	OperationTypeInc = iota
	OperationTypeSet
)

Variables

View Source
var DefaultClock utcClock

DefaultClock is the default implementation of the clock.

Functions

func GetFieldValue

func GetFieldValue(field string, data interface{}) (interface{}, error)

func NewEvent

func NewEvent(name string, data interface{}, moment time.Time) *evt

NewEvent will return an instance of a event.

func NoTags

func NoTags(e Event) (map[string]interface{}, error)

NoTags define that the aggregation will have no tags but the time.

Types

type Aggregation

type Aggregation interface {
	Aggregate(event Event, data *AggregationData) error
}

Aggregator produces an operation.

type AggregationData

type AggregationData []Operation

type AggregationFnc

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

AggregationFnc increases a value of a field

func NewAggregationFnc

func NewAggregationFnc(fnc func(e Event, data *AggregationData) error) *AggregationFnc

NewAggregationFnc creates a new instance of `AggregationFnc`.

func (*AggregationFnc) Aggregate

func (agg *AggregationFnc) Aggregate(event Event, data *AggregationData) error

Aggregate calls fnc and returns its error

type AggregationInc

type AggregationInc struct {
	Field string
	Value int
}

AggregatorInc increases a value of a field

func NewAggregationInc

func NewAggregationInc(field string, value ...int) *AggregationInc

NewAggregationInc creates a new instnace of the aggregation inc.

func (*AggregationInc) Aggregate

func (agg *AggregationInc) Aggregate(event Event, data *AggregationData) error

Aggregate adds the `Field` with its `Value` to the `data`.

type Clock

type Clock interface {
	Time() time.Time
}

Clock provides the time of the operation.

type Event

type Event interface {
	Name() string
	Data() interface{}
	Time() time.Time
}

Event is a happening that will be aggregated

type Granularity

type Granularity int
const (
	GranularitySecond Granularity = iota
	GranularityMinute
	GranularityHour
	GranularityDay
	GranularityWeek
	GranularityMonth
	GranularityYear
)

func (Granularity) RelativeTo

func (g Granularity) RelativeTo(t, relativeTo time.Time) int

func (Granularity) String

func (g Granularity) String() string

func (Granularity) Truncate

func (g Granularity) Truncate(t time.Time) time.Time

type GranularityComposite

type GranularityComposite struct {
	Record     Granularity
	Collection Granularity
}

GranularityComposite is the configuration added to the pipeline to be passed to the `Storage`.

The `Storage` create the collection and records according with this configuration.

type LocalClock

type LocalClock struct{}

LocalClock provides the current local time.

func (*LocalClock) Time

func (*LocalClock) Time() time.Time

Time returns the current local time.

type Operation

type Operation struct {
	Type  OperationType
	Field string
	Value interface{}
}

func NewOperationInc

func NewOperationInc(field string, value interface{}) *Operation

func NewOperationSet

func NewOperationSet(field string, value interface{}) *Operation

type OperationType

type OperationType = int

type Pipeline

type Pipeline struct {
	// Granularities is the set of granularity configurations that will be
	// stored in the `Storage` set in this `Pipeline`.
	Granularities []GranularityComposite

	// Aggregations is the set of aggregations that will be applied in this
	// `Pipeline`.
	Aggregations []Aggregation

	// Collection is the base name of the
	Collection string

	// TagFnc will evaluate the `Event` and recreate
	TagFnc PipelineTagFnc

	// Storage is the storaging system used in this `Pipeline`.
	Storage Storage

	// ErrorHandler is the handling error function that will be called if any
	// error is triggered in the pipeline process.
	ErrorHandler PipelineErrorHandler
}

Pipeline is responsible to receive an event and trigger each `Bucket` in sequence, aggregating each result and storing it using the `Storage`.

A Pipeline keeps an array of buckets that will be triggered when `Run` method is called.

func (*Pipeline) Run

func (p *Pipeline) Run(e Event) (*PipelineResult, error)

Run triggers the processing of the buckets in order of registering.

Each `BucketResult` is synchronously stored in the `Storage` specified at the `Pipeline` "constructor".

The param `e` informed is the source of the data that will go through the pipeline.

type PipelineErrorHandler

type PipelineErrorHandler func(aggregation Aggregation, err error) error

PipelineErrorHandler is called when an error is triggered in the pipeline process.

type PipelineResult

type PipelineResult struct {
	Data AggregationData
}

type PipelineTagFnc

type PipelineTagFnc func(e Event) (map[string]interface{}, error)

PipelineTagFunction receives an `Event` and set all keys beside the timeline which will, automatically, be set as _id.

func TagByField

func TagByField(fields ...string) PipelineTagFnc

TagByField implements a `PipelineKeyFunction` that will only use field names (through reflection) to get the data value. It is a helper function for sugar coding.

type Storage

type Storage interface {
	Store(entry *StorageEntry) error
}

Storage will persists the `Result` obtained by a bucket.

type StorageEntry

type StorageEntry struct {
	Event         Event
	Collection    string
	Granularities []GranularityComposite
	Result        *PipelineResult
	Keys          map[string]interface{}
}

Jump to

Keyboard shortcuts

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