Merge pull request #132 from prometheus/julius-leveldb-sorting

Make LevelDB sample keys fixed-length to ensure correct sort-order.
This commit is contained in:
Matt T. Proud 2013-04-11 09:25:02 -07:00
commit 2d70e75c52
3 changed files with 8 additions and 5 deletions

View file

@ -38,11 +38,14 @@ message LabelSet {
repeated LabelPair member = 1; repeated LabelPair member = 1;
} }
// The default LevelDB comparator sorts not only lexicographically, but also by
// key length (which takes precedence). Thus, no variable-length fields may be
// introduced into the key definition below.
message SampleKey { message SampleKey {
optional Fingerprint fingerprint = 1; optional Fingerprint fingerprint = 1;
optional bytes timestamp = 2; optional bytes timestamp = 2;
optional int64 last_timestamp = 3; optional sfixed64 last_timestamp = 3;
optional uint32 sample_count = 4; optional fixed32 sample_count = 4;
} }
message SampleValueSeries { message SampleValueSeries {

View file

@ -106,7 +106,7 @@ func NewFingerprintFromMetric(metric Metric) (f Fingerprint) {
return fingerprint{ return fingerprint{
firstCharacterOfFirstLabelName: firstCharacterOfFirstLabelName, firstCharacterOfFirstLabelName: firstCharacterOfFirstLabelName,
hash: binary.LittleEndian.Uint64(summer.Sum(nil)), hash: binary.LittleEndian.Uint64(summer.Sum(nil)),
labelMatterLength: uint(labelMatterLength), labelMatterLength: uint(labelMatterLength % 10),
lastCharacterOfLastLabelValue: lastCharacterOfLastLabelValue, lastCharacterOfLastLabelValue: lastCharacterOfLastLabelValue,
} }
} }

View file

@ -35,7 +35,7 @@ func testMetric(t test.Tester) {
"occupation": "robot", "occupation": "robot",
"manufacturer": "westinghouse", "manufacturer": "westinghouse",
}, },
rowkey: "04776841610193542734-f-56-t", rowkey: "04776841610193542734-f-6-t",
hash: 4776841610193542734, hash: 4776841610193542734,
}, },
{ {