[ARVADOS] updated: b30e81ee46c196476a03bc244fbc4419573ba34e

Git user git at public.curoverse.com
Fri Mar 17 16:30:56 EDT 2017


Summary of changes:
 services/crunch-run/crunchrun.go      | 72 ++++++++++++++++++++++++++---------
 services/crunch-run/crunchrun_test.go | 25 +++++++++++-
 2 files changed, 77 insertions(+), 20 deletions(-)

       via  b30e81ee46c196476a03bc244fbc4419573ba34e (commit)
       via  9f34ff6f6a6ea1d384528a093bad1c72bd2cea89 (commit)
      from  386faadf691e444b71d6c96e7c00792d9a0ba2c7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit b30e81ee46c196476a03bc244fbc4419573ba34e
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Fri Mar 17 17:29:56 2017 -0300

    10218: Save the container record as a json file and also write it on the logs.

diff --git a/services/crunch-run/crunchrun.go b/services/crunch-run/crunchrun.go
index 44d68ca..a3338ec 100644
--- a/services/crunch-run/crunchrun.go
+++ b/services/crunch-run/crunchrun.go
@@ -95,7 +95,6 @@ type ContainerRunner struct {
 	ArvMountExit   chan error
 	finalState     string
 
-	infoLogger   io.WriteCloser
 	statLogger   io.WriteCloser
 	statReporter *crunchstat.Reporter
 	statInterval time.Duration
@@ -559,6 +558,34 @@ func (runner *ContainerRunner) LogNodeInfo() (err error) {
 	return nil
 }
 
+// Get and save the raw JSON container record from the API server
+func (runner *ContainerRunner) LogContainerRecord() (err error) {
+	w := &ArvLogWriter{
+		runner.ArvClient,
+		runner.Container.UUID,
+		"container",
+		runner.LogCollection.Open("container.json"),
+	}
+	logger := log.New(w, "container", 0)
+
+	// Convert container record to pretty-printed JSON []byte
+	rec, err := json.MarshalIndent(runner.Container, "", "    ")
+	if err != nil {
+		return fmt.Errorf("While converting container record to JSON: %v", err)
+	}
+
+	// Write JSON record line-by-line
+	for _, line := range strings.Split(string(rec), "\n") {
+		logger.Println(line)
+	}
+
+	err = w.Close()
+	if err != nil {
+		return fmt.Errorf("While closing container.json log: %v", err)
+	}
+	return nil
+}
+
 // AttachLogs connects the docker container stdout and stderr logs to the
 // Arvados logger which logs to Keep and the API server logs table.
 func (runner *ContainerRunner) AttachStreams() (err error) {
@@ -1056,6 +1083,11 @@ func (runner *ContainerRunner) Run() (err error) {
 	if err != nil {
 		return
 	}
+	// Save container.json record on log collection
+	err = runner.LogContainerRecord()
+	if err != nil {
+		return
+	}
 
 	runner.StartCrunchstat()
 
diff --git a/services/crunch-run/crunchrun_test.go b/services/crunch-run/crunchrun_test.go
index fcf2456..c26830d 100644
--- a/services/crunch-run/crunchrun_test.go
+++ b/services/crunch-run/crunchrun_test.go
@@ -651,7 +651,7 @@ func (s *TestSuite) TestCrunchstat(c *C) {
 	c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
 }
 
-func (s *TestSuite) TestNodeInfo(c *C) {
+func (s *TestSuite) TestNodeInfoLog(c *C) {
 	api, _, _ := FullRunHelper(c, `{
 		"command": ["sleep", "1"],
 		"container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
@@ -677,6 +677,29 @@ func (s *TestSuite) TestNodeInfo(c *C) {
 	c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
 }
 
+func (s *TestSuite) TestContainerRecordLog(c *C) {
+	api, _, _ := FullRunHelper(c, `{
+		"command": ["sleep", "1"],
+		"container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
+		"cwd": ".",
+		"environment": {},
+		"mounts": {"/tmp": {"kind": "tmp"} },
+		"output_path": "/tmp",
+		"priority": 1,
+		"runtime_constraints": {}
+	}`, nil, func(t *TestDockerClient) {
+		time.Sleep(time.Second)
+		t.logWriter.Close()
+		t.finish <- dockerclient.WaitResult{}
+	})
+
+	c.Check(api.CalledWith("container.exit_code", 0), NotNil)
+	c.Check(api.CalledWith("container.state", "Complete"), NotNil)
+
+	c.Assert(api.Logs["container"], NotNil)
+	c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
+}
+
 func (s *TestSuite) TestFullRunStderr(c *C) {
 	api, _, _ := FullRunHelper(c, `{
     "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],

commit 9f34ff6f6a6ea1d384528a093bad1c72bd2cea89
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Thu Mar 16 16:16:34 2017 -0300

    10218: Use a []string for the entire command instead of splitting it.

diff --git a/services/crunch-run/crunchrun.go b/services/crunch-run/crunchrun.go
index 9ca4f80..44d68ca 100644
--- a/services/crunch-run/crunchrun.go
+++ b/services/crunch-run/crunchrun.go
@@ -509,18 +509,8 @@ func (runner *ContainerRunner) StartCrunchstat() {
 }
 
 type infoCommand struct {
-	label   string
-	command string
-	args    []string
-}
-
-func newInfoCommand(label string, command string) infoCommand {
-	cmd := strings.Split(command, " ")
-	return infoCommand{
-		label:   label,
-		command: cmd[0],
-		args:    cmd[1:],
-	}
+	label string
+	cmd   []string
 }
 
 // Gather node information and store it on the log for debugging
@@ -530,19 +520,31 @@ func (runner *ContainerRunner) LogNodeInfo() (err error) {
 	logger := log.New(w, "node-info", 0)
 
 	commands := []infoCommand{
-		newInfoCommand("Host Information", "uname -a"),
-		newInfoCommand("CPU Information", "cat /proc/cpuinfo"),
-		newInfoCommand("Memory Information", "cat /proc/meminfo"),
-		newInfoCommand("Disk Space", "df -m"),
+		infoCommand{
+			label: "Host Information",
+			cmd:   []string{"uname", "-a"},
+		},
+		infoCommand{
+			label: "CPU Information",
+			cmd:   []string{"cat", "/proc/cpuinfo"},
+		},
+		infoCommand{
+			label: "Memory Information",
+			cmd:   []string{"cat", "/proc/meminfo"},
+		},
+		infoCommand{
+			label: "Disk Space",
+			cmd:   []string{"df", "-m"},
+		},
 	}
 
 	// Run commands with informational output to be logged.
 	var out []byte
 	for _, command := range commands {
-		out, err = exec.Command(command.command, command.args...).Output()
+		out, err = exec.Command(command.cmd[0], command.cmd[1:]...).Output()
 		if err != nil {
 			return fmt.Errorf("While running command '%s': %v",
-				command.command, err)
+				command.cmd[0], err)
 		}
 		logger.Println(command.label)
 		for _, line := range strings.Split(string(out), "\n") {

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list