Skip to content

Commit

Permalink
Merge pull request #142 from aYukiSekiguchi/prevent_refresh_from_stop…
Browse files Browse the repository at this point in the history
…ping_on_exception

Prevent AWS credentials refresh from stopping on exception
  • Loading branch information
cosmo0920 authored Oct 2, 2024
2 parents c840b29 + b877206 commit e180c21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fluent/plugin/out_opensearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ class << self

@credential_mutex.synchronize do
@_os = nil
@_aws_credentials = aws_credentials(@endpoint)
begin
@_aws_credentials = aws_credentials(@endpoint)
rescue => e
log.error("Failed to get new AWS credentials: #{e}")
end
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions test/plugin/test_out_opensearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3977,4 +3977,26 @@ def test_ignore_excetion_handles_appropriate_ones
end
}
end

def test_no_aws_credentials_refresh_exception
# See https://github.com/fluent/fluent-plugin-opensearch/issues/129
endpoint_config =
Fluent::Config::Element.new('endpoint', '', {
'url' => "https://search-opensearch.aws.example.com/",
'region' => "local",
'access_key_id' => 'YOUR_AWESOME_KEY',
'secret_access_key' => 'YOUR_AWESOME_SECRET',
'refresh_credentials_interval' => '0',
}, [])
config = Fluent::Config::Element.new('ROOT', '**', { '@type' => 'opensearch' },
[endpoint_config])
# aws_credentials will be called twice in
# OpenSearchOutput#configure call, and in the 2nd call was changed not
# to emit exception. (instead, logging error) so check the error logs
flexmock(Fluent::Plugin::OpenSearchOutput).new_instances.should_receive(:aws_credentials)
.and_return(true).and_raise(::RuntimeError.new("No valid AWS credentials found."))
d = driver(config)
d.run
assert { d.logs.any?(/\[error\]: Failed to get new AWS credentials: No valid AWS credentials found.\n/) }
end
end

0 comments on commit e180c21

Please sign in to comment.