Help us shape the future of Go! Take the 2026 Go Developer Survey

prom_plugin

package
v0.57.29 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Overview

Package prom_plugin stores Prometheus samples in a World, scrapes exporters into it from approved Devices, and answers PromQL over it.

Each scrape target is one World object. Its root is a block-backed key-value tree holding the target's labels and scrape config, its series table, and one immutable segment per commit window. A Store appends samples to an in-memory window and commits the window as one segment, and a Queryable serves the fork's storage.Queryable interface from the committed segments of several targets. The spacewave-prom plugin registers the prom/target ObjectType, whose process scrapes the target on the Device its ProcessBinding approves.

Index

Constants

View Source
const ChunkSamples = 120

ChunkSamples is the number of samples after which a window starts a new chunk for a series, the same cut Prometheus uses for its head chunks.

View Source
const CompactSpan = 2 * time.Hour

CompactSpan is the time bucket that compaction merges a target's segments into, the length of a Prometheus block.

View Source
const ConfigID = ControllerID

ConfigID is the config identifier.

View Source
const ControllerID = "plugin/prom"

ControllerID is the controller identifier.

View Source
const DefaultCommitWindow = time.Minute

DefaultCommitWindow is the commit window of a config that sets none.

View Source
const PluginID = "spacewave-prom"

PluginID is the manifest ID of the Prometheus plugin.

Variables

View Source
var (
	// ErrReservedLabel is returned when a sample's labels carry a name that the
	// store's target labels already provide.
	ErrReservedLabel = errors.New("prom: label name is set by the target")
	// ErrCommitInProgress is returned when a store is committed while another
	// commit of the same store has not finished.
	ErrCommitInProgress = errors.New("prom: commit already in progress")
	// ErrStoodDown is returned when another writer took over a store's target.
	ErrStoodDown = errors.New("prom: another Device took over the target")
	// ErrCorruptStore is returned when a target's stored keys do not follow the
	// store layout.
	ErrCorruptStore = errors.New("prom: corrupt store")
	// ErrUnknownEncoding is returned when a stored chunk uses an encoding this
	// version cannot read.
	ErrUnknownEncoding = errors.New("prom: unknown chunk encoding")
)
View Source
var (
	ChunkEncoding_name = map[int32]string{
		0: "CHUNK_ENCODING_UNKNOWN",
		1: "CHUNK_ENCODING_XOR",
	}
	ChunkEncoding_value = map[string]int32{
		"CHUNK_ENCODING_UNKNOWN": 0,
		"CHUNK_ENCODING_XOR":     1,
	}
)

Enum value maps for ChunkEncoding.

View Source
var Version = controller.MustParseVersion("0.0.1")

Version is the component version.

Functions

func NewFactory

func NewFactory(b bus.Bus) controller.Factory

NewFactory constructs the component factory.

func NewLabelSet

func NewLabelSet(lset labels.Labels) *s4wave_prom.LabelSet

NewLabelSet converts a Prometheus label set to its stored form.

func ToLabels

func ToLabels(s *s4wave_prom.LabelSet) labels.Labels

ToLabels converts a stored label set to a Prometheus label set.

Types

type Chunk

type Chunk struct {

	// MinTime is the first sample's timestamp in milliseconds.
	MinTime int64 `protobuf:"varint,1,opt,name=min_time,json=minTime,proto3" json:"minTime,omitempty"`
	// MaxTime is the last sample's timestamp in milliseconds.
	MaxTime int64 `protobuf:"varint,2,opt,name=max_time,json=maxTime,proto3" json:"maxTime,omitempty"`
	// Encoding is how Data encodes the samples.
	Encoding ChunkEncoding `protobuf:"varint,3,opt,name=encoding,proto3" json:"encoding,omitempty"`
	// Data holds the encoded samples.
	Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

Chunk is a run of one series' samples in one encoding.

func (*Chunk) CloneMessageVT

func (m *Chunk) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Chunk) CloneVT

func (m *Chunk) CloneVT() *Chunk

func (*Chunk) EqualMessageVT

