From f9e99bd08a190633ecc4c4e76f3a503ced96954a Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Sun, 21 Apr 2013 18:15:56 +0200 Subject: [PATCH] Refresh SampleValue to 64-bit floating point. We always knew that this needed to be fixed. --- model/data.proto | 4 ++-- model/metric.go | 11 +++++++---- retrieval/format/processor0_0_1_test.go | 26 ++++++++++++------------- rules/rules_test.go | 2 +- storage/metric/curator_test.go | 4 ++-- storage/metric/leveldb.go | 2 +- storage/metric/rule_integration_test.go | 8 ++++---- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/model/data.proto b/model/data.proto index 95e25e2d9b..ce6cff9209 100644 --- a/model/data.proto +++ b/model/data.proto @@ -50,8 +50,8 @@ message SampleKey { message SampleValueSeries { message Value { - optional int64 timestamp = 1; - optional float value = 2; + optional int64 timestamp = 1; + optional double value = 2; } repeated Value value = 1; } diff --git a/model/metric.go b/model/metric.go index c254f3d929..9527a5c182 100644 --- a/model/metric.go +++ b/model/metric.go @@ -15,6 +15,7 @@ package model import ( "bytes" + "code.google.com/p/goprotobuf/proto" "fmt" "sort" "time" @@ -70,10 +71,12 @@ func (l LabelSet) String() string { type Metric map[LabelName]LabelValue // A SampleValue is a representation of a value for a given sample at a given -// time. It is presently float32 due to that being the representation that -// Protocol Buffers provide of floats in Go. This is a smell and should be -// remedied down the road. -type SampleValue float32 +// time. +type SampleValue float64 + +func (s SampleValue) ToDTO() *float64 { + return proto.Float64(float64(s)) +} func (v SampleValue) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%f\"", v)), nil diff --git a/retrieval/format/processor0_0_1_test.go b/retrieval/format/processor0_0_1_test.go index 8e0ba5ed76..3bf3d16ba1 100644 --- a/retrieval/format/processor0_0_1_test.go +++ b/retrieval/format/processor0_0_1_test.go @@ -59,14 +59,14 @@ func testProcessor001Process(t test.Tester) { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, - Value: 0.04598141, + Value: 0.0459814091918713, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, - Value: 78.485634, + Value: 78.48563317257356, }, }, { @@ -80,14 +80,14 @@ func testProcessor001Process(t test.Tester) { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, - Value: 0.04598141, + Value: 0.0459814091918713, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, - Value: 78.485634, + Value: 78.48563317257356, }, }, { @@ -101,63 +101,63 @@ func testProcessor001Process(t test.Tester) { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, - Value: 0.61204565, + Value: 0.6120456642749681, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, - Value: 97.317986, + Value: 97.31798360385088, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, - Value: 84.63044, + Value: 84.63044031436561, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, - Value: 1.3559151, + Value: 1.355915069887731, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, - Value: 109.89202, + Value: 109.89202084295582, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, - Value: 160.21101, + Value: 160.21100853053224, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, - Value: 1.7727332, + Value: 1.772733213161236, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, - Value: 109.99626, + Value: 109.99626121011262, }, }, { Sample: model.Sample{ Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, - Value: 172.49829, + Value: 172.49828748957728, }, }, }, diff --git a/rules/rules_test.go b/rules/rules_test.go index f4083e1612..8d9c8719dd 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -235,7 +235,7 @@ var expressionTests = []struct { }, { // Rates should transform per-interval deltas to per-second rates. expr: "rate(http_requests{group='canary',instance='1',job='app-server'}[10m])", - output: []string{"http_requests{group='canary',instance='1',job='app-server'} => 0.26666668 @[%v]"}, + output: []string{"http_requests{group='canary',instance='1',job='app-server'} => 0.26666666666666666 @[%v]"}, fullRanges: 1, intervalRanges: 0, }, { diff --git a/storage/metric/curator_test.go b/storage/metric/curator_test.go index c950ffb42f..2d0750feae 100644 --- a/storage/metric/curator_test.go +++ b/storage/metric/curator_test.go @@ -40,7 +40,7 @@ type ( sample struct { time time.Time - value float32 + value float64 } sampleGroup struct { @@ -90,7 +90,7 @@ func (s sampleGroup) Get() (key, value coding.Encoder) { for _, value := range s.values { series.Value = append(series.Value, &dto.SampleValueSeries_Value{ Timestamp: proto.Int64(value.time.Unix()), - Value: proto.Float32(float32(value.value)), + Value: proto.Float64(value.value), }) } diff --git a/storage/metric/leveldb.go b/storage/metric/leveldb.go index 02ebdf18b8..989c8dd87c 100644 --- a/storage/metric/leveldb.go +++ b/storage/metric/leveldb.go @@ -619,7 +619,7 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err for _, sample := range chunk { value.Value = append(value.Value, &dto.SampleValueSeries_Value{ Timestamp: proto.Int64(sample.Timestamp.Unix()), - Value: proto.Float32(float32(sample.Value)), + Value: sample.Value.ToDTO(), }) } diff --git a/storage/metric/rule_integration_test.go b/storage/metric/rule_integration_test.go index c7c6e2fec3..c71b6622c8 100644 --- a/storage/metric/rule_integration_test.go +++ b/storage/metric/rule_integration_test.go @@ -26,7 +26,7 @@ func GetValueAtTimeTests(persistenceMaker func() (MetricPersistence, test.Closer month time.Month day int hour int - value float32 + value float64 } type input struct { @@ -358,7 +358,7 @@ func GetBoundaryValuesTests(persistenceMaker func() (MetricPersistence, test.Clo month time.Month day int hour int - value float32 + value float64 } type input struct { @@ -672,7 +672,7 @@ func GetRangeValuesTests(persistenceMaker func() (MetricPersistence, test.Closer month time.Month day int hour int - value float32 + value float64 } type input struct { @@ -691,7 +691,7 @@ func GetRangeValuesTests(persistenceMaker func() (MetricPersistence, test.Closer month time.Month day int hour int - value float32 + value model.SampleValue } type behavior struct {