[ARVADOS] created: 2.1.0-789-g828efc617

Git user git at public.arvados.org
Mon May 17 15:26:27 UTC 2021


        at  828efc61700cd2a122dd87a7b629fa50e7ec5df3 (commit)


commit 828efc61700cd2a122dd87a7b629fa50e7ec5df3
Author: Nico Cesar <nico at nicocesar.com>
Date:   Mon May 17 11:24:59 2021 -0400

    starting to look promising. Squash this commit
    
    Arvados-DCO-1.1-Signed-off-by: Nico Cesar <nico at curii.com>

diff --git a/lib/crunchrun/crunchrun.go b/lib/crunchrun/crunchrun.go
index 88c137277..34436b970 100644
--- a/lib/crunchrun/crunchrun.go
+++ b/lib/crunchrun/crunchrun.go
@@ -175,7 +175,7 @@ type ContainerRunner struct {
 
 	enableNetwork string // one of "default" or "always"
 	networkMode   string // passed through to HostConfig.NetworkMode
-	arvMountLog   *ThrottledLogger
+	arvMountLog   io.WriteCloser
 
 	containerWatchdogInterval time.Duration
 
@@ -332,7 +332,17 @@ func (runner *ContainerRunner) ArvMountCmd(arvMountCmd []string, token string) (
 	if err != nil {
 		return nil, err
 	}
-	runner.arvMountLog = NewThrottledLogger(w)
+	runner.arvMountLog = &regexpMatchingWriter{
+		WriteCloser: w,
+		Notify: func(a string, b string) {
+			fmt.Printf("%s,%s,EUREKA", a, b)
+		},
+		Regexps: []string{
+			".",
+			"Keep write error",
+			"Block not found error",
+			"Unhandled exception during FUSE operation"},
+	}
 	c.Stdout = runner.arvMountLog
 	c.Stderr = runner.arvMountLog
 
diff --git a/lib/crunchrun/crunchrun_test.go b/lib/crunchrun/crunchrun_test.go
index dbdaa6293..05679e261 100644
--- a/lib/crunchrun/crunchrun_test.go
+++ b/lib/crunchrun/crunchrun_test.go
@@ -1138,7 +1138,8 @@ func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
 	defer kc.Close()
 	cr, err := NewContainerRunner(s.client, api, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
 	c.Assert(err, IsNil)
-	cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
+	am := &ArvMountCmdLine{}
+	cr.RunArvMount = am.ArvMountTest
 	cr.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
 		return &ArvTestClient{}, &KeepTestClient{}, nil, nil
 	}
@@ -1527,6 +1528,28 @@ func (s *TestSuite) TestSetupMounts(c *C) {
 		checkEmpty()
 	}
 
+	// arv-mount logs should match some regexp #8363
+	{
+		i = 0
+		cr.ArvMountPoint = ""
+		cr.Container.Mounts = make(map[string]arvados.Mount)
+		cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
+		cr.Container.OutputPath = "/tmp"
+		cr.statInterval = 5 * time.Second
+		cr.token = arvadostest.ActiveToken
+		err := cr.SetupMounts()
+		c.Check(err, IsNil)
+
+		fmt.Printf("NICO: %#v", am)
+
+		err = cr.Run()
+		c.Check(err, IsNil)
+
+		os.RemoveAll(cr.ArvMountPoint)
+		cr.CleanupDirs()
+		checkEmpty()
+	}
+
 	// git_tree mounts
 	{
 		i = 0
@@ -1609,6 +1632,29 @@ func (s *TestSuite) TestStdout(c *C) {
 	c.Check(cr.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
 }
 
+func (s *TestSuite) TestArvMountRegexp(c *C) {
+	helperRecord := `{
+		"command": ["/bin/sh", "-c", "echo $FROBIZ"],
+		"container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
+		"cwd": "/bin",
+		"environment": {"FROBIZ": "bilbo"},
+		"mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
+		"output_path": "/tmp",
+		"priority": 1,
+		"runtime_constraints": {},
+		"state": "Locked"
+	}`
+
+	_, cr, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
+		t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
+		t.logWriter.Close()
+	})
+
+	err := cr.Run()
+	c.Check(err, IsNil)
+
+}
+
 // Used by the TestStdoutWithWrongPath*()
 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
 	rec := arvados.Container{}
diff --git a/lib/crunchrun/logging.go b/lib/crunchrun/logging.go
index 050894383..a1160cf2e 100644
--- a/lib/crunchrun/logging.go
+++ b/lib/crunchrun/logging.go
@@ -24,6 +24,7 @@ type Timestamper func(t time.Time) string
 
 // Logging plumbing:
 //
+// (optionally) RegexpMatchingWriter ->
 // ThrottledLogger.Logger -> ThrottledLogger.Write ->
 // ThrottledLogger.buf -> ThrottledLogger.flusher ->
 // ArvLogWriter.Write -> CollectionFileWriter.Write | Api.Create
@@ -189,6 +190,35 @@ func NewThrottledLogger(writer io.WriteCloser) *ThrottledLogger {
 	return tl
 }
 
+// regexpMatchingWriter compares every line and sends it to the underlying
+// Writer. Function Notify() will be triggered if any regexp matches.
+type regexpMatchingWriter struct {
+	io.WriteCloser
+	Notify    func(regexp string, line string)
+	Regexps   []string
+	setupOnce sync.Once
+	matchers  []*regexp.Regexp
+}
+
+func (w *regexpMatchingWriter) Write(p []byte) (n int, err error) {
+	// set up matchers from Regexps on first Write()
+	w.setupOnce.Do(func() {
+		w.matchers = make([]*regexp.Regexp, len(w.Regexps))
+		for i, rstring := range w.Regexps {
+			w.matchers[i] = regexp.MustCompile(rstring)
+		}
+	})
+
+	// If any regexp matches then call w.Notify()...
+	for _, matcher := range w.matchers {
+		if matcher.Match(p) {
+			w.Notify(matcher.String(), string(p))
+		}
+	}
+
+	return w.WriteCloser.Write(p)
+}
+
 // Log throttling rate limiting config parameters
 var crunchLimitLogBytesPerJob int64 = 67108864
 var crunchLogThrottleBytes int64 = 65536

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list