func (this *Chunk) EqualMessageVT(thatMsg any) bool

func (*Chunk) EqualVT

func (this *Chunk) EqualVT(that *Chunk) bool

func (*Chunk) GetData

func (x *Chunk) GetData() []byte

func (*Chunk) GetEncoding

func (x *Chunk) GetEncoding() ChunkEncoding

func (*Chunk) GetMaxTime

func (x *Chunk) GetMaxTime() int64

func (*Chunk) GetMinTime

func (x *Chunk) GetMinTime() int64

func (*Chunk) MarshalJSON

func (x *Chunk) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Chunk to JSON.

func (*Chunk) MarshalProtoJSON

func (x *Chunk) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Chunk message to JSON.

func (*Chunk) MarshalProtoText

func (x *Chunk) MarshalProtoText() string

func (*Chunk) MarshalToSizedBufferVT

func (m *Chunk) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Chunk) MarshalToVT

func (m *Chunk) MarshalToVT(dAtA []byte) (int, error)

func (*Chunk) MarshalVT

func (m *Chunk) MarshalVT() (dAtA []byte, err error)

func (*Chunk) ProtoMessage

func (*Chunk) ProtoMessage()

func (*Chunk) Reset

func (x *Chunk) Reset()

func (*Chunk) SizeVT

func (m *Chunk) SizeVT() (n int)

func (*Chunk) String

func (x *Chunk) String() string

func (*Chunk) UnmarshalJSON

func (x *Chunk) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Chunk from JSON.

func (*Chunk) UnmarshalProtoJSON

func (x *Chunk) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Chunk message from JSON.

func (*Chunk) UnmarshalVT

func (m *Chunk) UnmarshalVT(dAtA []byte) error

type ChunkEncoding

type ChunkEncoding int32

ChunkEncoding identifies how a Chunk encodes its samples.

const (
	// CHUNK_ENCODING_UNKNOWN is the zero value; a stored chunk never carries it.
	ChunkEncoding_CHUNK_ENCODING_UNKNOWN ChunkEncoding = 0
	// CHUNK_ENCODING_XOR is the Prometheus XOR float chunk of tsdb/chunkenc.
	ChunkEncoding_CHUNK_ENCODING_XOR ChunkEncoding = 1
)

func (ChunkEncoding) Enum

func (x ChunkEncoding) Enum() *ChunkEncoding

func (ChunkEncoding) MarshalJSON

func (x ChunkEncoding) MarshalJSON() ([]byte, error)

MarshalJSON marshals the ChunkEncoding to JSON.

func (ChunkEncoding) MarshalProtoJSON

func (x ChunkEncoding) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the ChunkEncoding to JSON.

func (ChunkEncoding) MarshalProtoText

func (x ChunkEncoding) MarshalProtoText() string

func (ChunkEncoding) MarshalText

func (x ChunkEncoding) MarshalText() ([]byte, error)

MarshalText marshals the ChunkEncoding to text.

func (ChunkEncoding) String

func (x ChunkEncoding) String() string

func (*ChunkEncoding) UnmarshalJSON

func (x *ChunkEncoding) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the ChunkEncoding from JSON.

func (*ChunkEncoding) UnmarshalProtoJSON

func (x *ChunkEncoding) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the ChunkEncoding from JSON.

func (*ChunkEncoding) UnmarshalText

func (x *ChunkEncoding) UnmarshalText(b []byte) error

UnmarshalText unmarshals the ChunkEncoding from text.

type CommitStats

type CommitStats struct {
	// Segments is the number of segments written, one per store with samples.
	Segments int
	// Samples is the number of samples in the written segments.
	Samples int
	// Blocks is the number of encoded blocks the transaction submitted for
	// storage, including key-value tree nodes and the World's own blocks.
	Blocks uint64
	// Bytes is the number of encoded bytes of those blocks.
	Bytes uint64
}

CommitStats reports what one commit wrote.

func CommitStores

func CommitStores(ctx context.Context, eng world.Engine, stores ...*Store) (CommitStats, error)

