Interface simplifications: GetValueAtTime().

Pointer arguments to copies.
This commit is contained in:
Matt T. Proud 2013-02-13 21:05:01 -08:00
parent 1e2d6c7418
commit 56f069b3ec
5 changed files with 20 additions and 20 deletions

View file

@ -37,7 +37,7 @@ func (p *PersistenceAdapter) getMetricsWithLabels(labels model.LabelSet) ([]*mod
}
metrics := []*model.Metric{}
for _, fingerprint := range fingerprints {
metric, err := p.persistence.GetMetricForFingerprint(fingerprint)
metric, err := p.persistence.GetMetricForFingerprint(*fingerprint)
if err != nil {
return nil, err
}
@ -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
}

View file

@ -30,19 +30,19 @@ type MetricPersistence interface {
Close() error
// Record a new sample in the storage layer.
AppendSample(sample model.Sample) error
AppendSample(model.Sample) error
// Get all of the metric fingerprints that are associated with the provided
// label set.
GetFingerprintsForLabelSet(labelSet model.LabelSet) ([]*model.Fingerprint, error)
GetFingerprintsForLabelSet(model.LabelSet) ([]*model.Fingerprint, error)
// Get all of the metric fingerprints that are associated for a given label
// name.
GetFingerprintsForLabelName(labelName model.LabelName) ([]*model.Fingerprint, error)
GetFingerprintsForLabelName(model.LabelName) ([]*model.Fingerprint, error)
GetMetricForFingerprint(f *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)
GetRangeValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.SampleSet, error)

View file

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

View file

@ -262,7 +262,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() {
@ -271,7 +271,7 @@ func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f *model.Fingerprint)
recordOutcome(storageOperations, storageLatency, duration, err, map[string]string{operation: getMetricForFingerprint, result: success}, map[string]string{operation: getMetricForFingerprint, result: failure})
}()
raw, err := l.fingerprintToMetrics.Get(coding.NewProtocolBufferEncoder(model.FingerprintToDTO(f)))
raw, err := l.fingerprintToMetrics.Get(coding.NewProtocolBufferEncoder(model.FingerprintToDTO(&f)))
if err != nil {
return
}
@ -300,14 +300,14 @@ func (l *LevelDBMetricPersistence) GetBoundaryValues(m *model.Metric, i *model.I
}()
// XXX: Maybe we will want to emit incomplete sets?
open, err = l.GetValueAtTime(m, &i.OldestInclusive, s)
open, err = l.GetValueAtTime(*m, i.OldestInclusive, *s)
if err != nil {
return
} else if open == nil {
return
}
end, err = l.GetValueAtTime(m, &i.NewestInclusive, s)
end, err = l.GetValueAtTime(*m, i.NewestInclusive, *s)
if err != nil {
return
} else if end == nil {
@ -339,7 +339,7 @@ type iterator interface {
Value() []byte
}
func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time, s *metric.StalenessPolicy) (sample *model.Sample, err error) {
func (l *LevelDBMetricPersistence) GetValueAtTime(m model.Metric, t time.Time, s metric.StalenessPolicy) (sample *model.Sample, err error) {
begin := time.Now()
defer func() {
@ -353,7 +353,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
// Candidate for Refactoring
k := &dto.SampleKey{
Fingerprint: f,
Timestamp: indexable.EncodeTime(*t),
Timestamp: indexable.EncodeTime(t),
}
e, err := coding.NewProtocolBufferEncoder(k).Encode()
@ -473,7 +473,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
firstTime = alternativeTime
}
firstDelta := firstTime.Sub(*t)
firstDelta := firstTime.Sub(t)
if firstDelta < 0 {
firstDelta *= -1
}
@ -486,7 +486,7 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
return
}
sample = model.SampleFromDTO(m, t, firstValue)
sample = model.SampleFromDTO(&m, &t, firstValue)
if firstDelta == time.Duration(0) {
return
@ -542,13 +542,13 @@ func (l *LevelDBMetricPersistence) GetValueAtTime(m *model.Metric, t *time.Time,
return
}
interpolated := interpolate(firstTime, secondTime, *firstValue.Value, *secondValue.Value, *t)
interpolated := interpolate(firstTime, secondTime, *firstValue.Value, *secondValue.Value, t)
sampleValue := &dto.SampleValue{
Value: &interpolated,
}
sample = model.SampleFromDTO(m, t, sampleValue)
sample = model.SampleFromDTO(&m, &t, sampleValue)
return
}

View file

@ -592,7 +592,7 @@ var testGetValueAtTime = func(t test.Tester) {
DeltaAllowance: input.staleness,
}
actual, err := persistence.GetValueAtTime(&m, &time, &p)
actual, err := persistence.GetValueAtTime(m, time, p)
if err != nil {
t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err)
}