From 8be6ca5e1ec436bc591178045aae909db46965b4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 19 Oct 2019 14:03:40 +0000 Subject: [PATCH] fixup: remove timestamp argument from node.WithLatest() --- probe/docker/tagger.go | 3 +-- probe/kubernetes/reporter.go | 3 +-- probe/process/reporter.go | 12 ++++++------ render/filters.go | 3 +-- render/metrics_test.go | 6 ++---- render/short_lived_connections_test.go | 4 +--- report/marshal_test.go | 6 +++--- report/node.go | 8 ++------ report/node_test.go | 2 +- report/table.go | 7 ++----- 10 files changed, 20 insertions(+), 34 deletions(-) diff --git a/probe/docker/tagger.go b/probe/docker/tagger.go index d95e01cde..270939e57 100644 --- a/probe/docker/tagger.go +++ b/probe/docker/tagger.go @@ -4,7 +4,6 @@ import ( "strconv" "strings" - "github.com/weaveworks/common/mtime" "github.com/weaveworks/scope/probe/process" "github.com/weaveworks/scope/report" ) @@ -115,7 +114,7 @@ func (t *Tagger) tag(tree process.Tree, topology *report.Topology) { continue } - node = node.WithLatest(ContainerID, mtime.Now(), c.ID()) + node = node.WithLatest(ContainerID, c.ID()) node = node.WithParent(report.Container, report.MakeContainerNodeID(c.ID())) // If we can work out the image name, add a parent tag for it diff --git a/probe/kubernetes/reporter.go b/probe/kubernetes/reporter.go index 05ab0c73b..9ad64218b 100644 --- a/probe/kubernetes/reporter.go +++ b/probe/kubernetes/reporter.go @@ -6,7 +6,6 @@ import ( "k8s.io/apimachinery/pkg/labels" log "github.com/sirupsen/logrus" - "github.com/weaveworks/common/mtime" "github.com/weaveworks/scope/probe" "github.com/weaveworks/scope/probe/controls" "github.com/weaveworks/scope/probe/docker" @@ -283,7 +282,7 @@ func (r *Tagger) Tag(rpt report.Report) (report.Report, error) { // Tag the pause containers with "does-not-make-connections" if isPauseContainer(n, rpt) { - n = n.WithLatest(report.DoesNotMakeConnections, mtime.Now(), "") + n = n.WithLatest(report.DoesNotMakeConnections, "") } rpt.Container.Nodes[id] = n.WithParent(report.Pod, report.MakePodNodeID(uid)) diff --git a/probe/process/reporter.go b/probe/process/reporter.go index 35253bbcb..49bcec135 100644 --- a/probe/process/reporter.go +++ b/probe/process/reporter.go @@ -84,22 +84,22 @@ func (r *Reporter) processTopology() (report.Topology, error) { pidstr := strconv.Itoa(p.PID) nodeID := report.MakeProcessNodeID(r.scope, pidstr) node := report.MakeNode(nodeID) - node = node.WithLatest(PID, now, pidstr) - node = node.WithLatest(Threads, now, strconv.Itoa(p.Threads)) + node = node.WithLatest(PID, pidstr) + node = node.WithLatest(Threads, strconv.Itoa(p.Threads)) if p.Name != "" { - node = node.WithLatest(Name, now, p.Name) + node = node.WithLatest(Name, p.Name) } if p.Cmdline != "" { if r.noCommandLineArguments { - node = node.WithLatest(Cmdline, now, report.StripCommandArgs(p.Cmdline)) + node = node.WithLatest(Cmdline, report.StripCommandArgs(p.Cmdline)) } else { - node = node.WithLatest(Cmdline, now, p.Cmdline) + node = node.WithLatest(Cmdline, p.Cmdline) } } if p.PPID > 0 { - node = node.WithLatest(PPID, now, strconv.Itoa(p.PPID)) + node = node.WithLatest(PPID, strconv.Itoa(p.PPID)) } var metrics = report.Metrics{ diff --git a/render/filters.go b/render/filters.go index 315e75220..a0f5e9975 100644 --- a/render/filters.go +++ b/render/filters.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/weaveworks/common/mtime" "github.com/weaveworks/scope/report" ) @@ -189,7 +188,7 @@ func ColorConnected(r Renderer) Renderer { RenderFunc: func(input Nodes) Nodes { output := input.Copy() for id := range connected(input.Nodes) { - output[id] = output[id].WithLatest(IsConnectedMark, mtime.Now(), "true") + output[id] = output[id].WithLatest(IsConnectedMark, "true") } return Nodes{Nodes: output, Filtered: input.Filtered} }, diff --git a/render/metrics_test.go b/render/metrics_test.go index 5e6f74e31..42922a8cb 100644 --- a/render/metrics_test.go +++ b/render/metrics_test.go @@ -3,7 +3,6 @@ package render_test import ( "context" "testing" - "time" "github.com/weaveworks/common/test" "github.com/weaveworks/scope/render" @@ -12,7 +11,6 @@ import ( ) func TestPropagateSingleMetrics(t *testing.T) { - now := time.Now() for _, c := range []struct { name string input report.Node @@ -131,7 +129,7 @@ func TestPropagateSingleMetrics(t *testing.T) { "metric1": report.MakeMetric(nil), }), report.MakeNode("child2"). - WithLatest(report.DoesNotMakeConnections, now, ""). + WithLatest(report.DoesNotMakeConnections, ""). WithTopology(report.Container). WithMetrics(report.Metrics{ "metric2": report.MakeMetric(nil), @@ -150,7 +148,7 @@ func TestPropagateSingleMetrics(t *testing.T) { "metric1": report.MakeMetric(nil), }), report.MakeNode("child2"). - WithLatest(report.DoesNotMakeConnections, now, ""). + WithLatest(report.DoesNotMakeConnections, ""). WithTopology(report.Container). WithMetrics(report.Metrics{ "metric2": report.MakeMetric(nil), diff --git a/render/short_lived_connections_test.go b/render/short_lived_connections_test.go index e06fc4fa9..adbdbbead 100644 --- a/render/short_lived_connections_test.go +++ b/render/short_lived_connections_test.go @@ -5,8 +5,6 @@ import ( "fmt" "testing" - "github.com/weaveworks/common/mtime" - "github.com/weaveworks/scope/render" "github.com/weaveworks/scope/report" "github.com/weaveworks/scope/test/utils" @@ -91,7 +89,7 @@ var ( WithSets(report.MakeSets(). Add(report.DockerContainerIPs, report.MakeStringSet(pauseContainerIP)). Add(report.DockerContainerIPsWithScopes, report.MakeStringSet(report.MakeAddressNodeID("", pauseContainerIP))), - ).WithTopology(report.Container).WithLatest(report.DoesNotMakeConnections, mtime.Now(), ""), + ).WithTopology(report.Container).WithLatest(report.DoesNotMakeConnections, ""), }, }, Host: report.Topology{ diff --git a/report/marshal_test.go b/report/marshal_test.go index 0275341c7..732d049a2 100644 --- a/report/marshal_test.go +++ b/report/marshal_test.go @@ -40,18 +40,18 @@ func makeTestReport() report.Report { WithTopology("endpoint"). WithSet("snooped_dns_names", report.MakeStringSet("ip-172-20-1-168.ec2.internal")). WithLatestActiveControls("docker_pause_container"). - WithLatest("addr", t1, "127.0.0.1"), + WithLatest("addr", "127.0.0.1"), ) r.Process.WithShape("square").WithLabel("process", "processes"). AddNode(report.MakeNode("ip-172-20-1-168;10446"). WithTopology("process"). WithParents(report.MakeSets().Add("host", report.MakeStringSet("ip-172-20-1-168;"))). - WithLatest("pid", t1, "10446"). + WithLatest("pid", "10446"). WithMetrics(report.Metrics{"process_cpu_usage_percent": report.MakeMetric([]report.Sample{{Timestamp: t1, Value: 0.1}, {Timestamp: t2, Value: 0.2}})})) r.Pod.WithShape("heptagon").WithLabel("pod", "pods"). AddNode(report.MakeNode("fceef9592ec3cf1a8e1d178fdd0de41a;"). WithTopology("pod"). - WithLatest("host_node_id", t1, "ip-172-20-1-168;")) + WithLatest("host_node_id", "ip-172-20-1-168;")) r.Overlay.WithMetadataTemplates(report.MetadataTemplates{ "weave_encryption": report.MetadataTemplate{ID: "weave_encryption", Label: "Encryption", Priority: 4, From: "latest"}, }). diff --git a/report/node.go b/report/node.go index 0c6a4f392..da17141c3 100644 --- a/report/node.go +++ b/report/node.go @@ -2,9 +2,6 @@ package report import ( "strings" - "time" - - "github.com/weaveworks/common/mtime" ) // Node describes a superset of the metadata that probes can collect @@ -75,8 +72,7 @@ func (n Node) WithLatests(m map[string]string) Node { } // WithLatest produces a new Node with k mapped to v in the Latest metadata. -// TODO: remove backwards-compatibility time argument -func (n Node) WithLatest(k string, _ time.Time, v string) Node { +func (n Node) WithLatest(k string, v string) Node { n.Latest = n.Latest.Set(k, v) return n } @@ -121,7 +117,7 @@ func (n Node) WithAdjacent(a ...string) Node { // WithLatestActiveControls says which controls are active on this node. // Implemented as a delimiter-separated string in Latest func (n Node) WithLatestActiveControls(cs ...string) Node { - return n.WithLatest(NodeActiveControls, mtime.Now(), strings.Join(cs, ScopeDelim)) + return n.WithLatest(NodeActiveControls, strings.Join(cs, ScopeDelim)) } // ActiveControls returns a string slice with the names of active controls. diff --git a/report/node_test.go b/report/node_test.go index 2843d21f5..53f22ac22 100644 --- a/report/node_test.go +++ b/report/node_test.go @@ -113,7 +113,7 @@ func TestMergeNodes(t *testing.T) { ":192.168.1.1:12345": report.MakeNodeWith(":192.168.1.1:12345", map[string]string{ Name: "curl", Domain: "node-a.local", - }).WithLatest(PID, time.Now().Add(-1*time.Minute), "0"), + }).WithLatest(PID, "0"), }, b: report.Nodes{ ":192.168.1.1:12345": report.MakeNodeWith(":192.168.1.1:12345", map[string]string{ // <-- same ID diff --git a/report/table.go b/report/table.go index d9f244e72..58ccbe5e0 100644 --- a/report/table.go +++ b/report/table.go @@ -6,7 +6,6 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/weaveworks/common/mtime" ) // Table types @@ -22,12 +21,11 @@ const ( // AddPrefixMulticolumnTable appends arbitrary rows to the Node, returning a new node. func (node Node) AddPrefixMulticolumnTable(prefix string, rows []Row) Node { - now := mtime.Now() for _, row := range rows { // Add all the row values as separate entries for columnID, value := range row.Entries { key := strings.Join([]string{row.ID, columnID}, tableEntryKeySeparator) - node = node.WithLatest(prefix+key, now, value) + node = node.WithLatest(prefix+key, value) } } return node @@ -35,9 +33,8 @@ func (node Node) AddPrefixMulticolumnTable(prefix string, rows []Row) Node { // AddPrefixPropertyList appends arbitrary key-value pairs to the Node, returning a new node. func (node Node) AddPrefixPropertyList(prefix string, propertyList map[string]string) Node { - now := mtime.Now() for label, value := range propertyList { - node = node.WithLatest(prefix+label, now, value) + node = node.WithLatest(prefix+label, value) } return node }