mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user