From 89fa7e957f732c03bda1ef41d566773bccdf4d45 Mon Sep 17 00:00:00 2001 From: Sriram Date: Thu, 2 Jun 2022 18:11:15 -0700 Subject: [PATCH] fix: handle error and return gracefully during failures The plugin during start, tries to fetch bucket info and also ensure that the bucket exists. in this process, if the output configs don't have sufficient permissions or privileges to execute any of the gcp apis, it errors with forbidden and fails. this is problematic in the logging operator context esp., when we allow different teams to setup their log flows with their output sinks and only one of those sinks have an issue. we would expect the rest of the logging ecosystem to work well, while the specific flow fails gracefully without bombing the entire setup --- lib/fluent/plugin/out_gcs.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/fluent/plugin/out_gcs.rb b/lib/fluent/plugin/out_gcs.rb index f41547b..6de46e2 100644 --- a/lib/fluent/plugin/out_gcs.rb +++ b/lib/fluent/plugin/out_gcs.rb @@ -102,16 +102,21 @@ def configure(conf) end def start - @gcs = Google::Cloud::Storage.new( - project: @project, - keyfile: @credentials, - retries: @client_retries, - timeout: @client_timeout - ) - @gcs_bucket = @gcs.bucket(@bucket) - - ensure_bucket - super + begin + @gcs = Google::Cloud::Storage.new( + project: @project, + keyfile: @credentials, + retries: @client_retries, + timeout: @client_timeout + ) + @gcs_bucket = @gcs.bucket(@bucket) + + ensure_bucket + super + rescue => e + log.warn "GCS output plugin initialization error: #{e.message}" + log.warn "#{e.full_message()}" + end end def format(tag, time, record)