From 497270eff77e81bea3ace9ff90c1d78cc8b9de22 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 18 Apr 2016 14:39:48 +0100 Subject: [PATCH 1/3] support docker rename events --- probe/docker/registry.go | 3 ++- probe/docker/registry_test.go | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/probe/docker/registry.go b/probe/docker/registry.go index 962f22b26e..b839e86e5f 100644 --- a/probe/docker/registry.go +++ b/probe/docker/registry.go @@ -14,6 +14,7 @@ import ( const ( CreateEvent = "create" DestroyEvent = "destroy" + RenameEvent = "rename" StartEvent = "start" DieEvent = "die" PauseEvent = "pause" @@ -238,7 +239,7 @@ func (r *registry) updateImages() error { func (r *registry) handleEvent(event *docker_client.APIEvents) { switch event.Status { - case CreateEvent, StartEvent, DieEvent, DestroyEvent, PauseEvent, UnpauseEvent: + case CreateEvent, RenameEvent, StartEvent, DieEvent, DestroyEvent, PauseEvent, UnpauseEvent: r.updateContainerState(event.ID) } } diff --git a/probe/docker/registry_test.go b/probe/docker/registry_test.go index fefb412d86..1039d85f6f 100644 --- a/probe/docker/registry_test.go +++ b/probe/docker/registry_test.go @@ -203,9 +203,22 @@ var ( }, }, } - apiContainer1 = client.APIContainers{ID: "ping"} - apiContainer2 = client.APIContainers{ID: "wiff"} - apiImage1 = client.APIImages{ID: "baz", RepoTags: []string{"bang", "not-chosen"}} + renamedContainer = &client.Container{ + ID: "renamed", + Name: "renamed", + Image: "baz", + State: client.State{Pid: 1, Running: true}, + Config: &client.Config{ + Labels: map[string]string{ + "foo1": "bar1", + "foo2": "bar2", + }, + }, + } + apiContainer1 = client.APIContainers{ID: "ping"} + apiContainer2 = client.APIContainers{ID: "wiff"} + renamedAPIContainer = client.APIContainers{ID: "renamed"} + apiImage1 = client.APIImages{ID: "baz", RepoTags: []string{"bang", "not-chosen"}} ) func newMockClient() *mockDockerClient { @@ -350,5 +363,17 @@ func TestRegistryEvents(t *testing.T) { want := []docker.Container{} check(want) } + + { + mdc.Lock() + mdc.apiContainers = []client.APIContainers{renamedAPIContainer} + mdc.containers[renamedContainer.ID] = renamedContainer + mdc.Unlock() + mdc.send(&client.APIEvents{Status: docker.RenameEvent, ID: renamedContainer.ID}) + runtime.Gosched() + + want := []docker.Container{&mockContainer{renamedContainer}} + check(want) + } }) } From 415ac7c5db5c47861022a8e84b3fa6d682426f08 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Tue, 19 Apr 2016 17:14:17 +0200 Subject: [PATCH 2/3] Update node label as well as metrics if they change! --- client/app/scripts/charts/nodes-chart.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/app/scripts/charts/nodes-chart.js b/client/app/scripts/charts/nodes-chart.js index df4a5f887d..b64d53efb6 100644 --- a/client/app/scripts/charts/nodes-chart.js +++ b/client/app/scripts/charts/nodes-chart.js @@ -333,9 +333,6 @@ export default class NodesChart extends React.Component { const stateNodes = this.initNodes(props.nodes, state.nodes); const stateEdges = this.initEdges(props.nodes, stateNodes); - const nodeMetrics = stateNodes.map(node => makeMap({ - metrics: node.get('metrics') - })); const nodeScale = this.getNodeScale(props.nodes, state.width, state.height); const nextState = { nodeScale }; @@ -356,7 +353,7 @@ export default class NodesChart extends React.Component { // inject metrics and save coordinates for restore const layoutNodes = graph.nodes - .mergeDeep(nodeMetrics) + .mergeDeep(stateNodes) .map(node => node.merge({ px: node.get('x'), py: node.get('y') From 81334cdbd88f7a4708832ca318414d8e9eb5e6b8 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Wed, 20 Apr 2016 10:05:17 +0200 Subject: [PATCH 3/3] Fixes up node (de)selection after bad attempt to fix stale metadata --- client/app/scripts/charts/nodes-chart.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/app/scripts/charts/nodes-chart.js b/client/app/scripts/charts/nodes-chart.js index b64d53efb6..ae839c96f2 100644 --- a/client/app/scripts/charts/nodes-chart.js +++ b/client/app/scripts/charts/nodes-chart.js @@ -352,12 +352,15 @@ export default class NodesChart extends React.Component { log(`graph layout took ${timedLayouter.time}ms`); // inject metrics and save coordinates for restore - const layoutNodes = graph.nodes - .mergeDeep(stateNodes) + let layoutNodes = graph.nodes .map(node => node.merge({ px: node.get('x'), py: node.get('y') })); + + // Re-apply in case layout runner's node cache applied stale node metadata + layoutNodes = layoutNodes.mergeDeep(stateNodes); + const layoutEdges = graph.edges .map(edge => edge.set('ppoints', edge.get('points')));