2014-08-21 13:06:11 -07:00
|
|
|
package index
|
|
|
|
|
|
|
|
import (
|
2014-09-09 05:36:26 -07:00
|
|
|
"encoding"
|
|
|
|
|
2014-08-21 13:06:11 -07:00
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
)
|
|
|
|
|
2014-09-09 05:36:26 -07:00
|
|
|
// MetricIndexer indexes facets of a clientmodel.Metric. Implementers may or may
|
|
|
|
// not be concurrency-safe.
|
2014-08-21 13:06:11 -07:00
|
|
|
type MetricIndexer interface {
|
2014-09-09 05:36:26 -07:00
|
|
|
// IndexMetrics adds metrics to the index. If the metrics was added
|
|
|
|
// before and has been archived in the meantime, it is now un-archived.
|
2014-08-21 13:06:11 -07:00
|
|
|
IndexMetrics(FingerprintMetricMapping) error
|
|
|
|
// UnindexMetrics removes metrics from the index.
|
|
|
|
UnindexMetrics(FingerprintMetricMapping) error
|
2014-09-09 05:36:26 -07:00
|
|
|
// ArchiveMetrics marks the metric with the given fingerprint as
|
|
|
|
// 'archived', which has to be called if upon eviction of the
|
|
|
|
// corresponding time series from memory. By calling this method, the
|
|
|
|
// MetricIndexer learns about the time range of the evicted time series,
|
|
|
|
// which is used later for the decision if an evicted time series has to
|
|
|
|
// be moved back into memory. The implementer of MetricIndexer can make
|
|
|
|
// use of the archived state, e.g. by saving archived metrics in an
|
|
|
|
// on-disk index and non-archived metrics in an in-memory index.
|
|
|
|
ArchiveMetrics(fp clientmodel.Fingerprint, first, last clientmodel.Timestamp) error
|
2014-08-21 13:06:11 -07:00
|
|
|
|
|
|
|
// GetMetricForFingerprint returns the metric associated with the provided fingerprint.
|
|
|
|
GetMetricForFingerprint(clientmodel.Fingerprint) (clientmodel.Metric, error)
|
|
|
|
// GetFingerprintsForLabelPair returns all fingerprints for the provided label pair.
|
|
|
|
GetFingerprintsForLabelPair(l clientmodel.LabelName, v clientmodel.LabelValue) (clientmodel.Fingerprints, error)
|
|
|
|
// GetLabelValuesForLabelName returns all label values associated with a given label name.
|
|
|
|
GetLabelValuesForLabelName(clientmodel.LabelName) (clientmodel.LabelValues, error)
|
2014-09-09 05:36:26 -07:00
|
|
|
// HasFingerprint returns true if a metric with the given fingerprint
|
|
|
|
// has been indexed and has NOT been archived yet.
|
2014-08-21 13:06:11 -07:00
|
|
|
HasFingerprint(clientmodel.Fingerprint) (bool, error)
|
2014-09-09 05:36:26 -07:00
|
|
|
// HasArchivedFingerprint returns true if a metric with the given
|
|
|
|
// fingerprint was indexed before and has been archived in the
|
|
|
|
// meantime. In that case, the time range of the archived metric is also
|
|
|
|
// returned.
|
|
|
|
HasArchivedFingerprint(clientmodel.Fingerprint) (present bool, first, last clientmodel.Timestamp, err error)
|
|
|
|
|
|
|
|
Close() error
|
2014-08-21 13:06:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// KeyValueStore persists key/value pairs.
|
|
|
|
type KeyValueStore interface {
|
2014-09-09 05:36:26 -07:00
|
|
|
Put(key, value encoding.BinaryMarshaler) error
|
|
|
|
Get(k encoding.BinaryMarshaler, v encoding.BinaryUnmarshaler) (bool, error)
|
|
|
|
Has(k encoding.BinaryMarshaler) (has bool, err error)
|
|
|
|
Delete(k encoding.BinaryMarshaler) error
|
2014-08-21 13:06:11 -07:00
|
|
|
|
|
|
|
NewBatch() Batch
|
|
|
|
Commit(b Batch) error
|
|
|
|
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Batch allows KeyValueStore mutations to be pooled and committed together.
|
|
|
|
type Batch interface {
|
2014-09-09 05:36:26 -07:00
|
|
|
Put(key, value encoding.BinaryMarshaler) error
|
|
|
|
Delete(key encoding.BinaryMarshaler) error
|
2014-08-21 13:06:11 -07:00
|
|
|
Reset()
|
|
|
|
}
|