logstash-output-azure_service_bus 0.2.3 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d25bb98310be24692a94d2fcd87e0e5845957f42c16b923b2e9fcf381275bb1b
4
- data.tar.gz: 514c75f9918c1e17d659d6781ed2a50b2caf28ed9a8f96a0c326d42894794116
3
+ metadata.gz: '083f7b36cee46fdb059036aaf5d1be5147d9847698668ccd47d2d55e2178726b'
4
+ data.tar.gz: 83a758c5fec612555dcd2bbd019ce6cc8fc6a387d0d0203b1f5af8bc8316ffd8
5
5
  SHA512:
6
- metadata.gz: 3d547ae59c36e62cf3da4b1919b5a5a6932fccd5132775b6762d02954533b128592b328be7376b78ba64b2aef0dd5039ab82b296f5a2986c0b3afec9494eb00b
7
- data.tar.gz: 436eb44572d7ed0d5b4127a142c810f5c5307f33f47a0022c448b578d64e4f0a435e5954f2f0ee3363e9a0777a7ab587dac9e0d975e04cfe3a7f7f14fb436613
6
+ metadata.gz: 0be573d501e76e02a9ccc60fdbdaf79cde4550e9e0930ba6bfed8ace0721f9a659c176720ecacc6774bb27c80ae2329f1adadc10af2e476bb747f8b11f47bb64
7
+ data.tar.gz: 5de0f339d87b98804a369638051134c854d4860f9eb9d87d8a616ada52609cadad91edd89012562c9f64dfe111a3aa839214f5ecb575a63100ca611d05d1779e
data/README.md CHANGED
@@ -43,5 +43,5 @@ output {
43
43
  }
