pointstores

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package pointstores contains the implementation of all the supported storage adapters for the series

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ElasticAdapter

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

ElasticAdapter is a point store implementation for Elasticsearch

func NewElasticAdapter

func NewElasticAdapter(sp config.SeriesParams) (*ElasticAdapter, error)

NewElasticAdapter returns an initialized Elasticsearch point store

func (ElasticAdapter) AddPoint

func (ea ElasticAdapter) AddPoint(name string, p Point) error

AddPoint upserts a measurement into the index of a given series

func (ElasticAdapter) AddSeries

func (ea ElasticAdapter) AddSeries(name string, sample Point, retentionDays int) error

AddSeries creates and configures a new index in Elasticsearch to hold a time series

func (ElasticAdapter) DeleteSeries

func (ea ElasticAdapter) DeleteSeries(name string) error

DeleteSeries removes the index used to store a series

func (ElasticAdapter) Exists

func (ea ElasticAdapter) Exists(name string) (bool, error)

Exists returns true if an index for the specified series is present in Elasticsearch, false if not or in case of error (make sure to check if error is nil before looking at the boolean)

func (ElasticAdapter) GetCount

func (ea ElasticAdapter) GetCount(name string, labels map[string]string) (int, error)

GetCount retrieves the number of points recorded for the given series with the specified labels (returns 0 if the series doesn't exist)

func (ElasticAdapter) GetLastN

func (ea ElasticAdapter) GetLastN(name string, labels map[string]string, n int) ([]Point, error)

GetLastN retrieves the last N points for the given series with the specified labels

func (ElasticAdapter) GetLatest

func (ea ElasticAdapter) GetLatest(name string, labels map[string]string) (Point, error)

GetLatest retrieves the most recent value of the series with the specified labels

func (ElasticAdapter) ListSeries

func (ea ElasticAdapter) ListSeries() ([]types.BriefSeries, error)

ListSeries as its name implies, returns a list of all the series that are available in Elasticsearch

func (ElasticAdapter) LoadTestSet

func (ea ElasticAdapter) LoadTestSet(name, path string) error

LoadTestSet loads a set of points from a single file for testing (not part of the standard PointStore interface)

type FileAdapter

type FileAdapter struct {
	Path string
}

FileAdapter is a point store implementation that uses the filesystem. Its main purpose is to facilitate testing, given its low performance it is strongly discouraged for production use

func NewFileAdapter

func NewFileAdapter(conf map[string]interface{}) (*FileAdapter, error)

NewFileAdapter returns an initialized file point store object

func (FileAdapter) AddPoint

func (fa FileAdapter) AddPoint(name string, p Point) error

AddPoint creates a new file with the JSON representation of the point in the subdirectory that corresponds to the given series

func (FileAdapter) AddSeries

func (fa FileAdapter) AddSeries(name string, sample Point, retentionDays int) error

AddSeries creates a directory to hold a time series

func (FileAdapter) DeleteSeries

func (fa FileAdapter) DeleteSeries(name string) error

DeleteSeries removes the subdirectory used to store a series

func (FileAdapter) Exists

func (fa FileAdapter) Exists(name string) (bool, error)

Exists returns true if a directory is present for the specified series, false if not or in case of error

func (FileAdapter) GetCount

func (fa FileAdapter) GetCount(name string, labels map[string]string) (int, error)

GetCount retrieves the number of points recorded for the given series (labels are ignored in this adapter for speed) (returns 0 if the series doesn't exist)

func (FileAdapter) GetLastN

func (fa FileAdapter) GetLastN(name string, labels map[string]string, n int) ([]Point, error)

GetLastN returns the last n points for the given series

func (FileAdapter) GetLatest

func (fa FileAdapter) GetLatest(name string, labels map[string]string) (Point, error)

GetLatest returns the most recent value of the series by looking for the most recent file in its subdir

func (FileAdapter) ListSeries

func (fa FileAdapter) ListSeries() ([]types.BriefSeries, error)

ListSeries returns a list of all the available series in the configured directory

func (FileAdapter) LoadTestSet

func (fa FileAdapter) LoadTestSet(name string) ([]Point, error)

LoadTestSet loads a set of points from a single file for testing (not part of the standard PointStore interface)

type Point

type Point struct {
	Labels    map[string]string
	Values    map[string]float32
	TimeStamp int64
}

Point represents a single measurement in a time series

func (Point) ID

func (p Point) ID() string

ID generates a string that uniquely identifies a point. Useful for deduplication

func (Point) MarshalJSON

func (p Point) MarshalJSON() ([]byte, error)

MarshalJSON is required for flattening the struct

func (*Point) UnmarshalJSON

func (p *Point) UnmarshalJSON(data []byte) error

UnmarshalJSON makes sure that we can recover a point struct from a flattened representation

type PointStore

type PointStore interface {
	// Adds a point to a series, should create it if it doesn't exist (calling AddSeries)
	AddPoint(name string, p Point) error
	// Create a new series
	AddSeries(name string, sample Point, retentionDays int) error
	// Delete a series
	DeleteSeries(name string) error
	Exists(name string) (bool, error)
	GetCount(name string, labels map[string]string) (int, error)
	// Gets the current value of the series
	GetLatest(name string, labels map[string]string) (Point, error)
	GetLastN(name string, labels map[string]string, n int) ([]Point, error)
	// Get list of available series
	ListSeries() ([]types.BriefSeries, error)
}

PointStore is an abstraction over the storage service that will be used to store the measurements taken from envs

func New

func New(conf config.Config) (PointStore, error)

New returns an initialized point store of the type specified in the configuration

type QResponse

type QResponse struct {
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
	Hits     struct {
		Total struct {
			Value    int    `json:"value"`
			Relation string `json:"relation"`
		} `json:"total"`
		Hits []struct {
			Index string `json:"_index"`
			ID    string `json:"_id"`
			P     Point  `json:"_source"`
		} `json:"hits"`
	} `json:"hits"`
}

QResponse is used to facilitate parsing Elasticsearch point query responses

Jump to

Keyboard shortcuts

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