Merge pull request #75 from prometheus/refactor/storage/simplifications

Interface simplifications.
This commit is contained in:
juliusv 2013-02-14 08:29:09 -08:00
commit ddb82a6e5d
4 changed files with 9 additions and 12 deletions

View file

@ -37,7 +37,7 @@ func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) ([]*mod
} }
metrics := []*model.Metric{} 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 nil, err
} }

View file

@ -34,11 +34,11 @@ type MetricPersistence interface {
// Get all of the metric fingerprints that are associated with the provided // Get all of the metric fingerprints that are associated with the provided
// label set. // label set.
GetFingerprintsForLabelSet(model.LabelSet) ([]*model.Fingerprint, error) GetFingerprintsForLabelSet(model.LabelSet) ([]model.Fingerprint, error)
// Get all of the metric fingerprints that are associated for a given label // Get all of the metric fingerprints that are associated for a given label
// 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)

View file

@ -887,7 +887,7 @@ func TestGetMetricForFingerprint(t *testing.T) {
t.Errorf("Expected one element.") t.Errorf("Expected one element.")
} }
v, e := persistence.GetMetricForFingerprint(*result[0]) v, e := persistence.GetMetricForFingerprint(result[0])
if e != nil { if e != nil {
t.Error(e) t.Error(e)
} }
@ -912,7 +912,7 @@ func TestGetMetricForFingerprint(t *testing.T) {
t.Errorf("Expected one element.") t.Errorf("Expected one element.")
} }
v, e = persistence.GetMetricForFingerprint(*result[0]) v, e = persistence.GetMetricForFingerprint(result[0])
if e != nil { if e != nil {
t.Error(e) t.Error(e)

View file

@ -180,7 +180,7 @@ func (l *LevelDBMetricPersistence) GetLabelNameFingerprints(n *dto.LabelName) (c
return return
} }
func (l *LevelDBMetricPersistence) GetFingerprintsForLabelSet(labelSet model.LabelSet) (fps []*model.Fingerprint, err error) { func (l *LevelDBMetricPersistence) GetFingerprintsForLabelSet(labelSet model.LabelSet) (fps []model.Fingerprint, err error) {
begin := time.Now() begin := time.Now()
defer func() { defer func() {
@ -222,16 +222,15 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelSet(labelSet model.Lab
for i := 1; i < numberOfSets; i++ { for i := 1; i < numberOfSets; i++ {
base = base.Intersection(sets[i]) base = base.Intersection(sets[i])
} }
fps = []*model.Fingerprint{}
for _, e := range base.Elements() { for _, e := range base.Elements() {
fingerprint := e.(model.Fingerprint) fingerprint := e.(model.Fingerprint)
fps = append(fps, &fingerprint) fps = append(fps, fingerprint)
} }
return return
} }
func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.LabelName) (fps []*model.Fingerprint, err error) { func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.LabelName) (fps []model.Fingerprint, err error) {
begin := time.Now() begin := time.Now()
defer func() { defer func() {
@ -240,8 +239,6 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.L
recordOutcome(storageOperations, storageLatency, duration, err, map[string]string{operation: getFingerprintsForLabelName, result: success}, map[string]string{operation: getFingerprintsForLabelName, result: failure}) recordOutcome(storageOperations, storageLatency, duration, err, map[string]string{operation: getFingerprintsForLabelName, result: success}, map[string]string{operation: getFingerprintsForLabelName, result: failure})
}() }()
fps = make([]*model.Fingerprint, 0, 0)
raw, err := l.labelNameToFingerprints.Get(coding.NewProtocolBufferEncoder(model.LabelNameToDTO(&labelName))) raw, err := l.labelNameToFingerprints.Get(coding.NewProtocolBufferEncoder(model.LabelNameToDTO(&labelName)))
if err != nil { if err != nil {
return return
@ -256,7 +253,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName model.L
for _, m := range unmarshaled.Member { for _, m := range unmarshaled.Member {
fp := model.Fingerprint(*m.Signature) fp := model.Fingerprint(*m.Signature)
fps = append(fps, &fp) fps = append(fps, fp)
} }
return return