CommitStores writes each store's open window as one segment, and moves every target's root, in one World transaction. It writes nothing for a store without samples, and returns zero stats when no store has any.

A write holds only the window's samples and the key-value tree nodes on the path to the new keys, so its size follows the window, not the target's history. If the transaction fails, no store changes: the next commit retries the same windows first. A store whose commit is still running makes CommitStores return ErrCommitInProgress without writing. A store whose target another writer has taken over writes nothing and stands down, as Store.Lost reports; the others commit.

type Config

type Config struct {

	// CommitWindowMs is how long a Device collects its targets' scrapes before
	// committing them in one World transaction. Zero commits every minute.
	CommitWindowMs uint32 `protobuf:"varint,1,opt,name=commit_window_ms,json=commitWindowMs,proto3" json:"commitWindowMs,omitempty"`
	// contains filtered or unexported fields
}

Config configures the Prometheus plugin controller.

func (*Config) CloneMessageVT

func (m *Config) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Config) CloneVT

func (m *Config) CloneVT() *Config

func (*Config) CommitWindow

func (c *Config) CommitWindow() time.Duration

CommitWindow returns the time between a Device's commits in one Space.

func (*Config) EqualMessageVT

func (this *Config) EqualMessageVT(thatMsg any) bool

func (*Config) EqualVT

func (this *Config) EqualVT(that *Config) bool

func (*Config) EqualsConfig

func (c *Config) EqualsConfig(other config.Config) bool

EqualsConfig checks if the config is equal to another.

func (*Config) GetCommitWindowMs

func (x *Config) GetCommitWindowMs() uint32

func (*Config) GetConfigID

func (c *Config) GetConfigID() string

GetConfigID returns the unique string for this configuration type.

func (*Config) MarshalJSON

func (x *Config) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Config to JSON.

func (*Config) MarshalProtoJSON

func (x *Config) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Config message to JSON.

func (*Config) MarshalProtoText

func (x *Config) MarshalProtoText() string

func (*Config) MarshalToSizedBufferVT

func (m *Config) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Config) MarshalToVT

func (m *Config) MarshalToVT(dAtA []byte) (int, error)

func (*Config) MarshalVT

func (m *Config) MarshalVT() (dAtA []byte, err error)

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (x *Config) Reset()

func (*Config) SizeVT

func (m *Config) SizeVT() (n int)

func (*Config) String

func (x *Config) String() string

func (*Config) UnmarshalJSON

func (x *Config) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Config from JSON.

func (*Config) UnmarshalProtoJSON

func (x *Config) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Config message from JSON.

func (*Config) UnmarshalVT

func (m *Config) UnmarshalVT(dAtA []byte) error

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type Controller

type Controller struct {
	*bus.BusController[*Config]
	// Holder publishes the registrations and reports when they are ready.
	*s4wave_plugin_registration.Holder
	// contains filtered or unexported fields
}

Controller registers prom/target and prom/dashboard with the core plugin and serves its resources.

func (*Controller) Execute

func (c *Controller) Execute(ctx context.Context) error

Execute registers the plugin's ObjectTypes with the core plugin until ctx ends.

func (*Controller) HandleDirective

func (c *Controller) HandleDirective(ctx context.Context, di directive.Instance) ([]directive.Resolver, error)

HandleDirective serves the plugin's resource service.

type Querier

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

Querier is a storage.Querier over a Queryable for one time range.

Select reads only the segments that overlap the range. Label lookups ignore time and report the labels of every committed series that matches.

func NewQuerier

func NewQuerier(q *Queryable, mint, maxt int64) *Querier

NewQuerier constructs a querier for samples between mint and maxt.

func (*Querier) Close

func (q *Querier) Close() error

Close releases the querier; it holds nothing.

func (*Querier) LabelNames

func (q *Querier) LabelNames(ctx context.Context, _ *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)

LabelNames returns the sorted label names of the series matching matchers.

func (*Querier) LabelValues

func (q *Querier) LabelValues(ctx context.Context, name string, _ *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)

LabelValues returns the sorted values of label name among the series matching matchers.

func (*Querier) Select

func (q *Querier) Select(ctx context.Context, _ bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet

Select returns the series matching matchers, sorted by labels. Series from several targets with the same labels are merged. A hints range inside the querier's range narrows the segments read.

type Queryable

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

Queryable is a storage.Queryable over the committed segments of several targets. It reads the World and keeps no state of its own, so it sees every commit the engine has and works against a synced copy of the World.

func NewQueryable

func NewQueryable(eng world.Engine, targets TargetLister) *Queryable

NewQueryable constructs a queryable over the targets that targets lists.

func (*Queryable) Querier

func (q *Queryable) Querier(mint, maxt int64) (storage.Querier, error)

Querier returns a querier for samples between mint and maxt, inclusive, in milliseconds.

type Segment

type Segment struct {

	// MinTime is the earliest sample timestamp in milliseconds, inclusive.
	MinTime int64 `protobuf:"varint,1,opt,name=min_time,json=minTime,proto3" json:"minTime,omitempty"`
	// MaxTime is the latest sample timestamp in milliseconds, inclusive.
	MaxTime int64 `protobuf:"varint,2,opt,name=max_time,json=maxTime,proto3" json:"maxTime,omitempty"`
	// Series holds the window's samples per series in series number order.
	Series []*SeriesChunks `protobuf:"bytes,3,rep,name=series,proto3" json:"series,omitempty"`
	// contains filtered or unexported fields
}

Segment is the immutable samples one commit window collected. Segments of one target do not overlap in time.

func (*Segment) CloneMessageVT

func (m *Segment) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Segment) CloneVT

func (m *Segment) CloneVT() *Segment

func (*Segment) EqualMessageVT

func (this *Segment) EqualMessageVT(thatMsg any) bool

func (*Segment) EqualVT

func (this *Segment) EqualVT(that *Segment) bool

func (*Segment) GetMaxTime

func (x *Segment) GetMaxTime() int64

func (*Segment) GetMinTime

func (x *Segment) GetMinTime() int64

func (*Segment) GetSeries

func (x *Segment) GetSeries() []*SeriesChunks

func (*Segment) MarshalJSON

func (x *Segment) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Segment to JSON.

func (*Segment) MarshalProtoJSON

func (x *Segment) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Segment message to JSON.

func (*Segment) MarshalProtoText

func (x *Segment) MarshalProtoText() string

func (*Segment) MarshalToSizedBufferVT

func (m *Segment) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Segment) MarshalToVT

func (m *Segment) MarshalToVT(dAtA []byte) (int, error)

func (*Segment) MarshalVT

func (m *Segment) MarshalVT() (dAtA []byte, err error)

func (*Segment) ProtoMessage

func (*Segment) ProtoMessage()

func (*Segment) Reset

func (x *Segment) Reset()

func (*Segment) SizeVT

func (m *Segment) SizeVT() (n int)

func (*Segment) String

func (x *Segment) String() string

func (*Segment) UnmarshalJSON

func (x *Segment) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Segment from JSON.

func (*Segment) UnmarshalProtoJSON

func (x *Segment) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Segment message from JSON.

func (*Segment) UnmarshalVT

func (m *Segment) UnmarshalVT(dAtA []byte) error

type SeriesChunks

type SeriesChunks struct {

	// Series is the series number in the target's series table.
	Series uint64 `protobuf:"varint,1,opt,name=series,proto3" json:"series,omitempty"`
	// Chunks are the series' chunks in ascending time order.
	Chunks []*Chunk `protobuf:"bytes,2,rep,name=chunks,proto3" json:"chunks,omitempty"`
	// contains filtered or unexported fields
}

SeriesChunks holds one series' chunks within a segment.

func (*SeriesChunks) CloneMessageVT

func (m *SeriesChunks) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*SeriesChunks) CloneVT

func (m *SeriesChunks) CloneVT() *SeriesChunks

func (*SeriesChunks) EqualMessageVT

func (this *SeriesChunks) EqualMessageVT(thatMsg any) bool

func (*SeriesChunks) EqualVT

func (this *SeriesChunks) EqualVT(that *SeriesChunks) bool

func (*SeriesChunks) GetChunks

func (x *SeriesChunks) GetChunks() []*Chunk

func (*SeriesChunks) GetSeries

func (x *SeriesChunks) GetSeries() uint64

func (*SeriesChunks) MarshalJSON

func (x *SeriesChunks) MarshalJSON() ([]byte, error)

MarshalJSON marshals the SeriesChunks to JSON.

func (*SeriesChunks) MarshalProtoJSON

func (x *SeriesChunks) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the SeriesChunks message to JSON.

func (*SeriesChunks) MarshalProtoText

func (x *SeriesChunks) MarshalProtoText() string

func (*SeriesChunks) MarshalToSizedBufferVT

func (m *SeriesChunks) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*SeriesChunks) MarshalToVT

func (m *SeriesChunks) MarshalToVT(dAtA []byte) (int, error)

func (*SeriesChunks) MarshalVT

func (m *SeriesChunks) MarshalVT() (dAtA []byte, err error)

func (*SeriesChunks) ProtoMessage

func (*SeriesChunks) ProtoMessage()

func (*SeriesChunks) Reset

func (x *SeriesChunks) Reset()

func (*SeriesChunks) SizeVT

func (m *SeriesChunks) SizeVT() (n int)

func (*SeriesChunks) String

func (x *SeriesChunks) String() string

func (*SeriesChunks) UnmarshalJSON

func (x *SeriesChunks) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the SeriesChunks from JSON.

func (*SeriesChunks) UnmarshalProtoJSON

func (x *SeriesChunks) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the SeriesChunks message from JSON.

func (*SeriesChunks) UnmarshalVT

func (m *SeriesChunks) UnmarshalVT(dAtA []byte) error

type SeriesPage

type SeriesPage struct {

	// FirstSeries is the series number of the first entry. Numbers are dense and
	// never reused, so the page covers FirstSeries through
	// FirstSeries + len(series) - 1.
	FirstSeries uint64 `protobuf:"varint,1,opt,name=first_series,json=firstSeries,proto3" json:"firstSeries,omitempty"`
	// Series holds the label sets of the added series in series number order.
	Series []*prom.LabelSet `protobuf:"bytes,2,rep,name=series,proto3" json:"series,omitempty"`
	// contains filtered or unexported fields
}

SeriesPage appends series to a target's series table. A commit writes a page only when its window introduced series.

func (*SeriesPage) CloneMessageVT

func (m *SeriesPage) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*SeriesPage) CloneVT

func (m *SeriesPage) CloneVT() *SeriesPage

func (*SeriesPage) EqualMessageVT

func (this *SeriesPage) EqualMessageVT(thatMsg any) bool

func (*SeriesPage) EqualVT

func (this *SeriesPage) EqualVT(that *SeriesPage) bool

func (*SeriesPage) GetFirstSeries

func (x *SeriesPage) GetFirstSeries() uint64

func (*SeriesPage) GetSeries

func (x *SeriesPage) GetSeries() []*prom.LabelSet

func (*SeriesPage) MarshalJSON

func (x *SeriesPage) MarshalJSON() ([]byte, error)

MarshalJSON marshals the SeriesPage to JSON.

func (*SeriesPage) MarshalProtoJSON

func (x *SeriesPage) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the SeriesPage message to JSON.

func (*SeriesPage) MarshalProtoText

func (x *SeriesPage) MarshalProtoText() string

func (*SeriesPage) MarshalToSizedBufferVT

func (m *SeriesPage) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*SeriesPage) MarshalToVT

func (m *SeriesPage) MarshalToVT(dAtA []byte) (int, error)

func (*SeriesPage) MarshalVT

func (m *SeriesPage) MarshalVT() (dAtA []byte, err error)

func (*SeriesPage) ProtoMessage

func (*SeriesPage) ProtoMessage()

func (*SeriesPage) Reset

func (x *SeriesPage) Reset()

func (*SeriesPage) SizeVT

func (m *SeriesPage) SizeVT() (n int)

func (*SeriesPage) String

func (x *SeriesPage) String() string

