X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8da2f73faeeecd81f52949451fe07a674ba47df6..1488e37321751c94c8da026b860c0ced2da9088e:/lib/crunchrun/logging_test.go diff --git a/lib/crunchrun/logging_test.go b/lib/crunchrun/logging_test.go index e3fa3af0bb..42f165fd75 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 @@ -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 @@ -219,3 +226,34 @@ func (s *LoggingTestSuite) testWriteLogsWithRateLimit(c *C, throttleParam string c.Check(true, Equals, strings.Contains(stderrLog, expected)) c.Check(string(kc.Content), Equals, logtext) } + +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 }