44
44
  ```
45
45
 
46
- ## Service Bus Configuration
47
- This plugin will retry sending messages if the Service Bus connection times out or returns a bad response. To avoid idempotence issues, you should enable duplicate detection on the destination queue or topic.
46
+ ## Retry
47
+ This plugin will retry sending messages _indefinitely_ if Service Bus times out or returns a [documented bad response](https://docs.microsoft.com/en-us/rest/api/servicebus/send-message-batch#response-codes) (except 400). To avoid idempotence issues, you should enable duplicate detection on the destination queue or topic.
@@ -13,30 +13,33 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
13
13
  config :messageid_field, :validate => :string
14
14
 
15
15
  def register
16
- retry_options = {
17
- max: 5,
16
+ service_bus_retry_options = {
17
+ max: Float::MAX, # Essentially retries indefinitely
18
18
  interval: 1,
19
19
  interval_randomness: 0.5,
20
20
  backoff_factor: 2,
21
- retry_statuses: [429, 500],
22
- exceptions: [Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::RetriableResponse],
23
- methods: %i[get post],
24
- retry_block: ->(env, _options, retries, exception) { @logger.warn("Problem (#{exception}) for #{env.method.upcase} #{env.url} - #{retries + 1} retry(s) left") }
21
+ exceptions: [Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::RetriableResponse, Errno::ECONNRESET],
22
+ methods: [], # Empty -> all methods
23
+ retry_statuses: [401, 403, 404, 410, 429, 500], # https://docs.microsoft.com/en-us/rest/api/servicebus/send-message-batch#response-codes
24
+ retry_block: lambda do |env, _options, _retries, exception|
25
+ if env.status.nil?
26
+ @logger.warn("Problem (#{exception}) for #{env.method.upcase} #{env.url}")
27
+ else
28
+ @logger.warn("Problem (HTTP #{env.status}) for #{env.method.upcase} #{env.url}")
29
+ end
30
+ end,
31
+ retry_if: lambda do |env, _exc|
32
+ refresh_access_token if env.status == 401
33
+ true # Always retry
34
+ end
25
35
  }
26
- @token_conn = Faraday.new(
27
- url: 'http://169.254.169.254/metadata/identity/oauth2/token',
28
- params: { 'api-version' => '2018-02-01', 'resource' => 'https://servicebus.azure.net/' },
29
- headers: { 'Metadata' => 'true' },
30
- request: { timeout: 4 }
31
- ) do |f|
32
- f.request :retry, retry_options
33
- end
34
36
  @service_bus_conn = Faraday.new(
35
37
  url: "https://#{@service_bus_namespace}.servicebus.windows.net/#{@service_bus_entity}/",
36
38
  request: { timeout: 10 }
37
- ) do |f|
38
- f.request :retry, retry_options
39
+ ) do |conn|
40
+ conn.request :retry, service_bus_retry_options
39
41
  end
42
+ @access_token = ''
40
43
  refresh_access_token
41
44
  end
42
45
 
@@ -59,37 +62,37 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
59
62
  end
60
63
 
61
64
  def post_messages(messages)
62
- refresh_access_token if access_token_needs_refresh?
63
- begin
64
- response = @service_bus_conn.post('messages') do |req|
65
- req.body = JSON.generate(messages)
66
- req.headers = { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.microsoft.servicebus.json' }
67
- end
68
- rescue StandardError => e
69
- @logger.error("Error (#{e}) while sending message to Service Bus")
65
+ response = @service_bus_conn.post('messages') do |req|
66
+ req.body = JSON.generate(messages)
67
+ req.headers = { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.microsoft.servicebus.json' }
70
68
  end
71
- if !response.nil?
72
- @logger.error("Error while sending message to Service Bus: HTTP #{response.status}") if response.status != 201
73
- @logger.debug("Sent #{messages.length} message(s) to Service Bus") if response.status == 200
69
+ rescue StandardError => e
70
+ # Hopefully we never make it here and "throw away" messages since we have an agressive retry strategy.
71
+ @logger.error("Error (#{e}) while sending message to Service Bus")
72
+ else
73
+ if response.status == 200
74
+ @logger.debug("Sent #{messages.length} message(s) to Service Bus")
75
+ else
76
+ @logger.error("Error while sending message to Service Bus: HTTP #{response.status}")
74
77
  end
75
78
  end
76
79
 
77
- def access_token_needs_refresh?
78
- Time.now.to_i - 60 > @access_token_expiration # Refresh the access token if it will expire within 60 seconds.
79
- end
80
-
81
80
  def refresh_access_token
82
81
  @logger.info('Refreshing Azure access token')
83
82
  begin
84
- response = @token_conn.get
85
- rescue Faraday::ConnectionFailed => e
86
- @logger.error('Unable to connect to the Azure Instance Metadata Service')
87
- raise e
83
+ response = Faraday.get('http://169.254.169.254/metadata/identity/oauth2/token', { 'api-version' => '2018-02-01', 'resource' => 'https://servicebus.azure.net/' }) do |req|
84
+ req.headers = { 'Metadata' => 'true' }
85
+ req.options.timeout = 4
86
+ end
87
+ rescue StandardError => e # We just catch everything and move on since @service_bus_conn will handle retries.
88
+ @logger.error("Error while fetching access token: #{e}")
89
+ else
90
+ if response.status == 200
91
+ data = JSON.parse(response.body)
92
+ @access_token = data['access_token']
93
+ else
94
+ @logger.error("HTTP error when fetching access token: #{response.body}")
95
+ end
88
96
  end
89
- raise "Unable to fetch token: #{response.body}" if response.status != 200
90
-
91
- data = JSON.parse(response.body)
92
- @access_token = data['access_token']
93
- @access_token_expiration = data['expires_on'].to_i
94
97
  end
95
98
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-azure_service_bus'
3
- s.version = '0.2.3'
3
+ s.version = '0.3.2'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Send Logstash messages to Azure Service Bus.'
6
6
  s.homepage = 'https://github.com/gharryg/logstash-output-azure_service_bus'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-azure_service_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harrison Golden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-13 00:00:00.000000000 Z
11
+ date: 2022-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement