mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 08:33:06 +00:00
Merge pull request #74 from prometheus/refactor/storage/simplifications
GetFingerprintsForLabelName simplifications.
This commit is contained in:
commit
cbad5da29b
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
@ -30,21 +30,21 @@ 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)
|
||||
GetBoundaryValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.Sample, *model.Sample, error)
|
||||
GetRangeValues(*model.Metric, *model.Interval, *StalenessPolicy) (*model.SampleSet, 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)
|
||||
|
||||
GetAllMetricNames() ([]string, error)
|
||||
|
||||
|
@ -791,7 +791,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) {
|
||||
}
|
||||
|
||||
b := model.LabelName("name")
|
||||
result, getErr := persistence.GetFingerprintsForLabelName(&b)
|
||||
result, getErr := persistence.GetFingerprintsForLabelName(b)
|
||||
|
||||
if getErr != nil {
|
||||
t.Error(getErr)
|
||||
@ -802,7 +802,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) {
|
||||
}
|
||||
|
||||
b = model.LabelName("request_type")
|
||||
result, getErr = persistence.GetFingerprintsForLabelName(&b)
|
||||
result, getErr = persistence.GetFingerprintsForLabelName(b)
|
||||
|
||||
if getErr != nil {
|
||||
t.Error(getErr)
|
||||
@ -813,7 +813,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) {
|
||||
}
|
||||
|
||||
b = model.LabelName("language")
|
||||
result, getErr = persistence.GetFingerprintsForLabelName(&b)
|
||||
result, getErr = persistence.GetFingerprintsForLabelName(b)
|
||||
|
||||
if getErr != nil {
|
||||
t.Error(getErr)
|
||||
@ -824,7 +824,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) {
|
||||
}
|
||||
|
||||
b = model.LabelName("sprache")
|
||||
result, getErr = persistence.GetFingerprintsForLabelName(&b)
|
||||
result, getErr = persistence.GetFingerprintsForLabelName(b)
|
||||
|
||||
if getErr != nil {
|
||||
t.Error(getErr)
|
||||
@ -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)
|
||||
|
@ -231,7 +231,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelSet(labelSet model.Lab
|
||||
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()
|
||||
|
||||
defer func() {
|
||||
@ -242,7 +242,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName *model.
|
||||
|
||||
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 {
|
||||
return
|
||||
}
|
||||
@ -262,7 +262,7 @@ func (l *LevelDBMetricPersistence) GetFingerprintsForLabelName(labelName *model.
|
||||
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
|
||||
}
|
||||
@ -290,7 +290,7 @@ func (l *LevelDBMetricPersistence) GetMetricForFingerprint(f *model.Fingerprint)
|
||||
return
|
||||
}
|
||||
|
||||
func (l *LevelDBMetricPersistence) GetBoundaryValues(m *model.Metric, i *model.Interval, s *metric.StalenessPolicy) (open *model.Sample, end *model.Sample, err error) {
|
||||
func (l *LevelDBMetricPersistence) GetBoundaryValues(m model.Metric, i model.Interval, s metric.StalenessPolicy) (open *model.Sample, end *model.Sample, err error) {
|
||||
begin := time.Now()
|
||||
|
||||
defer func() {
|
||||
@ -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,18 +542,18 @@ 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
|
||||
}
|
||||
|
||||
func (l *LevelDBMetricPersistence) GetRangeValues(m *model.Metric, i *model.Interval, s *metric.StalenessPolicy) (v *model.SampleSet, err error) {
|
||||
func (l *LevelDBMetricPersistence) GetRangeValues(m model.Metric, i model.Interval, s metric.StalenessPolicy) (v *model.SampleSet, err error) {
|
||||
begin := time.Now()
|
||||
|
||||
defer func() {
|
||||
|
@ -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)
|
||||
}
|
||||
@ -1058,7 +1058,7 @@ var testGetBoundaryValues = func(t test.Tester) {
|
||||
DeltaAllowance: input.staleness,
|
||||
}
|
||||
|
||||
openValue, endValue, err := persistence.GetBoundaryValues(&m, &interval, &p)
|
||||
openValue, endValue, err := persistence.GetBoundaryValues(m, interval, p)
|
||||
if err != nil {
|
||||
t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err)
|
||||
}
|
||||
@ -1652,7 +1652,7 @@ var testGetRangeValues = func(t test.Tester) {
|
||||
DeltaAllowance: input.staleness,
|
||||
}
|
||||
|
||||
values, err := persistence.GetRangeValues(&m, &i, &p)
|
||||
values, err := persistence.GetRangeValues(m, i, p)
|
||||
if err != nil {
|
||||
t.Errorf("%d.%d(%s). Could not query for value: %q\n", i, j, behavior.name, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user