mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Merge pull request #76 from prometheus/refactor/storage/simplifications
Interface simplification.
This commit is contained in:
commit
ae01bce5f1
|
@ -30,20 +30,20 @@ type PersistenceAdapter struct {
|
|||
// AST-global persistence to use.
|
||||
var persistenceAdapter *PersistenceAdapter = nil
|
||||
|
||||
func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) ([]*model.Metric, error) {
|
||||
func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) (metrics []model.Metric, err error) {
|
||||
fingerprints, err := p.persistence.GetFingerprintsForLabelSet(labels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
metrics := []*model.Metric{}
|
||||
for _, fingerprint := range fingerprints {
|
||||
metric, err := p.persistence.GetMetricForFingerprint(fingerprint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return metrics, err
|
||||
}
|
||||
metrics = append(metrics, metric)
|
||||
}
|
||||
return metrics, nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *time.Time) ([]*model.Sample, error) {
|
||||
|
@ -53,7 +53,7 @@ func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *ti
|
|||
}
|
||||
samples := []*model.Sample{}
|
||||
for _, metric := range metrics {
|
||||
sample, err := p.persistence.GetValueAtTime(*metric, *timestamp, *p.stalenessPolicy)
|
||||
sample, err := p.persistence.GetValueAtTime(metric, *timestamp, *p.stalenessPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *
|
|||
sampleSets := []*model.SampleSet{}
|
||||
for _, metric := range metrics {
|
||||
// TODO: change to GetBoundaryValues() once it has the right return type.
|
||||
sampleSet, err := p.persistence.GetRangeValues(*metric, *interval, *p.stalenessPolicy)
|
||||
sampleSet, err := p.persistence.GetRangeValues(metric, *interval, *p.stalenessPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *
|
|||
}
|
||||
|
||||
// TODO remove when persistence return value is fixed.
|
||||
sampleSet.Metric = *metric
|
||||
sampleSet.Metric = metric
|
||||
sampleSets = append(sampleSets, sampleSet)
|
||||
}
|
||||
return sampleSets, nil
|
||||
|
@ -97,7 +97,7 @@ func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *mod
|
|||
|
||||
sampleSets := []*model.SampleSet{}
|
||||
for _, metric := range metrics {
|
||||
sampleSet, err := p.persistence.GetRangeValues(*metric, *interval, *p.stalenessPolicy)
|
||||
sampleSet, err := p.persistence.GetRangeValues(metric, *interval, *p.stalenessPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *mod
|
|||
}
|
||||
|
||||
// TODO remove when persistence return value is fixed.
|
||||
sampleSet.Metric = *metric
|
||||
sampleSet.Metric = metric
|
||||
sampleSets = append(sampleSets, sampleSet)
|
||||
}
|
||||
return sampleSets, nil
|
||||
|
|
|
@ -40,7 +40,7 @@ type MetricPersistence interface {
|
|||
// name.
|
||||
GetFingerprintsForLabelName(model.LabelName) ([]model.Fingerprint, error)
|
||||
|
||||
GetMetricForFingerprint(model.Fingerprint) (*model.Metric, error)
|
||||
GetMetricForFingerprint(model.Fingerprint) (model.Metric, error)
|
||||
|
||||
GetValueAtTime(model.Metric, time.Time, StalenessPolicy) (*model.Sample, error)
|
||||
GetBoundaryValues(model.Metric, model.Interval, StalenessPolicy) (*model.Sample, *model.Sample, error)
|
||||
|
|
|
@ -892,11 +892,11 @@ func TestGetMetricForFingerprint(t *testing.T) {
|
|||
t.Error(e)
|
||||
}
|
||||
|
||||
if len(*v) != 1 {
|
||||
if len(v) != 1 {
|
||||
t.Errorf("Expected one-dimensional metric.")
|
||||
}
|
||||
|
||||
if (*v)["request_type"] != "your_mom" {
|
||||
if v["request_type"] != "your_mom" {
|
||||
t.Errorf("Expected metric to match.")
|
||||
}
|
||||
|
||||
|
@ -918,15 +918,15 @@ func TestGetMetricForFingerprint(t *testing.T) {
|
|||
t.Error(e)
|
||||
}
|
||||
|
||||
if len(*v) != 2 {
|
||||
if len(v) != 2 {
|
||||
t.Errorf("Expected one-dimensional metric.")
|
||||
}
|
||||
|
||||
if (*v)["request_type"] != "your_dad" {
|
||||
if v["request_type"] != "your_dad" {
|
||||
t.Errorf("Expected metric to match.")
|
||||
}
|
||||
|
||||
if (*v)["one-off"] != "value" {
|
||||
if v["one-off"] != "value" {
|
||||
t.Errorf("Expected metric to match.")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.L
|
|||
return
|
||||
}
|
||||
|
||||
func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f model.Fingerprint) (m *model.Metric, err error) {
|
||||
func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f model.Fingerprint) (m model.Metric, err error) {
|
||||
begin := time.Now()
|
||||
|
||||
defer func() {
|
||||
|
@ -279,9 +279,10 @@ func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f model.Fingerprint)
|
|||
return
|
||||
}
|
||||
|
||||
m = &model.Metric{}
|
||||
m = model.Metric{}
|
||||
|
||||
for _, v := range unmarshaled.LabelPair {
|
||||
(*m)[model.LabelName(*v.Name)] = model.LabelValue(*v.Value)
|
||||
m[model.LabelName(*v.Name)] = model.LabelValue(*v.Value)
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue