5 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
12 type LoggingTestSuite struct{}
14 type TestTimestamper struct {
18 func (this *TestTimestamper) Timestamp(t time.Time) string {
20 t, err := time.ParseInLocation(time.RFC3339Nano, fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count), t.Location())
24 return RFC3339Timestamp(t)
27 // Gocheck boilerplate
28 var _ = Suite(&LoggingTestSuite{})
30 func (s *LoggingTestSuite) TestWriteLogs(c *C) {
31 api := &ArvTestClient{}
32 kc := &KeepTestClient{}
33 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
34 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
36 cr.CrunchLog.Print("Hello world!")
37 cr.CrunchLog.Print("Goodbye")
40 c.Check(api.Calls, Equals, 1)
42 mt, err := cr.LogCollection.ManifestText()
44 c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n")
46 logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
47 "2015-12-29T15:51:45.000000002Z Goodbye\n"
49 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
50 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext)
51 c.Check(string(kc.Content), Equals, logtext)
54 func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) {
58 api := &ArvTestClient{}
59 kc := &KeepTestClient{}
60 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
61 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
62 cr.CrunchLog.Immediate = nil
64 for i := 0; i < 2000000; i++ {
65 cr.CrunchLog.Printf("Hello %d", i)
67 cr.CrunchLog.Print("Goodbye")
70 c.Check(api.Calls > 1, Equals, true)
71 c.Check(api.Calls < 2000000, Equals, true)
73 mt, err := cr.LogCollection.ManifestText()
75 c.Check(mt, Equals, ". 9c2c05d1fae6aaa8af85113ba725716d+67108864 80b821383a07266c2a66a4566835e26e+21780065 0:88888929:crunch-run.txt\n")
78 func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
79 api := &ArvTestClient{}
80 kc := &KeepTestClient{}
81 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
82 ts := &TestTimestamper{}
83 cr.CrunchLog.Timestamper = ts.Timestamp
84 stdout := NewThrottledLogger(cr.NewLogWriter("stdout"))
85 stdout.Timestamper = ts.Timestamp
87 cr.CrunchLog.Print("Hello world!")
88 stdout.Print("Doing stuff")
89 cr.CrunchLog.Print("Goodbye")
94 logText := make(map[string]string)
95 for _, content := range api.Content {
96 log := content["log"].(arvadosclient.Dict)
97 logText[log["event_type"].(string)] += log["properties"].(map[string]string)["text"]
100 c.Check(logText["crunch-run"], Equals, `2015-12-29T15:51:45.000000001Z Hello world!
101 2015-12-29T15:51:45.000000003Z Goodbye
103 c.Check(logText["stdout"], Equals, `2015-12-29T15:51:45.000000002Z Doing stuff
104 2015-12-29T15:51:45.000000004Z Blurb
107 mt, err := cr.LogCollection.ManifestText()
109 c.Check(mt, Equals, ""+
110 ". 408672f5b5325f7d20edfbf899faee42+83 0:83:crunch-run.txt\n"+
111 ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")
114 func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytes(c *C) {
115 testWriteLogsWithRateLimit(c, "crunchLogThrottleBytes", 50, 65536, "Exceeded rate 50 bytes per 60 seconds")
118 func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleLines(c *C) {
119 testWriteLogsWithRateLimit(c, "crunchLogThrottleLines", 1, 1024, "Exceeded rate 1 lines per 60 seconds")
122 func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytesPerEvent(c *C) {
123 testWriteLogsWithRateLimit(c, "crunchLimitLogBytesPerJob", 50, 67108864, "Exceeded log limit 50 bytes (crunch_limit_log_bytes_per_job)")
126 func testWriteLogsWithRateLimit(c *C, throttleParam string, throttleValue int, throttleDefault int, expected string) {
127 discoveryMap[throttleParam] = float64(throttleValue)
129 discoveryMap[throttleParam] = float64(throttleDefault)
132 api := &ArvTestClient{}
133 kc := &KeepTestClient{}
134 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
135 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
137 cr.CrunchLog.Print("Hello world!")
138 cr.CrunchLog.Print("Goodbye")
141 c.Check(api.Calls, Equals, 1)
143 mt, err := cr.LogCollection.ManifestText()
145 c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n")
147 logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
148 "2015-12-29T15:51:45.000000002Z Goodbye\n"
150 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
151 stderrLog := api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]
152 c.Check(true, Equals, strings.Contains(stderrLog, expected))
153 c.Check(string(kc.Content), Equals, logtext)