Skip to content

Commit

Permalink
Retry ssl connection errors (#27)
Browse files Browse the repository at this point in the history
* Retry ssl connection errors and do not raise unknown errors

* Adapt test

* Review comments and changelog

* Bump minor version

* Re-raise unknown errors

* Document single concurrency

* Format changelog
  • Loading branch information
dyladan authored Jun 30, 2023
1 parent bfec8be commit e772a59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## 0.4.0

- Add` OpenSSL::SSL::SSLError` to the list of retried exception
- Change concurrency mode to `:single`

## 0.3.2

- Add Net::OpenTimeout to the list of retried exceptions
- Add `Net::OpenTimeout` to the list of retried exceptions

## 0.3.1

Expand Down
8 changes: 6 additions & 2 deletions lib/logstash/outputs/dynatrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
require 'logstash/namespace'
require 'logstash/outputs/base'
require 'logstash/json'
require 'openssl'

MAX_RETRIES = 5
PLUGIN_VERSION = '0.3.2'
PLUGIN_VERSION = '0.4.0'

module LogStash
module Outputs
Expand All @@ -30,6 +31,8 @@ class RetryableError < StandardError;
class Dynatrace < LogStash::Outputs::Base
config_name 'dynatrace'

concurrency :single

# The full URL of the Dynatrace log ingestion endpoint:
# - on SaaS: https://{your-environment-id}.live.dynatrace.com/api/v2/logs/ingest
# - on Managed: https://{your-domain}/e/{your-environment-id}/api/v2/logs/ingest
Expand Down Expand Up @@ -93,9 +96,10 @@ def multi_receive(events)

raise RetryableError.new "code #{response.code}" if retryable(response)

rescue Net::OpenTimeout, Net::HTTPBadResponse, RetryableError => e
rescue Net::OpenTimeout, Net::HTTPBadResponse, OpenSSL::SSL::SSLError, RetryableError => e
# Net::OpenTimeout indicates a connection could not be established within the timeout period
# Net::HTTPBadResponse indicates a protocol error
# OpenSSL::SSL::SSLErrorWaitReadable indicates an error establishing the ssl connection
if retries < MAX_RETRIES
sleep_seconds = 2 ** retries
@logger.warn("Failed to contact dynatrace: #{e.message}. Trying again after #{sleep_seconds} seconds.")
Expand Down
2 changes: 1 addition & 1 deletion version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

module DynatraceConstants
# Also required to change the version in lib/logstash/outputs/dynatrace.rb
VERSION = '0.3.2'
VERSION = '0.4.0'
end

0 comments on commit e772a59

Please sign in to comment.