mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
AST persistence adapter simplifications after storage changes.
This commit is contained in:
parent
e50de005f9
commit
2f814d0e6d
|
@ -30,57 +30,36 @@ type PersistenceAdapter struct {
|
||||||
// AST-global persistence to use.
|
// AST-global persistence to use.
|
||||||
var persistenceAdapter *PersistenceAdapter = nil
|
var persistenceAdapter *PersistenceAdapter = nil
|
||||||
|
|
||||||
func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) (fingerprintToMetric map[model.Fingerprint]model.Metric, err error) {
|
func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *time.Time) (samples []*model.Sample, err error) {
|
||||||
fingerprints, err := p.persistence.GetFingerprintsForLabelSet(labels)
|
fingerprints, err := p.persistence.GetFingerprintsForLabelSet(labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fingerprintToMetric = make(map[model.Fingerprint]model.Metric)
|
|
||||||
for _, fingerprint := range fingerprints {
|
for _, fingerprint := range fingerprints {
|
||||||
var metric *model.Metric // Don't shadow err.
|
var sample *model.Sample // Don't shadow err.
|
||||||
metric, err = p.persistence.GetMetricForFingerprint(fingerprint)
|
sample, err = p.persistence.GetValueAtTime(fingerprint, *timestamp, *p.stalenessPolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if metric == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fingerprintToMetric[fingerprint] = *metric
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *time.Time) ([]*model.Sample, error) {
|
|
||||||
metrics, err := p.getMetricsWithLabels(labels)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
samples := []*model.Sample{}
|
|
||||||
for fingerprint := range metrics {
|
|
||||||
sample, err := p.persistence.GetValueAtTime(fingerprint, *timestamp, *p.stalenessPolicy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if sample == nil {
|
if sample == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
samples = append(samples, sample)
|
samples = append(samples, sample)
|
||||||
}
|
}
|
||||||
return samples, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *model.Interval) ([]*model.SampleSet, error) {
|
func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *model.Interval) (sampleSets []*model.SampleSet, err error) {
|
||||||
metrics, err := p.getMetricsWithLabels(labels)
|
fingerprints, err := p.persistence.GetFingerprintsForLabelSet(labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sampleSets := []*model.SampleSet{}
|
for _, fingerprint := range fingerprints {
|
||||||
for fingerprint, metric := range metrics {
|
var sampleSet *model.SampleSet // Don't shadow err.
|
||||||
// TODO: change to GetBoundaryValues() once it has the right return type.
|
// TODO: change to GetBoundaryValues() once it has the right return type.
|
||||||
sampleSet, err := p.persistence.GetRangeValues(fingerprint, *interval)
|
sampleSet, err = p.persistence.GetRangeValues(fingerprint, *interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -88,22 +67,20 @@ func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove when persistence return value is fixed.
|
|
||||||
sampleSet.Metric = metric
|
|
||||||
sampleSets = append(sampleSets, sampleSet)
|
sampleSets = append(sampleSets, sampleSet)
|
||||||
}
|
}
|
||||||
return sampleSets, nil
|
return sampleSets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *model.Interval) ([]*model.SampleSet, error) {
|
func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *model.Interval) (sampleSets []*model.SampleSet, err error) {
|
||||||
metrics, err := p.getMetricsWithLabels(labels)
|
fingerprints, err := p.persistence.GetFingerprintsForLabelSet(labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sampleSets := []*model.SampleSet{}
|
for _, fingerprint := range fingerprints {
|
||||||
for fingerprint, metric := range metrics {
|
var sampleSet *model.SampleSet // Don't shadow err.
|
||||||
sampleSet, err := p.persistence.GetRangeValues(fingerprint, *interval)
|
sampleSet, err = p.persistence.GetRangeValues(fingerprint, *interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -111,8 +88,6 @@ func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *mod
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove when persistence return value is fixed.
|
|
||||||
sampleSet.Metric = metric
|
|
||||||
sampleSets = append(sampleSets, sampleSet)
|
sampleSets = append(sampleSets, sampleSet)
|
||||||
}
|
}
|
||||||
return sampleSets, nil
|
return sampleSets, nil
|
||||||
|
|
Loading…
Reference in a new issue