Skip to content

Commit

Permalink
Merge pull request #1043 from weaveworks/1040-docker-exec-crash
Browse files Browse the repository at this point in the history
Distinguish between reporting probes and controlling probes
  • Loading branch information
tomwilkie committed Feb 26, 2016
2 parents b0d6078 + b33c516 commit ef1fc2a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions probe/docker/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *registry) attachContainer(containerID string, req xfer.Request) xfer.Re
hasTTY := c.HasTTY()
id, pipe, err := controls.NewPipe(r.pipes, req.AppID)
if err != nil {
xfer.ResponseError(err)
return xfer.ResponseError(err)
}
local, _ := pipe.Ends()
cw, err := r.client.AttachToContainerNonBlocking(docker_client.AttachToContainerOptions{
Expand Down Expand Up @@ -103,12 +103,12 @@ func (r *registry) execContainer(containerID string, req xfer.Request) xfer.Resp
Container: containerID,
})
if err != nil {
xfer.ResponseError(err)
return xfer.ResponseError(err)
}

id, pipe, err := controls.NewPipe(r.pipes, req.AppID)
if err != nil {
xfer.ResponseError(err)
return xfer.ResponseError(err)
}
local, _ := pipe.Ends()
cw, err := r.client.StartExecNonBlocking(exec.ID, docker_client.StartExecOptions{
Expand Down
8 changes: 6 additions & 2 deletions probe/docker/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ const (
type Reporter struct {
registry Registry
hostID string
probeID string
probe *probe.Probe
}

// NewReporter makes a new Reporter
func NewReporter(registry Registry, hostID string, probe *probe.Probe) *Reporter {
func NewReporter(registry Registry, hostID string, probeID string, probe *probe.Probe) *Reporter {
reporter := &Reporter{
registry: registry,
hostID: hostID,
probeID: probeID,
probe: probe,
}
registry.WatchContainerUpdates(reporter.ContainerUpdated)
Expand Down Expand Up @@ -103,9 +105,11 @@ func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
Icon: "fa-terminal",
})

metadata := map[string]string{report.ControlProbeID: r.probeID}

r.registry.WalkContainers(func(c Container) {
nodeID := report.MakeContainerNodeID(c.ID())
result.AddNode(nodeID, c.GetNode(r.hostID, localAddrs))
result.AddNode(nodeID, c.GetNode(r.hostID, localAddrs).WithLatests(metadata))
})

return result
Expand Down
11 changes: 7 additions & 4 deletions probe/docker/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ var (
)

func TestReporter(t *testing.T) {
var controlProbeID = "a1b2c3d4"

containerImageNodeID := report.MakeContainerImageNodeID("baz")
rpt, err := docker.NewReporter(mockRegistryInstance, "host1", nil).Report()
rpt, err := docker.NewReporter(mockRegistryInstance, "host1", controlProbeID, nil).Report()
if err != nil {
t.Fatal(err)
}
Expand All @@ -65,9 +67,10 @@ func TestReporter(t *testing.T) {
}

for k, want := range map[string]string{
docker.ContainerID: "ping",
docker.ContainerName: "pong",
docker.ImageID: "baz",
docker.ContainerID: "ping",
docker.ContainerName: "pong",
docker.ImageID: "baz",
report.ControlProbeID: controlProbeID,
} {
if have, ok := node.Latest.Lookup(k); !ok || have != want {
t.Errorf("Expected container %s latest %q: %q, got %q", containerNodeID, k, want, have)
Expand Down
11 changes: 3 additions & 8 deletions probe/host/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import (
// in every topology to an origin host node in the host topology.
type Tagger struct {
hostNodeID string
probeID string
}

// NewTagger tags each node with a foreign key linking it to its origin host
// in the host topology.
func NewTagger(hostID, probeID string) Tagger {
func NewTagger(hostID string) Tagger {
return Tagger{
hostNodeID: report.MakeHostNodeID(hostID),
probeID: probeID,
}
}

Expand All @@ -27,11 +25,8 @@ func (Tagger) Name() string { return "Host" }
// Tag implements Tagger.
func (t Tagger) Tag(r report.Report) (report.Report, error) {
var (
metadata = map[string]string{
report.HostNodeID: t.hostNodeID,
report.ProbeID: t.probeID,
}
parents = report.EmptySets.Add(report.Host, report.MakeStringSet(t.hostNodeID))
metadata = map[string]string{report.HostNodeID: t.hostNodeID}
parents = report.EmptySets.Add(report.Host, report.MakeStringSet(t.hostNodeID))
)

// Explicity don't tag Endpoints and Addresses - These topologies include pseudo nodes,
Expand Down
8 changes: 1 addition & 7 deletions probe/host/tagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (
func TestTagger(t *testing.T) {
var (
hostID = "foo"
probeID = "a1b2c3d4"
endpointNodeID = report.MakeEndpointNodeID(hostID, "1.2.3.4", "56789") // hostID ignored
node = report.MakeNodeWith(map[string]string{"foo": "bar"})
)

r := report.MakeReport()
r.Process.AddNode(endpointNodeID, node)
rpt, _ := host.NewTagger(hostID, probeID).Tag(r)
rpt, _ := host.NewTagger(hostID).Tag(r)
have := rpt.Process.Nodes[endpointNodeID].Copy()

// It should now have the host ID
Expand All @@ -26,11 +25,6 @@ func TestTagger(t *testing.T) {
t.Errorf("Expected %q got %q", wantHostID, report.MakeHostNodeID(hostID))
}

// It should now have the probe ID
if haveProbeID, ok := have.Latest.Lookup(report.ProbeID); !ok || haveProbeID != probeID {
t.Errorf("Expected %q got %q", probeID, haveProbeID)
}

// It should still have the other keys
want := "bar"
if have, ok := have.Latest.Lookup("foo"); !ok || have != want {
Expand Down
4 changes: 2 additions & 2 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func probeMain() {
host.NewReporter(hostID, hostName),
process.NewReporter(processCache, hostID, process.GetDeltaTotalJiffies),
)
p.AddTagger(probe.NewTopologyTagger(), host.NewTagger(hostID, probeID))
p.AddTagger(probe.NewTopologyTagger(), host.NewTagger(hostID))

if *dockerEnabled {
if err := report.AddLocalBridge(*dockerBridge); err != nil {
Expand All @@ -155,7 +155,7 @@ func probeMain() {
if registry, err := docker.NewRegistry(*dockerInterval, clients); err == nil {
defer registry.Stop()
p.AddTagger(docker.NewTagger(registry, processCache))
p.AddReporter(docker.NewReporter(registry, hostID, p))
p.AddReporter(docker.NewReporter(registry, hostID, probeID, p))
} else {
log.Errorf("Docker: failed to start registry: %v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion render/detailed/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ func controlsFor(topology report.Topology, nodeID string) []ControlInstance {

for _, id := range node.Controls.Controls {
if control, ok := topology.Controls[id]; ok {
probeID, _ := node.Latest.Lookup(report.ProbeID)
probeID, ok := node.Latest.Lookup(report.ControlProbeID)
if !ok {
continue
}
result = append(result, ControlInstance{
ProbeID: probeID,
NodeID: nodeID,
Expand Down
4 changes: 2 additions & 2 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ const (
// a node in the host topology. That host node is the origin host, where
// the node was originally detected.
HostNodeID = "host_node_id"
// ProbeID is the random ID of the probe which generated the specific node.
ProbeID = "probe_id"
// ControlProbeID is the random ID of the probe which controls the specific node.
ControlProbeID = "control_probe_id"
)

0 comments on commit ef1fc2a

Please sign in to comment.