X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/045e3127cb48845c7d988d01488c055f02ae2ec3..b1ffc878a5ea6ba083b8fbc8f20c15c7a6f1e1ec:/lib/crunchrun/logging_test.go diff --git a/lib/crunchrun/logging_test.go b/lib/crunchrun/logging_test.go index e3fa3af0bb..ee3320c7c3 100644 --- a/lib/crunchrun/logging_test.go +++ b/lib/crunchrun/logging_test.go @@ -5,7 +5,9 @@ package crunchrun import ( + "bytes" "fmt" + "io" "strings" "testing" "time" @@ -13,6 +15,7 @@ import ( "git.arvados.org/arvados.git/sdk/go/arvados" "git.arvados.org/arvados.git/sdk/go/arvadosclient" . "gopkg.in/check.v1" + check "gopkg.in/check.v1" ) type LoggingTestSuite struct { @@ -45,7 +48,7 @@ func (s *LoggingTestSuite) TestWriteLogs(c *C) { api := &ArvTestClient{} kc := &KeepTestClient{} defer kc.Close() - cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") + cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzzzzzzzzzzzz") c.Assert(err, IsNil) cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp @@ -64,7 +67,7 @@ func (s *LoggingTestSuite) TestWriteLogs(c *C) { c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run") c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext) - c.Check(string(kc.Content), Equals, logtext) + s.checkWroteBlock(c, kc, "74561df9ae65ee9f35d5661d42454264+83", logtext) } func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) { @@ -74,7 +77,7 @@ func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) { api := &ArvTestClient{} kc := &KeepTestClient{} defer kc.Close() - cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") + cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzzzzzzzzzzzz") c.Assert(err, IsNil) cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp cr.CrunchLog.Immediate = nil @@ -97,7 +100,7 @@ func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) { api := &ArvTestClient{} kc := &KeepTestClient{} defer kc.Close() - cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") + cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzzzzzzzzzzzz") c.Assert(err, IsNil) ts := &TestTimestamper{} cr.CrunchLog.Timestamper = ts.Timestamp @@ -146,7 +149,7 @@ func (s *LoggingTestSuite) TestLogUpdate(c *C) { api := &ArvTestClient{} kc := &KeepTestClient{} defer kc.Close() - cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") + cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzzzzzzzzzzzz") c.Assert(err, IsNil) ts := &TestTimestamper{} cr.CrunchLog.Timestamper = ts.Timestamp @@ -188,6 +191,10 @@ func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytesPerEvent(c *C) s.testWriteLogsWithRateLimit(c, "crunchLimitLogBytesPerJob", 50, 67108864, "Exceeded log limit 50 bytes (crunch_limit_log_bytes_per_job)") } +func (s *LoggingTestSuite) TestWriteLogsWithZeroBytesPerJob(c *C) { + s.testWriteLogsWithRateLimit(c, "crunchLimitLogBytesPerJob", 0, 67108864, "Exceeded log limit 0 bytes (crunch_limit_log_bytes_per_job)") +} + func (s *LoggingTestSuite) testWriteLogsWithRateLimit(c *C, throttleParam string, throttleValue int, throttleDefault int, expected string) { discoveryMap[throttleParam] = float64(throttleValue) defer func() { @@ -197,7 +204,7 @@ func (s *LoggingTestSuite) testWriteLogsWithRateLimit(c *C, throttleParam string api := &ArvTestClient{} kc := &KeepTestClient{} defer kc.Close() - cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") + cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzzzzzzzzzzzz") c.Assert(err, IsNil) cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp @@ -217,5 +224,43 @@ func (s *LoggingTestSuite) testWriteLogsWithRateLimit(c *C, throttleParam string c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run") stderrLog := api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"] c.Check(true, Equals, strings.Contains(stderrLog, expected)) - c.Check(string(kc.Content), Equals, logtext) + s.checkWroteBlock(c, kc, "74561df9ae65ee9f35d5661d42454264+83", logtext) +} + +func (s *LoggingTestSuite) checkWroteBlock(c *C, kc *KeepTestClient, locator, expect string) { + buf := make([]byte, len([]byte(expect))+1) + n, err := kc.ReadAt(locator, buf, 0) + c.Check(err, IsNil) + c.Check(string(buf[:n]), Equals, expect) } + +type filterSuite struct{} + +var _ = Suite(&filterSuite{}) + +func (*filterSuite) TestFilterKeepstoreErrorsOnly(c *check.C) { + var buf bytes.Buffer + f := filterKeepstoreErrorsOnly{WriteCloser: nopCloser{&buf}} + for _, s := range []string{ + "not j", + "son\n" + `{"msg":"foo"}` + "\n{}\n" + `{"msg":"request"}` + "\n" + `{"msg":1234}` + "\n\n", + "\n[\n", + `{"msg":"response","respStatusCode":404,"foo": "bar"}` + "\n", + `{"msg":"response","respStatusCode":206}` + "\n", + } { + f.Write([]byte(s)) + } + c.Check(buf.String(), check.Equals, `not json +{"msg":"foo"} +{} +{"msg":1234} +[ +{"msg":"response","respStatusCode":404,"foo": "bar"} +`) +} + +type nopCloser struct { + io.Writer +} + +func (nopCloser) Close() error { return nil }