Remove Metric Add() method

* Helps reduce garbage (MakeMetric() now takes a slice and there's a shorter version MakeSingletonMetric())
* Fixes bug computing Max (Min) in samples since using MakeMetric()
  was causing a default Max/Min of zero.
* Simplifies code a bit
This commit is contained in:
Alfonso Acosta
2016-08-01 16:58:11 +00:00
parent 3e000662f4
commit 8a950a59d6
15 changed files with 152 additions and 193 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ func TestNodeMetrics(t *testing.T) {
func TestMetricRowSummary(t *testing.T) {
var (
now = time.Now()
metric = report.MakeMetric().Add(now, 1.234)
metric = report.MakeSingletonMetric(now, 1.234)
row = report.MetricRow{
ID: "id",
Format: "format",
+2 -2
View File
@@ -47,10 +47,10 @@ func TestSummaries(t *testing.T) {
// It should summarize nodes' metrics
{
t1, t2 := mtime.Now().Add(-1*time.Minute), mtime.Now()
metric := report.MakeMetric().Add(t1, 1).Add(t2, 2)
metric := report.MakeMetric([]report.Sample{{t1, 1}, {t2, 2}})
input := fixture.Report.Copy()
input.Process.Nodes[fixture.ClientProcess1NodeID] = input.Process.Nodes[fixture.ClientProcess1NodeID].WithMetrics(report.Metrics{process.CPUUsage: metric})
input.Process.Nodes[fixture.ClientProcess1NodeID].Metrics[process.CPUUsage] = metric
have := detailed.Summaries(input, render.ProcessRenderer.Render(input, nil))
node, ok := have[fixture.ClientProcess1NodeID]
+17 -17
View File
@@ -31,20 +31,20 @@ func TestPropagateSingleMetrics(t *testing.T) {
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
),
),
topology: report.Container,
output: report.Nodes{
"a": report.MakeNode("a").WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}).WithChildren(
report.MakeNodeSet(
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
),
),
@@ -57,30 +57,30 @@ func TestPropagateSingleMetrics(t *testing.T) {
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
report.MakeNode("child2").
WithTopology("otherTopology").
WithMetrics(report.Metrics{
"metric2": report.MakeMetric(),
"metric2": report.MakeMetric(nil),
}),
),
),
topology: report.Container,
output: report.Nodes{
"a": report.MakeNode("a").WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}).WithChildren(
report.MakeNodeSet(
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
report.MakeNode("child2").
WithTopology("otherTopology").
WithMetrics(report.Metrics{
"metric2": report.MakeMetric(),
"metric2": report.MakeMetric(nil),
}),
),
),
@@ -93,12 +93,12 @@ func TestPropagateSingleMetrics(t *testing.T) {
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
report.MakeNode("child2").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric2": report.MakeMetric(),
"metric2": report.MakeMetric(nil),
}),
),
),
@@ -109,12 +109,12 @@ func TestPropagateSingleMetrics(t *testing.T) {
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
report.MakeNode("child2").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric2": report.MakeMetric(),
"metric2": report.MakeMetric(nil),
}),
),
),
@@ -127,32 +127,32 @@ func TestPropagateSingleMetrics(t *testing.T) {
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
report.MakeNode("child2").
WithLatest(report.DoesNotMakeConnections, now, "").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric2": report.MakeMetric(),
"metric2": report.MakeMetric(nil),
}),
),
),
topology: report.Container,
output: report.Nodes{
"a": report.MakeNode("a").WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}).WithChildren(
report.MakeNodeSet(
report.MakeNode("child1").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric1": report.MakeMetric(),
"metric1": report.MakeMetric(nil),
}),
report.MakeNode("child2").
WithLatest(report.DoesNotMakeConnections, now, "").
WithTopology(report.Container).
WithMetrics(report.Metrics{
"metric2": report.MakeMetric(),
"metric2": report.MakeMetric(nil),
}),
),
),