Skip to content

Commit 49f8e4e

Browse files
committed
Address feedback (backoff on http 429)
1 parent 9deaa96 commit 49f8e4e

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

fluent-plugin-datadog.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require "fluent/plugin/version.rb"
1111

1212
Gem::Specification.new do |spec|
1313
spec.name = "fluent-plugin-datadog"
14-
spec.version = Datadog::FluentPlugin::GEM_VERSION
14+
spec.version = DatadogFluentPlugin::VERSION
1515
spec.authors = ["Datadog Solutions Team"]
1616
spec.email = ["support@datadoghq.com"]
1717
spec.summary = "Datadog output plugin for Fluent event collector"

lib/fluent/plugin/out_datadog.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_pr
325325
unless force_v1_routes
326326
@client.override_headers["DD-API-KEY"] = api_key
327327
@client.override_headers["DD-EVP-ORIGIN"] = "fluent"
328-
@client.override_headers["DD-EVP-ORIGIN-VERSION"] = Datadog::FluentPlugin::GEM_VERSION
328+
@client.override_headers["DD-EVP-ORIGIN-VERSION"] = DatadogFluentPlugin::VERSION
329329
end
330330
@client.override_headers["Content-Type"] = "application/json"
331331
if use_compression
@@ -342,7 +342,8 @@ def send(payload)
342342
request.body = payload
343343
response = @client.request @uri, request
344344
res_code = response.code.to_i
345-
if res_code >= 500
345+
# on a backend error or on an http 429, retry with backoff
346+
if res_code >= 500 || res_code == 429
346347
raise RetryableError.new "Unable to send payload: #{res_code} #{response.message}"
347348
end
348349
if res_code >= 400

lib/fluent/plugin/version.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
module Datadog
4-
class FluentPlugin
5-
GEM_VERSION = '0.14.0'
6-
end
3+
module DatadogFluentPlugin
4+
VERSION = '0.14.0'
75
end

test/plugin/test_out_datadog.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ def create_valid_subject
223223
end
224224
end
225225

226+
# note that in theory, v1 routes should not return a 429 but still
227+
# we added this mechanism for v1 routes while implementing v2 ones
228+
test "should retry when server is returning 429 (v1 routes)" do
229+
api_key = 'XXX'
230+
stub_dd_request_with_return_code(api_key, 429)
231+
payload = '{}'
232+
client = Fluent::DatadogOutput::DatadogHTTPClient.new Logger.new(STDOUT), false, false, "datadog.com", 443, 80, nil, false, api_key, true
233+
assert_raise(Fluent::DatadogOutput::RetryableError) do
234+
client.send(payload)
235+
end
236+
end
237+
226238
test "should not retry when server is returning 4XX (v1 routes)" do
227239
api_key = 'XXX'
228240
stub_dd_request_with_return_code(api_key, 400)
@@ -246,6 +258,16 @@ def create_valid_subject
246258
end
247259
end
248260

261+
test "should retry when server is returning 429 (v2 routes)" do
262+
api_key = 'XXX'
263+
stub_dd_request_with_return_code(api_key, 429, true)
264+
payload = '{}'
265+
client = Fluent::DatadogOutput::DatadogHTTPClient.new Logger.new(STDOUT), false, false, "datadog.com", 443, 80, nil, false, api_key
266+
assert_raise(Fluent::DatadogOutput::RetryableError) do
267+
client.send(payload)
268+
end
269+
end
270+
249271
test "should not retry when server is returning 4XX (v2 routes)" do
250272
api_key = 'XXX'
251273
stub_dd_request_with_return_code(api_key, 400, true)
@@ -297,7 +319,7 @@ def stub_dd_request_v2_routes(api_key)
297319
'Content-Type'=>'application/json',
298320
'Dd-Api-Key'=> "#{api_key}",
299321
'Dd-Evp-Origin'=>'fluent',
300-
'Dd-Evp-Origin-Version'=> "#{Datadog::FluentPlugin::GEM_VERSION}",
322+
'Dd-Evp-Origin-Version'=> "#{DatadogFluentPlugin::VERSION}",
301323
'Keep-Alive'=>'30',
302324
'User-Agent'=>'Ruby'
303325
})

0 commit comments

Comments
 (0)