@@ -120,8 +120,24 @@ func TestParseBackoffDuration(t *testing.T) {
120120 wantErr bool
121121 }{
122122 {
123- desc : "a valid backoff duration is parsed correctly" ,
124- line : "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 32m0s" ,
123+ desc : "a valid backoff duration is parsed correctly when at the end of the message" ,
124+ line : "Fri May 15 22:05:01 UTC 2020: benchmark 0: action throttled, backoff for 32m0s" ,
125+ wantBackoffDur : 32 * time .Minute ,
126+ },
127+ {
128+ desc : "a valid backoff duration is parsed correctly when at the end of a message ending with a period" ,
129+ line : "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 32m0s." ,
130+ wantBackoffDur : 32 * time .Minute ,
131+ },
132+ {
133+ desc : "a valid backoff duration in a structured log statement is parsed correctly" ,
134+ line : `Mon Dec 20 20:21:40 UTC 2021: benchmark 39: {"timestamp":"2021-12-20T20:21:39.973Z","severity":"DEBUG","logging.googleapis.com/insertId":"..........K231soqV4EIcG8w42yR2.3","message":"Must wait 35m to create profile: Error: generic::aborted: action throttled, backoff for 35m0s","logName":"projects/{{projectId}}/logs/%40google-cloud%2Fprofiler","resource":{"type":"gae_app","labels":{"module_id":"profiler-backoff-test-node12-2021-12-20-12-18-47-077307-0800","zone":"us-east4-b"}}}` ,
135+ wantBackoffDur : 35 * time .Minute ,
136+ },
137+
138+ {
139+ desc : "a valid backoff duration is parsed correctly when in the middle of the message" ,
140+ line : "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 32m0s ... more information" ,
125141 wantBackoffDur : 32 * time .Minute ,
126142 },
127143 {
@@ -139,6 +155,11 @@ func TestParseBackoffDuration(t *testing.T) {
139155 line : "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 1h1m1s1ms1us" ,
140156 wantBackoffDur : time .Hour + time .Minute + time .Second + time .Millisecond + time .Microsecond ,
141157 },
158+ {
159+ desc : "a backoff duration at the start of the message is parsed correctly" ,
160+ line : "1h1m1s1ms" ,
161+ wantBackoffDur : time .Hour + time .Minute + time .Second + time .Millisecond ,
162+ },
142163 } {
143164 t .Run (tc .desc , func (t * testing.T ) {
144165 backoffDur , err := parseBackoffDuration (tc .line )
0 commit comments