Use slices instead of linked lists for Metric

Also:

* Remove Gob encoder/decoder
* Stop using custom encoders/decoders for Timestamps (both ugorji and the Golang JSON codecs use nanosecond precision).
* Use idiomatic way to check for existence in metric.LastSample()
This commit is contained in:
Alfonso Acosta
2016-07-30 01:11:06 +00:00
parent 15cf1e16b2
commit b8bf60c6f1
9 changed files with 130 additions and 288 deletions

View File

@@ -88,10 +88,10 @@ func TestReporter(t *testing.T) {
// Should have metrics
for key, want := range metrics {
wantSample := want.LastSample()
wantSample, _ := want.LastSample()
if metric, ok := node.Metrics[key]; !ok {
t.Errorf("Expected %s metric, but not found", key)
} else if sample := metric.LastSample(); sample == nil {
} else if sample, ok := metric.LastSample(); !ok {
t.Errorf("Expected %s metric to have a sample, but there were none", key)
} else if sample.Value != wantSample.Value {
t.Errorf("Expected %s metric sample %f, got %f", key, wantSample, sample.Value)

View File

@@ -69,9 +69,6 @@ func (m mockPublisher) Stop() {
}
func TestProbe(t *testing.T) {
// marshalling->unmarshaling is not idempotent due to `json:"omitempty"`
// tags, transforming empty slices into nils. So, we make DeepEqual
// happy by setting empty `json:"omitempty"` entries to nil
const probeID = "probeid"
now := time.Now()
mtime.NowForce(now)
@@ -79,8 +76,15 @@ func TestProbe(t *testing.T) {
want := report.MakeReport()
node := report.MakeNodeWith("a", map[string]string{"b": "c"})
node.Metrics = nil // omitempty
// omitempty
// DeepEqual doesn't handle the location of timestamps correctly
// See https://github.com/golang/go/issues/10089
node.Controls.Timestamp = time.Now()
// marshalling->unmarshaling is not idempotent due to `json:"omitempty"`
// tags, transforming empty slices into nils. So, we make DeepEqual
// happy by setting empty `json:"omitempty"` entries to nil
node.Metrics = nil
want.Endpoint.Controls = nil
want.Process.Controls = nil
want.Container.Controls = nil

View File

@@ -62,7 +62,7 @@ func TestReporter(t *testing.T) {
}
if memoryUsage, ok := node.Metrics[process.MemoryUsage]; !ok {
t.Errorf("Expected memory usage metric, but not found")
} else if sample := memoryUsage.LastSample(); sample == nil {
} else if sample, ok := memoryUsage.LastSample(); !ok {
t.Errorf("Expected memory usage metric to have a sample, but there were none")
} else if sample.Value != 0. {
t.Errorf("Expected memory usage metric sample %f, got %f", 0., sample.Value)