From 4c1a2e7594b47ce4e48152e82c3d908ae0536486 Mon Sep 17 00:00:00 2001 From: Yen-Cheng Chou Date: Mon, 30 Sep 2019 00:15:49 -0400 Subject: [PATCH] Mark more grpc error codes as recoverable errors. - When CANCELED is returned, the operation was cancelled. Mark the error as recoverable and allows the Client to resend the samples. - When DEADLINE_EXCEEDED is returned, the operation might not be completed. Mark the error as recoverable and allows the Client to resend the samples. - When PERMISSION_DENIED or UNAUTHENTICATED errors are returned, it's the errors are not caused by the samples - so we mark the errors as recoverable errors and allows the Client to resend the samples until the permission and authentication are fixed. --- stackdriver/client.go | 4 +++- stackdriver/client_test.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/stackdriver/client.go b/stackdriver/client.go index 8a9a9e02..2e46668b 100644 --- a/stackdriver/client.go +++ b/stackdriver/client.go @@ -180,7 +180,9 @@ func (c *Client) Store(req *monitoring.CreateTimeSeriesRequest) error { return } switch status.Code() { - case codes.DeadlineExceeded, codes.Unavailable: + case codes.Canceled, codes.DeadlineExceeded, + codes.PermissionDenied, + codes.Unauthenticated, codes.Unavailable: errors <- recoverableError{err} default: errors <- err diff --git a/stackdriver/client_test.go b/stackdriver/client_test.go index 297e464a..ec824702 100644 --- a/stackdriver/client_test.go +++ b/stackdriver/client_test.go @@ -82,13 +82,25 @@ func TestStoreErrorHandling(t *testing.T) { recoverable: false, }, { - status: status.New(codes.Unavailable, longErrMessage), + status: status.New(codes.Canceled, longErrMessage), recoverable: true, }, { status: status.New(codes.DeadlineExceeded, longErrMessage), recoverable: true, }, + { + status: status.New(codes.PermissionDenied, longErrMessage), + recoverable: true, + }, + { + status: status.New(codes.Unauthenticated, longErrMessage), + recoverable: true, + }, + { + status: status.New(codes.Unavailable, longErrMessage), + recoverable: true, + }, } for i, test := range tests {