From: radhika Date: Mon, 24 Apr 2017 21:21:52 +0000 (-0400) Subject: 8019: more testing X-Git-Tag: 1.1.0~267^2~12 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/9dabca0eedbc9f842d542fea3463a441140d590c?ds=sidebyside 8019: more testing --- diff --git a/services/crunch-run/logging.go b/services/crunch-run/logging.go index 00cc06a04c..da6a9ff666 100644 --- a/services/crunch-run/logging.go +++ b/services/crunch-run/logging.go @@ -285,9 +285,8 @@ func (arvlog *ArvLogWriter) rateLimit(line []byte) (bool, []byte, error) { lineSize := int64(len(line)) partialLine := false skipCounts := false - if arvlog.logThrottleIsOpen { - matches := lineRegexp.FindStringSubmatch(string(line)) + if arvlog.logThrottleIsOpen { crunchLogPartialLineThrottlePeriod, err := arvlog.ArvClient.Discovery("crunchLogPartialLineThrottlePeriod") crunchLimitLogBytesPerJob, err := arvlog.ArvClient.Discovery("crunchLimitLogBytesPerJob") crunchLogThrottleBytes, err := arvlog.ArvClient.Discovery("crunchLogThrottleBytes") @@ -297,6 +296,8 @@ func (arvlog *ArvLogWriter) rateLimit(line []byte) (bool, []byte, error) { return false, []byte(""), err } + matches := lineRegexp.FindStringSubmatch(string(line)) + if len(matches) == 2 && strings.HasPrefix(matches[1], "[...]") && strings.HasSuffix(matches[1], "[...]") { partialLine = true diff --git a/services/crunch-run/logging_test.go b/services/crunch-run/logging_test.go index 2ea9a31367..477ed3949b 100644 --- a/services/crunch-run/logging_test.go +++ b/services/crunch-run/logging_test.go @@ -112,39 +112,21 @@ func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) { } func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytes(c *C) { - discoveryMap["crunchLogThrottleBytes"] = float64(50) - defer func() { - discoveryMap["crunchLogThrottleBytes"] = float64(65536) - }() - - api := &ArvTestClient{} - kc := &KeepTestClient{} - cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") - cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp - - cr.CrunchLog.Print("Hello world!") - cr.CrunchLog.Print("Goodbye") - cr.CrunchLog.Close() - - c.Check(api.Calls, Equals, 1) - - mt, err := cr.LogCollection.ManifestText() - c.Check(err, IsNil) - c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n") + testWriteLogsWithRateLimit(c, "crunchLogThrottleBytes", 50, 65536, "Exceeded rate 50 bytes per 60 seconds") +} - logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" + - "2015-12-29T15:51:45.000000002Z Goodbye\n" +func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleLines(c *C) { + testWriteLogsWithRateLimit(c, "crunchLogThrottleLines", 1, 1024, "Exceeded rate 1 lines per 60 seconds") +} - 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, "Exceeded rate 50 bytes per 60 seconds")) - c.Check(string(kc.Content), Equals, logtext) +func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytesPerEvent(c *C) { + testWriteLogsWithRateLimit(c, "crunchLimitLogBytesPerJob", 50, 67108864, "Exceeded log limit 50 bytes (crunch_limit_log_bytes_per_job)") } -func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleLines(c *C) { - discoveryMap["crunchLogThrottleLines"] = float64(1) +func testWriteLogsWithRateLimit(c *C, throttleParam string, throttleValue int, throttleDefault int, expected string) { + discoveryMap[throttleParam] = float64(throttleValue) defer func() { - discoveryMap["crunchLogThrottleLines"] = float64(1024) + discoveryMap[throttleParam] = float64(throttleDefault) }() api := &ArvTestClient{} @@ -167,6 +149,6 @@ func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleLines(c *C) { 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, "Exceeded rate 1 lines per 60 seconds")) + c.Check(true, Equals, strings.Contains(stderrLog, expected)) c.Check(string(kc.Content), Equals, logtext) }