PR comment fixups.

This commit is contained in:
Julius Volz 2013-03-26 14:46:02 +01:00
parent dd67ab115b
commit e096896932
5 changed files with 27 additions and 19 deletions

View file

@ -44,6 +44,7 @@ type MetricPersistence interface {
// name. // name.
GetFingerprintsForLabelName(model.LabelName) (model.Fingerprints, error) GetFingerprintsForLabelName(model.LabelName) (model.Fingerprints, error)
// Get the metric associated with the provided fingerprint.
GetMetricForFingerprint(model.Fingerprint) (*model.Metric, error) GetMetricForFingerprint(model.Fingerprint) (*model.Metric, error)
GetValueAtTime(model.Fingerprint, time.Time, StalenessPolicy) (*model.Sample, error) GetValueAtTime(model.Fingerprint, time.Time, StalenessPolicy) (*model.Sample, error)
@ -52,6 +53,7 @@ type MetricPersistence interface {
ForEachSample(IteratorsForFingerprintBuilder) (err error) ForEachSample(IteratorsForFingerprintBuilder) (err error)
// Get all label values that are associated with a given label name.
GetAllValuesForLabel(model.LabelName) (model.LabelValues, error) GetAllValuesForLabel(model.LabelName) (model.LabelValues, error)
// Requests the storage stack to build a materialized View of the values // Requests the storage stack to build a materialized View of the values

View file

@ -1221,13 +1221,16 @@ func (l *LevelDBMetricPersistence) GetRangeValues(fp model.Fingerprint, i model.
type MetricKeyDecoder struct{} type MetricKeyDecoder struct{}
func (d *MetricKeyDecoder) DecodeKey(in interface{}) (out interface{}, err error) { func (d *MetricKeyDecoder) DecodeKey(in interface{}) (out interface{}, err error) {
unmarshaled := &dto.LabelPair{} unmarshaled := dto.LabelPair{}
err = proto.Unmarshal(in.([]byte), unmarshaled) err = proto.Unmarshal(in.([]byte), &unmarshaled)
if err != nil { if err != nil {
return return
} }
out = unmarshaled out = model.LabelPair{
Name: model.LabelName(*unmarshaled.Name),
Value: model.LabelValue(*unmarshaled.Value),
}
return return
} }
@ -1240,9 +1243,9 @@ type LabelNameFilter struct {
labelName model.LabelName labelName model.LabelName
} }
func (f *LabelNameFilter) Filter(key, value interface{}) (filterResult storage.FilterResult) { func (f LabelNameFilter) Filter(key, value interface{}) (filterResult storage.FilterResult) {
unmarshaled, ok := key.(*dto.LabelPair) labelPair, ok := key.(model.LabelPair)
if ok && model.LabelName(*unmarshaled.Name) == f.labelName { if ok && labelPair.Name == f.labelName {
return storage.ACCEPT return storage.ACCEPT
} }
return storage.SKIP return storage.SKIP
@ -1253,8 +1256,8 @@ type CollectLabelValuesOp struct {
} }
func (op *CollectLabelValuesOp) Operate(key, value interface{}) (err *storage.OperatorError) { func (op *CollectLabelValuesOp) Operate(key, value interface{}) (err *storage.OperatorError) {
unmarshaled := key.(*dto.LabelPair) labelPair := key.(model.LabelPair)
op.labelValues = append(op.labelValues, model.LabelValue(*unmarshaled.Value)) op.labelValues = append(op.labelValues, model.LabelValue(labelPair.Value))
return return
} }

View file

@ -352,13 +352,12 @@ func (s memorySeriesStorage) GetAllValuesForLabel(labelName model.LabelName) (va
valueSet := map[model.LabelValue]bool{} valueSet := map[model.LabelValue]bool{}
for _, series := range s.fingerprintToSeries { for _, series := range s.fingerprintToSeries {
if value, ok := series.metric[labelName]; ok { if value, ok := series.metric[labelName]; ok {
valueSet[value] = true if !valueSet[value] {
values = append(values, value)
valueSet[value] = true
}
} }
} }
for value := range valueSet {
values = append(values, value)
}
sort.Sort(values)
return return
} }

View file

@ -63,9 +63,12 @@ type Storage interface {
Flush() Flush()
Close() Close()
// MetricPersistence proxy methods. // Get all label values that are associated with the provided label name.
GetAllValuesForLabel(model.LabelName) (model.LabelValues, error) GetAllValuesForLabel(model.LabelName) (model.LabelValues, error)
// Get all of the metric fingerprints that are associated with the provided
// label set.
GetFingerprintsForLabelSet(model.LabelSet) (model.Fingerprints, error) GetFingerprintsForLabelSet(model.LabelSet) (model.Fingerprints, error)
// Get the metric associated with the provided fingerprint.
GetMetricForFingerprint(model.Fingerprint) (m *model.Metric, err error) GetMetricForFingerprint(model.Fingerprint) (m *model.Metric, err error)
} }
@ -530,12 +533,11 @@ func (t *tieredStorage) GetAllValuesForLabel(labelName model.LabelName) (values
valueSet := map[model.LabelValue]bool{} valueSet := map[model.LabelValue]bool{}
for _, value := range append(diskValues, memoryValues...) { for _, value := range append(diskValues, memoryValues...) {
valueSet[value] = true if !valueSet[value] {
values = append(values, value)
valueSet[value] = true
}
} }
for value := range valueSet {
values = append(values, value)
}
sort.Sort(values)
return return
} }

View file

@ -19,6 +19,7 @@ import (
"github.com/prometheus/prometheus/utility/test" "github.com/prometheus/prometheus/utility/test"
"io/ioutil" "io/ioutil"
"os" "os"
"sort"
"testing" "testing"
"time" "time"
) )
@ -518,6 +519,7 @@ func TestGetAllValuesForLabel(t *testing.T) {
t.Fatalf("%d. Expected metric count %d, got %d", i, len(scenario.out), len(metricNames)) t.Fatalf("%d. Expected metric count %d, got %d", i, len(scenario.out), len(metricNames))
} }
sort.Sort(metricNames)
for j, expected := range scenario.out { for j, expected := range scenario.out {
if expected != string(metricNames[j]) { if expected != string(metricNames[j]) {
t.Fatalf("%d.%d. Expected metric %s, got %s", i, j, expected, metricNames[j]) t.Fatalf("%d.%d. Expected metric %s, got %s", i, j, expected, metricNames[j])