Refresh SampleValue to 64-bit floating point.

We always knew that this needed to be fixed.
This commit is contained in:
Matt T. Proud 2013-04-21 18:15:56 +02:00
parent 092c7bd88e
commit f9e99bd08a
7 changed files with 30 additions and 27 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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,
},
},
},

View File

@ -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,
}, {

View File

@ -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),
})
}

View File

@ -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(),
})
}

View File

@ -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 {