pgmodel

package
v0.0.0-...-855edac 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: 35 Imported by: 0

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

View Source
const (
	DefaultMetricCacheSize = 10000
)
View Source
const GetLabelsSQL = "SELECT (labels_info($1::int[])).*"
View Source
const (
	MetricNameLabelName = "__name__"
)
View Source
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

View Source
var (
	// ErrEntryNotFound is returned when entry is not found.
	ErrEntryNotFound = fmt.Errorf("entry not found")
)
View Source
var (
	ErrNoMetricName = fmt.Errorf("metric name missing")
)
View Source
var (
	ExtensionIsInstalled = false
)
View Source
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

func CheckSchemaVersion(ctx context.Context, conn *pgx.Conn, versionInfo VersionInfo) error

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 Cfg

type Cfg struct {
	AsyncAcks       bool
	ReportInterval  int
	SeriesCacheSize uint64
	NumCopiers      int
}

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) Close

func (i *DBIngestor) Close()

Close closes the ingestor

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

func (r *DBReader) HealthCheck() error

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 GetLabels

func GetLabels(str string) (l *Labels)

func LabelsFromSlice

func LabelsFromSlice(ls labels.Labels) (*Labels, error)

LabelsFromSlice converts a labels.Labels to a Labels object

func SetLabels

func SetLabels(str string, lset *Labels) *Labels

func (*Labels) Compare

func (l *Labels) Compare(b *Labels) int

Compare returns a comparison int between two Labels

func (*Labels) Equal

func (l *Labels) Equal(b *Labels) bool

Equal returns true if two Labels are equal

func (*Labels) Len

func (l *Labels) Len() int

func (*Labels) Less

func (l *Labels) Less(i, j int) bool

func (*Labels) String

func (l *Labels) String() string

func (*Labels) Swap

func (l *Labels) Swap(i, j int)

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

func (*MetricNameCache) Set

func (m *MetricNameCache) Set(metric string, tableName string) error

Set stores table name for specified metric.

type Migrator

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

func NewMigrator

func NewMigrator(db *pgx.Conn, sqlFiles http.FileSystem, toc map[string][]string) *Migrator

func (*Migrator) Migrate

func (t *Migrator) Migrate(appVersion semver.Version) error

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

func (*SampleInfoIterator) Values

func (t *SampleInfoIterator) Values() (time.Time, float64, SeriesID)

Values returns the values for the current row

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).

type VersionInfo

type VersionInfo struct {
	Version    string
	CommitHash string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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