Documentation
¶
Overview ¶
This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
Index ¶
- Constants
- Variables
- func CheckDependencies(db *pgx.Conn, versionInfo VersionInfo) (err error)
- func CheckSchemaVersion(ctx context.Context, conn *pgx.Conn, versionInfo VersionInfo) error
- func FinishWriteRequest(wr *prompb.WriteRequest)
- func FromLabelMatchers(matchers []*prompb.LabelMatcher) ([]*labels.Matcher, error)
- func Migrate(db *pgx.Conn, versionInfo VersionInfo) (err error)
- func NewWriteRequest() *prompb.WriteRequest
- type Cfg
- type DBCreator
- type DBIngestor
- type DBInserter
- type DBReader
- type HealthChecker
- type Labels
- type MetricCache
- type MetricNameCache
- type Migrator
- type Querier
- type QueryHealthChecker
- type Reader
- type SampleInfoIterator
- type SeriesCache
- type SeriesID
- type VersionInfo
Constants ¶
const (
DefaultMetricCacheSize = 10000
)
const GetLabelsSQL = "SELECT (labels_info($1::int[])).*"
const (
MetricNameLabelName = "__name__"
)
const ( // Postgres time zero is Sat Jan 01 00:00:00 2000 UTC. // This is the offset of the Unix epoch in milliseconds from the Postgres zero. PostgresUnixEpoch = -946684800000 )
Variables ¶
var ( // ErrEntryNotFound is returned when entry is not found. ErrEntryNotFound = fmt.Errorf("entry not found") )
var (
ErrNoMetricName = fmt.Errorf("metric name missing")
)
var (
ExtensionIsInstalled = false
)
var LabelsInterner = sync.Map{}
Functions ¶
func CheckDependencies ¶
func CheckDependencies(db *pgx.Conn, versionInfo VersionInfo) (err error)
CheckDependencies makes sure all project dependencies, including the DB schema the extension, are set up correctly. This will set the ExtensionIsInstalled flag and thus should only be called once, at initialization.
func CheckSchemaVersion ¶
CheckSchemaVersion checks the DB schema version without checking the extension
func FinishWriteRequest ¶
func FinishWriteRequest(wr *prompb.WriteRequest)
func FromLabelMatchers ¶
func FromLabelMatchers(matchers []*prompb.LabelMatcher) ([]*labels.Matcher, error)
FromLabelMatchers parses protobuf label matchers to Prometheus label matchers.
func Migrate ¶
func Migrate(db *pgx.Conn, versionInfo VersionInfo) (err error)
Migrate performs a database migration to the latest version
func NewWriteRequest ¶
func NewWriteRequest() *prompb.WriteRequest
Types ¶
type DBCreator ¶
type DBCreator interface {
// Init should set up any connection or other setup for talking to the DB,
// but should NOT create any databases.
Init()
// DBExists checks if a database with the given name currently exists.
DBExists(dbName string) bool
// CreateDB creates a database with the given name.
CreateDB(dbName string) error
// RemoveOldDB removes an existing database with the given name.
RemoveOldDB(dbName string) error
// CreateSchema does further initialization after the database is created.
CreateSchema(dbName string) error
}
DBCreator is used for initial setup of the database by preparing the correct series schema.
type DBIngestor ¶
type DBIngestor struct {
// contains filtered or unexported fields
}
DBIngestor ingest the TimeSeries data into Timescale database.
func NewPgxIngestor ¶
func NewPgxIngestor(c *pgxpool.Pool) (*DBIngestor, error)
NewPgxIngestor returns a new Ingestor that write to PostgreSQL using PGX
func NewPgxIngestorWithMetricCache ¶
func NewPgxIngestorWithMetricCache(c *pgxpool.Pool, cache MetricCache, cfg *Cfg) (*DBIngestor, error)
NewPgxIngestorWithMetricCache returns a new Ingestor that uses connection pool and a metrics cache for caching metric table names.
func (*DBIngestor) CompleteMetricCreation ¶
func (i *DBIngestor) CompleteMetricCreation() error
func (*DBIngestor) Ingest ¶
func (i *DBIngestor) Ingest(tts []prompb.TimeSeries, req *prompb.WriteRequest) (uint64, error)
Ingest transforms and ingests the timeseries data into Timescale database.
type DBInserter ¶
type DBInserter interface {
// Ingest takes an array of TimeSeries and attepts to store it into the database.
// Returns the number of metrics ingested and any error encountered before finishing.
Ingest([]prompb.TimeSeries, *prompb.WriteRequest) (uint64, error)
}
DBInserter is responsible for ingesting the TimeSeries protobuf structs and storing them in the database.
type DBReader ¶
type DBReader struct {
// contains filtered or unexported fields
}
DBReader reads data from the database.
func NewPgxReader ¶
func NewPgxReader(c *pgxpool.Pool, readHist prometheus.ObserverVec, labelsCacheSize uint64) *DBReader
NewPgxReader returns a new DBReader that reads that from PostgreSQL using PGX.
func NewPgxReaderWithMetricCache ¶
func NewPgxReaderWithMetricCache(c *pgxpool.Pool, cache MetricCache, labelsCacheSize uint64) *DBReader
NewPgxReaderWithMetricCache returns a new DBReader that reads from PostgreSQL using PGX and caches metric table names using the supplied cacher.
func (*DBReader) GetQuerier ¶
func (r *DBReader) GetQuerier() QueryHealthChecker
func (*DBReader) HealthCheck ¶
HealthCheck checks that the reader is properly connected
func (*DBReader) Read ¶
func (r *DBReader) Read(req *prompb.ReadRequest) (*prompb.ReadResponse, error)
type HealthChecker ¶
type HealthChecker interface {
HealthCheck() error
}
HealthChecker allows checking for proper operations.
type Labels ¶
type Labels struct {
// contains filtered or unexported fields
}
Labels stores a labels.Labels in its canonical string representation
func LabelsFromSlice ¶
LabelsFromSlice converts a labels.Labels to a Labels object
type MetricCache ¶
type MetricCache interface {
Get(metric string) (string, error)
Set(metric string, tableName string) error
}
MetricCache provides a caching mechanism for metric table names.
type MetricNameCache ¶
type MetricNameCache struct {
Metrics *clockcache.Cache
}
MetricNameCache stores and retrieves metric table names in a in-memory cache.
func (*MetricNameCache) Capacity ¶
func (m *MetricNameCache) Capacity() int
func (*MetricNameCache) Get ¶
func (m *MetricNameCache) Get(metric string) (string, error)
Get fetches the table name for specified metric.
func (*MetricNameCache) NumElements ¶
func (m *MetricNameCache) NumElements() int
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
func NewMigrator ¶
type Querier ¶
type Querier interface {
Query(*prompb.Query) ([]*prompb.TimeSeries, error)
Select(mint int64, maxt int64, sortSeries bool, hints *storage.SelectHints, path []parser.Node, ms ...*labels.Matcher) (storage.SeriesSet, parser.Node)
LabelNames() ([]string, error)
LabelValues(labelName string) ([]string, error)
NumCachedLabels() int
LabelsCacheCapacity() int
}
Querier queries the data using the provided query data and returns the matching timeseries.
type QueryHealthChecker ¶
type QueryHealthChecker interface {
Querier
HealthChecker
}
QueryHealthChecker can query and check its own health.
type Reader ¶
type Reader interface {
Read(*prompb.ReadRequest) (*prompb.ReadResponse, error)
}
Reader reads the data based on the provided read request.
type SampleInfoIterator ¶
type SampleInfoIterator struct {
// contains filtered or unexported fields
}
SampleInfoIterator is an iterator over a collection of sampleInfos that returns data in the format expected for the data table row.
func NewSampleInfoIterator ¶
func NewSampleInfoIterator() SampleInfoIterator
NewSampleInfoIterator is the constructor
func (*SampleInfoIterator) Append ¶
func (t *SampleInfoIterator) Append(s samplesInfo)
Append adds a sample info to the back of the iterator
func (*SampleInfoIterator) Err ¶
func (t *SampleInfoIterator) Err() error
Err returns any error that has been encountered by the CopyFromSource. If this is not nil *Conn.CopyFrom will abort the copy.
func (*SampleInfoIterator) Next ¶
func (t *SampleInfoIterator) Next() bool
Next returns true if there is another row and makes the next row data available to Values(). When there are no more rows available or an error has occurred it returns false.
func (*SampleInfoIterator) ResetPosition ¶
func (t *SampleInfoIterator) ResetPosition()
ResetPosition resets the iteration position to the beginning
type SeriesCache ¶
type SeriesCache interface {
GetSeries(lset Labels) (SeriesID, error)
SetSeries(lset Labels, id SeriesID) error
NumElements() int
Capacity() int
}
SeriesCache provides a caching mechanism for labels and series.
type SeriesID ¶
type SeriesID int64
SeriesID represents a globally unique id for the series. This should be equivalent to the PostgreSQL type in the series table (currently BIGINT).