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.
|
// AST-global persistence to use.
|
||||||
var persistenceAdapter *PersistenceAdapter = nil
|
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)
|
fingerprints, err := p.persistence.GetFingerprintsForLabelSet(labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
metrics := []*model.Metric{}
|
|
||||||
for _, fingerprint := range fingerprints {
|
for _, fingerprint := range fingerprints {
|
||||||
metric, err := p.persistence.GetMetricForFingerprint(fingerprint)
|
metric, err := p.persistence.GetMetricForFingerprint(fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return metrics, err
|
||||||
}
|
}
|
||||||
metrics = append(metrics, metric)
|
metrics = append(metrics, metric)
|
||||||
}
|
}
|
||||||
return metrics, nil
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersistenceAdapter) GetValueAtTime(labels model.LabelSet, timestamp *time.Time) ([]*model.Sample, error) {
|
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{}
|
samples := []*model.Sample{}
|
||||||
for _, metric := range metrics {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *
|
||||||
sampleSets := []*model.SampleSet{}
|
sampleSets := []*model.SampleSet{}
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
// 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(*metric, *interval, *p.stalenessPolicy)
|
sampleSet, err := p.persistence.GetRangeValues(metric, *interval, *p.stalenessPolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func (p *PersistenceAdapter) GetBoundaryValues(labels model.LabelSet, interval *
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove when persistence return value is fixed.
|
// TODO remove when persistence return value is fixed.
|
||||||
sampleSet.Metric = *metric
|
sampleSet.Metric = metric
|
||||||
sampleSets = append(sampleSets, sampleSet)
|
sampleSets = append(sampleSets, sampleSet)
|
||||||
}
|
}
|
||||||
return sampleSets, nil
|
return sampleSets, nil
|
||||||
|
@ -97,7 +97,7 @@ func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *mod
|
||||||
|
|
||||||
sampleSets := []*model.SampleSet{}
|
sampleSets := []*model.SampleSet{}
|
||||||
for _, metric := range metrics {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func (p *PersistenceAdapter) GetRangeValues(labels model.LabelSet, interval *mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove when persistence return value is fixed.
|
// TODO remove when persistence return value is fixed.
|
||||||
sampleSet.Metric = *metric
|
sampleSet.Metric = metric
|
||||||
sampleSets = append(sampleSets, sampleSet)
|
sampleSets = append(sampleSets, sampleSet)
|
||||||
}
|
}
|
||||||
return sampleSets, nil
|
return sampleSets, nil
|
||||||
|
|
|
@ -40,7 +40,7 @@ type MetricPersistence interface {
|
||||||
// name.
|
// name.
|
||||||
GetFingerprintsForLabelName(model.LabelName) ([]model.Fingerprint, error)
|
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)
|
GetValueAtTime(model.Metric, time.Time, StalenessPolicy) (*model.Sample, error)
|
||||||
GetBoundaryValues(model.Metric, model.Interval, StalenessPolicy) (*model.Sample, *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)
|
t.Error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*v) != 1 {
|
if len(v) != 1 {
|
||||||
t.Errorf("Expected one-dimensional metric.")
|
t.Errorf("Expected one-dimensional metric.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*v)["request_type"] != "your_mom" {
|
if v["request_type"] != "your_mom" {
|
||||||
t.Errorf("Expected metric to match.")
|
t.Errorf("Expected metric to match.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,15 +918,15 @@ func TestGetMetricForFingerprint(t *testing.T) {
|
||||||
t.Error(e)
|
t.Error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*v) != 2 {
|
if len(v) != 2 {
|
||||||
t.Errorf("Expected one-dimensional metric.")
|
t.Errorf("Expected one-dimensional metric.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*v)["request_type"] != "your_dad" {
|
if v["request_type"] != "your_dad" {
|
||||||
t.Errorf("Expected metric to match.")
|
t.Errorf("Expected metric to match.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*v)["one-off"] != "value" {
|
if v["one-off"] != "value" {
|
||||||
t.Errorf("Expected metric to match.")
|
t.Errorf("Expected metric to match.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.L
|
||||||
return
|
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()
|
begin := time.Now()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -279,9 +279,10 @@ func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f model.Fingerprint)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m = &model.Metric{}
|
m = model.Metric{}
|
||||||
|
|
||||||
for _, v := range unmarshaled.LabelPair {
|
for _, v := range unmarshaled.LabelPair {
|
||||||
(*m)[model.LabelName(*v.Name)] = model.LabelValue(*v.Value)
|
m[model.LabelName(*v.Name)] = model.LabelValue(*v.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue