Skip to content

Commit

Permalink
Use argv[0] for process name, differentiate scope app and probe.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Jan 5, 2016
1 parent 6850e84 commit 3653303
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 82 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MAINTAINER Weaveworks Inc <[email protected]>
LABEL works.weave.role=system
WORKDIR /home/weave
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/testing" >>/etc/apk/repositories && \
apk add --update runit conntrack-tools iproute2 util-linux curl && \
apk add --update bash runit conntrack-tools iproute2 util-linux curl && \
rm -rf /var/cache/apk/*
ADD ./docker.tgz /
ADD ./weave /usr/bin/
Expand Down
4 changes: 2 additions & 2 deletions docker/run-app
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash

exec /home/weave/scope app $(cat /etc/weave/scope-app.args)
exec -a scope-app /home/weave/scope app $(cat /etc/weave/scope-app.args)
4 changes: 2 additions & 2 deletions docker/run-probe
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash

exec /home/weave/scope probe $(cat /etc/weave/scope-probe.args) $(cat /etc/weave/apps)
exec -a scope-probe /home/weave/scope probe $(cat /etc/weave/scope-probe.args) $(cat /etc/weave/apps)
2 changes: 1 addition & 1 deletion probe/endpoint/procspy/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func walkProcPid(buf *bytes.Buffer, walker process.Walker) (map[uint64]*Proc, er
if proc == nil {
proc = &Proc{
PID: uint(p.PID),
Name: p.Comm,
Name: p.Name,
}
}
res[statT.Ino] = proc
Expand Down
4 changes: 2 additions & 2 deletions probe/endpoint/procspy/proc_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var mockFS = fs.Dir("",
},
),
fs.File{
FName: "comm",
FContents: "foo\n",
FName: "cmdline",
FContents: "foo",
},
fs.Dir("ns",
fs.File{
Expand Down
4 changes: 2 additions & 2 deletions probe/process/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// We use these keys in node metadata
const (
PID = "pid"
Comm = "comm"
Name = "name"
PPID = "ppid"
Cmdline = "cmdline"
Threads = "threads"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (r *Reporter) processTopology() (report.Topology, error) {
node := report.MakeNode()
for _, tuple := range []struct{ key, value string }{
{PID, pidstr},
{Comm, p.Comm},
{Name, p.Name},
{Cmdline, p.Cmdline},
{Threads, strconv.Itoa(p.Threads)},
} {
Expand Down
16 changes: 8 additions & 8 deletions probe/process/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func (m *mockWalker) Walk(f func(process.Process, process.Process)) error {
func TestReporter(t *testing.T) {
walker := &mockWalker{
processes: []process.Process{
{PID: 1, PPID: 0, Comm: "init"},
{PID: 2, PPID: 1, Comm: "bash"},
{PID: 3, PPID: 1, Comm: "apache", Threads: 2},
{PID: 4, PPID: 2, Comm: "ping", Cmdline: "ping foo.bar.local"},
{PID: 1, PPID: 0, Name: "init"},
{PID: 2, PPID: 1, Name: "bash"},
{PID: 3, PPID: 1, Name: "apache", Threads: 2},
{PID: 4, PPID: 2, Name: "ping", Cmdline: "ping foo.bar.local"},
{PID: 5, PPID: 1, Cmdline: "tail -f /var/log/syslog"},
},
}
Expand All @@ -42,27 +42,27 @@ func TestReporter(t *testing.T) {
want.Process = report.MakeTopology().AddNode(
report.MakeProcessNodeID("", "1"), report.MakeNodeWith(map[string]string{
process.PID: "1",
process.Comm: "init",
process.Name: "init",
process.Threads: "0",
}).WithMetric(process.MemoryUsage, report.MakeMetric().Add(now, 0.)),
).AddNode(
report.MakeProcessNodeID("", "2"), report.MakeNodeWith(map[string]string{
process.PID: "2",
process.Comm: "bash",
process.Name: "bash",
process.PPID: "1",
process.Threads: "0",
}).WithMetric(process.MemoryUsage, report.MakeMetric().Add(now, 0.)),
).AddNode(
report.MakeProcessNodeID("", "3"), report.MakeNodeWith(map[string]string{
process.PID: "3",
process.Comm: "apache",
process.Name: "apache",
process.PPID: "1",
process.Threads: "2",
}).WithMetric(process.MemoryUsage, report.MakeMetric().Add(now, 0.)),
).AddNode(
report.MakeProcessNodeID("", "4"), report.MakeNodeWith(map[string]string{
process.PID: "4",
process.Comm: "ping",
process.Name: "ping",
process.PPID: "2",
process.Cmdline: "ping foo.bar.local",
process.Threads: "0",
Expand Down
8 changes: 4 additions & 4 deletions probe/process/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
func TestTree(t *testing.T) {
walker := &mockWalker{
processes: []process.Process{
{PID: 1, PPID: 0, Comm: "init"},
{PID: 2, PPID: 1, Comm: "bash"},
{PID: 3, PPID: 1, Comm: "apache", Threads: 2},
{PID: 4, PPID: 2, Comm: "ping", Cmdline: "ping foo.bar.local"},
{PID: 1, PPID: 0, Name: "init"},
{PID: 2, PPID: 1, Name: "bash"},
{PID: 3, PPID: 1, Name: "apache", Threads: 2},
{PID: 4, PPID: 2, Name: "ping", Cmdline: "ping foo.bar.local"},
},
}

Expand Down
2 changes: 1 addition & 1 deletion probe/process/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "sync"
// Process represents a single process.
type Process struct {
PID, PPID int
Comm string
Name string
Cmdline string
Threads int
Jiffies uint64
Expand Down
4 changes: 2 additions & 2 deletions probe/process/walker_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func parseLSOF(output string) (map[string]Process, error) {
process.PID = pid

case 'c':
process.Comm = value
process.Name = value

case 'n':
// 'n' is the last field, with '-F cn'
Expand All @@ -83,7 +83,7 @@ func parseLSOF(output string) (map[string]Process, error) {
}
processes[addresses[0]] = Process{
PID: process.PID,
Comm: process.Comm,
Name: process.Name,
}

default:
Expand Down
15 changes: 8 additions & 7 deletions probe/process/walker_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,22 @@ func (w *walker) Walk(f func(Process, Process)) error {
continue
}

cmdline := ""
cmdline, name := "", "(unknown)"
if cmdlineBuf, err := cachedReadFile(path.Join(w.procRoot, filename, "cmdline")); err == nil {
// like proc, treat name as the first element of command line
i := bytes.IndexByte(cmdlineBuf, '\000')
if i == -1 {
i = len(cmdlineBuf)
}
name = string(cmdlineBuf[:i])
cmdlineBuf = bytes.Replace(cmdlineBuf, []byte{'\000'}, []byte{' '}, -1)
cmdline = string(cmdlineBuf)
}

comm := "(unknown)"
if commBuf, err := cachedReadFile(path.Join(w.procRoot, filename, "comm")); err == nil {
comm = strings.TrimSpace(string(commBuf))
}

f(Process{
PID: pid,
PPID: ppid,
Comm: comm,
Name: name,
Cmdline: cmdline,
Threads: threads,
Jiffies: jiffies,
Expand Down
30 changes: 7 additions & 23 deletions probe/process/walker_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
var mockFS = fs.Dir("",
fs.Dir("proc",
fs.Dir("3",
fs.File{
FName: "comm",
FContents: "curl\n",
},
fs.File{
FName: "cmdline",
FContents: "curl\000google.com",
Expand All @@ -27,27 +23,19 @@ var mockFS = fs.Dir("",
},
),
fs.Dir("2",
fs.File{
FName: "comm",
FContents: "bash\n",
},
fs.File{
FName: "cmdline",
FContents: "",
FContents: "bash",
},
fs.File{
FName: "stat",
FContents: "2 na R 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0",
},
),
fs.Dir("4",
fs.File{
FName: "comm",
FContents: "apache\n",
},
fs.File{
FName: "cmdline",
FContents: "",
FContents: "apache",
},
fs.File{
FName: "stat",
Expand All @@ -56,13 +44,9 @@ var mockFS = fs.Dir("",
),
fs.Dir("notapid"),
fs.Dir("1",
fs.File{
FName: "comm",
FContents: "init\n",
},
fs.File{
FName: "cmdline",
FContents: "",
FContents: "init",
},
fs.File{
FName: "stat",
Expand All @@ -77,10 +61,10 @@ func TestWalker(t *testing.T) {
defer fs_hook.Restore()

want := map[int]process.Process{
3: {PID: 3, PPID: 2, Comm: "curl", Cmdline: "curl google.com", Threads: 1},
2: {PID: 2, PPID: 1, Comm: "bash", Cmdline: "", Threads: 1},
4: {PID: 4, PPID: 3, Comm: "apache", Cmdline: "", Threads: 1},
1: {PID: 1, PPID: 0, Comm: "init", Cmdline: "", Threads: 1},
3: {PID: 3, PPID: 2, Name: "curl", Cmdline: "curl google.com", Threads: 1},
2: {PID: 2, PPID: 1, Name: "bash", Cmdline: "", Threads: 1},
4: {PID: 4, PPID: 3, Name: "apache", Cmdline: "", Threads: 1},
1: {PID: 1, PPID: 0, Name: "init", Cmdline: "", Threads: 1},
}

have := map[int]process.Process{}
Expand Down
8 changes: 4 additions & 4 deletions probe/process/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func TestBasicWalk(t *testing.T) {

func TestCache(t *testing.T) {
processes := []process.Process{
{PID: 1, PPID: 0, Comm: "init"},
{PID: 2, PPID: 1, Comm: "bash"},
{PID: 3, PPID: 1, Comm: "apache", Threads: 2},
{PID: 4, PPID: 2, Comm: "ping", Cmdline: "ping foo.bar.local"},
{PID: 1, PPID: 0, Name: "init", Cmdline: "init"},
{PID: 2, PPID: 1, Name: "bash", Cmdline: "bash"},
{PID: 3, PPID: 1, Name: "apache", Threads: 2, Cmdline: "apache"},
{PID: 4, PPID: 2, Name: "ping", Cmdline: "ping foo.bar.local"},
}
walker := &mockWalker{
processes: processes,
Expand Down
2 changes: 1 addition & 1 deletion render/detailed_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func processOriginTable(nmd report.Node, addHostTag bool, addContainerTag bool)

var (
title = "Process"
name, commFound = nmd.Metadata[process.Comm]
name, commFound = nmd.Metadata[process.Name]
pid, pidFound = nmd.Metadata[process.PID]
)
if commFound {
Expand Down
22 changes: 11 additions & 11 deletions render/expected/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ var (
RenderedProcesses = (render.RenderableNodes{
ClientProcess1ID: {
ID: ClientProcess1ID,
LabelMajor: fixture.Client1Comm,
LabelMajor: fixture.Client1Name,
LabelMinor: fmt.Sprintf("%s (%s)", fixture.ClientHostID, fixture.Client1PID),
Rank: fixture.Client1Comm,
Rank: fixture.Client1Name,
Pseudo: false,
Origins: report.MakeIDList(
fixture.Client54001NodeID,
Expand All @@ -85,9 +85,9 @@ var (
},
ClientProcess2ID: {
ID: ClientProcess2ID,
LabelMajor: fixture.Client2Comm,
LabelMajor: fixture.Client2Name,
LabelMinor: fmt.Sprintf("%s (%s)", fixture.ClientHostID, fixture.Client2PID),
Rank: fixture.Client2Comm,
Rank: fixture.Client2Name,
Pseudo: false,
Origins: report.MakeIDList(
fixture.Client54002NodeID,
Expand All @@ -104,7 +104,7 @@ var (
ID: ServerProcessID,
LabelMajor: "apache",
LabelMinor: fmt.Sprintf("%s (%s)", fixture.ServerHostID, fixture.ServerPID),
Rank: fixture.ServerComm,
Rank: fixture.ServerName,
Pseudo: false,
Origins: report.MakeIDList(
fixture.Server80NodeID,
Expand All @@ -119,9 +119,9 @@ var (
},
nonContainerProcessID: {
ID: nonContainerProcessID,
LabelMajor: fixture.NonContainerComm,
LabelMajor: fixture.NonContainerName,
LabelMinor: fmt.Sprintf("%s (%s)", fixture.ServerHostID, fixture.NonContainerPID),
Rank: fixture.NonContainerComm,
Rank: fixture.NonContainerName,
Pseudo: false,
Origins: report.MakeIDList(
fixture.NonContainerProcessNodeID,
Expand Down Expand Up @@ -173,11 +173,11 @@ var (
IngressByteCount: newu64(2100),
},
},
fixture.NonContainerComm: {
ID: fixture.NonContainerComm,
LabelMajor: fixture.NonContainerComm,
fixture.NonContainerName: {
ID: fixture.NonContainerName,
LabelMajor: fixture.NonContainerName,
LabelMinor: "1 process",
Rank: fixture.NonContainerComm,
Rank: fixture.NonContainerName,
Pseudo: false,
Origins: report.MakeIDList(
fixture.NonContainerProcessNodeID,
Expand Down
6 changes: 3 additions & 3 deletions render/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func MapProcessIdentity(m RenderableNode, _ report.Networks) RenderableNodes {

var (
id = MakeProcessID(report.ExtractHostID(m.Node), pid)
major = m.Metadata["comm"]
major = m.Metadata[process.Name]
minor = fmt.Sprintf("%s (%s)", report.ExtractHostID(m.Node), pid)
rank = m.Metadata["comm"]
rank = m.Metadata[process.Name]
)

return RenderableNodes{id: NewRenderableNodeWith(id, major, minor, rank, m)}
Expand Down Expand Up @@ -440,7 +440,7 @@ func MapProcess2Name(n RenderableNode, _ report.Networks) RenderableNodes {
return RenderableNodes{n.ID: n}
}

name, ok := n.Node.Metadata["comm"]
name, ok := n.Node.Metadata[process.Name]
if !ok {
return RenderableNodes{}
}
Expand Down
16 changes: 8 additions & 8 deletions test/fixture/report_fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ var (
ServerPID = "215"
NonContainerPID = "1234"

Client1Comm = "curl"
Client2Comm = "curl"
ServerComm = "apache"
NonContainerComm = "bash"
Client1Name = "curl"
Client2Name = "curl"
ServerName = "apache"
NonContainerName = "bash"

True = "true"

Expand Down Expand Up @@ -197,25 +197,25 @@ var (
Nodes: report.Nodes{
ClientProcess1NodeID: report.MakeNodeWith(map[string]string{
process.PID: Client1PID,
"comm": Client1Comm,
process.Name: Client1Name,
docker.ContainerID: ClientContainerID,
report.HostNodeID: ClientHostNodeID,
}),
ClientProcess2NodeID: report.MakeNodeWith(map[string]string{
process.PID: Client2PID,
"comm": Client2Comm,
process.Name: Client2Name,
docker.ContainerID: ClientContainerID,
report.HostNodeID: ClientHostNodeID,
}),
ServerProcessNodeID: report.MakeNodeWith(map[string]string{
process.PID: ServerPID,
"comm": ServerComm,
process.Name: ServerName,
docker.ContainerID: ServerContainerID,
report.HostNodeID: ServerHostNodeID,
}),
NonContainerProcessNodeID: report.MakeNodeWith(map[string]string{
process.PID: NonContainerPID,
"comm": NonContainerComm,
process.Name: NonContainerName,
report.HostNodeID: ServerHostNodeID,
}),
},
Expand Down

0 comments on commit 3653303

Please sign in to comment.