func (*SeriesPage) UnmarshalJSON

func (x *SeriesPage) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the SeriesPage from JSON.

func (*SeriesPage) UnmarshalProtoJSON

func (x *SeriesPage) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the SeriesPage message from JSON.

func (*SeriesPage) UnmarshalVT

func (m *SeriesPage) UnmarshalVT(dAtA []byte) error

type SeriesSet

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

SeriesSet is a storage.SeriesSet over series held in memory.

func NewSeriesSet

func NewSeriesSet(series []storage.Series) *SeriesSet

NewSeriesSet constructs a series set that returns series in order.

func (*SeriesSet) At

func (s *SeriesSet) At() storage.Series

At returns the current series.

func (*SeriesSet) Err

func (s *SeriesSet) Err() error

Err returns nil; the series are already read.

func (*SeriesSet) Next

func (s *SeriesSet) Next() bool

Next advances to the next series and reports whether there is one.

func (*SeriesSet) Warnings

func (s *SeriesSet) Warnings() annotations.Annotations

Warnings returns no warnings.

type SeriesTable

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

SeriesTable maps the label sets of a target's series to dense series numbers. A number is the index of the label set in the table, is never reused, and is what segments store in place of the labels.

A SeriesTable is not safe for concurrent use.

func NewSeriesTable

func NewSeriesTable() *SeriesTable

NewSeriesTable constructs an empty series table.

func (*SeriesTable) Add

func (t *SeriesTable) Add(lset labels.Labels) uint64

Add appends lset as the next series and returns its number. The caller checks Lookup first; Add does not look for duplicates.

func (*SeriesTable) Labels

func (t *SeriesTable) Labels(num uint64) labels.Labels

Labels returns the label set of series num.

func (*SeriesTable) LabelsFrom

func (t *SeriesTable) LabelsFrom(from uint64) []labels.Labels

LabelsFrom returns the label sets from series number from to the end.

func (*SeriesTable) Len

func (t *SeriesTable) Len() uint64

Len returns the number of series in the table.

func (*SeriesTable) Lookup

func (t *SeriesTable) Lookup(lset labels.Labels) (uint64, bool)

Lookup returns the series number of lset.

func (*SeriesTable) Truncate

func (t *SeriesTable) Truncate(n uint64)

Truncate drops the series numbered n and above.

type StaticTargets

type StaticTargets []string

StaticTargets is a TargetLister with a fixed list of object keys.

func (StaticTargets) ListTargets

func (t StaticTargets) ListTargets(context.Context) ([]string, error)

ListTargets returns the fixed object keys.

type Store

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

Store is the single writer of one target's samples.

The target is a World object whose root is a block-backed key-value tree. The Store keeps the open window and the target's series table in memory; Append adds to the window and CommitStores writes the window as one segment. A crash or Rollback loses only the uncommitted window. Exactly one Store writes a target, so a Store reads the tree after it opens only to maintain its segments and to check that it is still the writer: the commit that closes a CompactSpan bucket drops expired segments and merges the closed buckets' segments in the same transaction, and a commit that finds a status this Store did not write stands the Store down instead of writing.

func CreateStore

func CreateStore(ctx context.Context, eng world.Engine, key string, target labels.Labels) (*Store, error)

CreateStore creates the World object key as an empty target carrying the labels target on every series, and returns its writer.

func OpenStore

func OpenStore(ctx context.Context, eng world.Engine, key string) (*Store, error)

OpenStore opens the existing target key for writing, reading its labels, series table and latest committed time.

func (*Store) Append

func (s *Store) Append(lset labels.Labels, t int64, v float64) error

Append adds a sample of the series lset to the open window.

lset must not carry a name that the target's labels set. The timestamp must be later than every sample the target has committed or is committing, and later than the series' earlier samples in the open window; otherwise Append returns storage.ErrOutOfOrderSample, or storage.ErrDuplicateSampleForTimestamp for the same time with another value.

func (*Store) AppendStale

func (s *Store) AppendStale(lset labels.Labels, t int64) error

