@@ -11,8 +11,8 @@ import (
11
11
12
12
logging "cloud.google.com/go/logging/apiv2"
13
13
"cloud.google.com/go/logging/apiv2/loggingpb"
14
+ "golang.org/x/time/rate"
14
15
"google.golang.org/genproto/googleapis/cloud/audit"
15
- "google.golang.org/grpc/codes"
16
16
"google.golang.org/grpc/status"
17
17
)
18
18
@@ -23,20 +23,23 @@ func Tail(ctx context.Context, projectID, clusterName string, cb func(*audit.Aud
23
23
}
24
24
defer client .Close ()
25
25
26
+ // Limiter used to throttle log tailing restarts
27
+ limiter := rate .NewLimiter (rate .Every (time .Second * 15 ), 3 )
28
+
26
29
for {
27
30
select {
28
31
case <- ctx .Done ():
29
32
return ctx .Err ()
30
33
default :
31
34
}
32
35
36
+ if err = limiter .Wait (ctx ); err != nil {
37
+ return fmt .Errorf ("limit wait failed: %w" , err )
38
+ }
39
+
33
40
if err = tailLogs (ctx , client , projectID , clusterName , cb ); err != nil {
34
- if grpcErr , ok := status .FromError (err ); ok && grpcErr .Code () == codes .OutOfRange {
35
- // Expected error case:
36
- // "rpc error: code = OutOfRange desc = Session has run for the maximum allowed duration of 1h. To
37
- // continue, start a new session with the same request"
38
- slog .Warn ("session expired, restarting" , slog .Any ("error" , err ))
39
- time .Sleep (time .Second * 5 )
41
+ if _ , ok := status .FromError (err ); ok {
42
+ slog .Warn ("gRPC request terminated, restarting" , slog .Any ("error" , err ))
40
43
continue
41
44
}
42
45
return fmt .Errorf ("log tailing failed: %w" , err )
0 commit comments