AppendStale adds a stale marker for the series lset at time t, which tells PromQL the series ended, as Prometheus does for a failed or vanished scrape.

func (*Store) Key

func (s *Store) Key() string

Key returns the World object key of the target.

func (*Store) Lost

func (s *Store) Lost() <-chan struct{}

Lost returns a channel closed when a commit finds that another writer wrote the target's status since this Store opened it. A lost Store writes nothing more; the writer reopens the target to write again.

func (*Store) Rollback

func (s *Store) Rollback() error

Rollback discards every uncommitted sample and the series only they introduced. It returns ErrCommitInProgress while a commit is running.

func (*Store) SetStatus

func (s *Store) SetStatus(status *s4wave_prom.TargetStatus) error

SetStatus records status to commit with the next window that holds samples. A later call replaces an uncommitted status.

type StoreReader

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

StoreReader reads one target's key-value tree: its labels, series table and segments. It holds no state beyond the transaction, which the caller discards.

func NewStoreReader

func NewStoreReader(kv kvtx.Tx) *StoreReader

NewStoreReader constructs a reader over a transaction on a target's tree.

func (*StoreReader) ForEachSegment

func (r *StoreReader) ForEachSegment(ctx context.Context, mint, maxt int64, fn func(*Segment) error) error

ForEachSegment calls fn with each segment overlapping mint to maxt inclusive, in time order. Segment keys carry the time range, so a segment outside the range is not read.

func (*StoreReader) Labels

func (r *StoreReader) Labels(ctx context.Context, matchers []*labels.Matcher) ([]labels.Labels, error)

Labels returns the full label sets of the target's series matching matchers, ignoring time.

func (*StoreReader) LastSegmentMaxTime

func (r *StoreReader) LastSegmentMaxTime(ctx context.Context) (int64, bool, error)

LastSegmentMaxTime returns the latest sample time the target has committed. It returns false when the target has no segment.

func (*StoreReader) Meta

Meta returns the target's TargetMeta.

func (*StoreReader) Select

func (r *StoreReader) Select(ctx context.Context, mint, maxt int64, matchers []*labels.Matcher) ([]storage.Series, error)

Select returns the target's series matching matchers, with their samples in mint to maxt. The target's labels are added to every series. The series are not sorted.

func (*StoreReader) Table

func (r *StoreReader) Table(ctx context.Context) (*SeriesTable, error)

Table reads the target's series table from its series pages.

func (*StoreReader) TargetLabels

func (r *StoreReader) TargetLabels(ctx context.Context) (labels.Labels, error)

TargetLabels returns the labels every series of the target carries.

type TargetLister

type TargetLister interface {
	// ListTargets returns the object keys of the targets to query. A key whose
	// object does not exist is skipped by the query.
	ListTargets(ctx context.Context) ([]string, error)
}

TargetLister lists the World object keys of the targets a Queryable reads. The Space's set of prom/target objects is the list; a lister is where that set comes from.

type Window

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

Window collects the samples one commit appends, per series, in XOR chunks.

A window holds only samples that are not yet committed, so the bytes a commit writes follow the window, not the history of the series. A Window is not safe for concurrent use; the Store that owns it serializes access.

func NewWindow

func NewWindow(firstSeries uint64) *Window

NewWindow constructs an empty window. firstSeries is the number the next new series of the target's series table will get.

func (*Window) Append

func (w *Window) Append(num uint64, t int64, v float64) error

Append adds a sample of series num.

Timestamps of one series must increase. Repeating the latest timestamp with the same value is accepted and ignored, as Prometheus does. Repeating it with another value returns storage.ErrDuplicateSampleForTimestamp, and an earlier timestamp returns storage.ErrOutOfOrderSample.

func (*Window) FirstSeries

func (w *Window) FirstSeries() uint64

FirstSeries returns the number of the first series the window introduced.

func (*Window) Samples

func (w *Window) Samples() int

Samples returns the number of samples in the window.

func (*Window) Segment

func (w *Window) Segment() *Segment

Segment encodes the window as a segment. It returns nil for an empty window.

Jump to

Keyboard shortcuts

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