Skip to content

Commit 3a9f935

Browse files
committed
Support sending logs to Datadog v2 endpoints.
This PR is also adding a public variable containing current Gem version.
1 parent b6f8bf7 commit 3a9f935

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ foo/
4040
*.iml
4141
.idea/
4242

43-
fluent/
4443
Gemfile.lock

fluent-plugin-datadog.gemspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
lib = File.expand_path('../lib', __FILE__)
88
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
99

10+
require "fluent/plugin/version.rb"
11+
1012
Gem::Specification.new do |spec|
1113
spec.name = "fluent-plugin-datadog"
12-
spec.version = "0.13.0"
14+
spec.version = Datadog::FluentPlugin::GEM_VERSION
1315
spec.authors = ["Datadog Solutions Team"]
1416
spec.email = ["support@datadoghq.com"]
1517
spec.summary = "Datadog output plugin for Fluent event collector"
1618
spec.homepage = "http://datadoghq.com"
1719
spec.license = "Apache-2.0"
1820

19-
spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-datadog.gemspec", "lib/fluent/plugin/out_datadog.rb"]
21+
spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-datadog.gemspec", "lib/fluent/plugin/version.rb", "lib/fluent/plugin/out_datadog.rb"]
2022
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
2123
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
2224
spec.require_paths = ["lib"]

lib/fluent/plugin/out_datadog.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
require "zlib"
1010
require "fluent/plugin/output"
1111

12+
require_relative "version"
13+
1214
class Fluent::DatadogOutput < Fluent::Plugin::Output
1315
class RetryableError < StandardError;
1416
end
@@ -50,6 +52,7 @@ class RetryableError < StandardError;
5052
config_param :compression_level, :integer, :default => 6
5153
config_param :no_ssl_validation, :bool, :default => false
5254
config_param :http_proxy, :string, :default => nil
55+
config_param :force_v1_routes, :bool, :default => false
5356

5457
# Format settings
5558
config_param :use_json, :bool, :default => true
@@ -89,7 +92,7 @@ def formatted_to_msgpack_binary?
8992

9093
def start
9194
super
92-
@client = new_client(log, @api_key, @use_http, @use_ssl, @no_ssl_validation, @host, @ssl_port, @port, @http_proxy, @use_compression)
95+
@client = new_client(log, @api_key, @use_http, @use_ssl, @no_ssl_validation, @host, @ssl_port, @port, @http_proxy, @use_compression, @force_v1_routes)
9396
end
9497

9598
def shutdown
@@ -261,9 +264,9 @@ def gzip_compress(payload, compression_level)
261264
end
262265

263266
# Build a new transport client
264-
def new_client(logger, api_key, use_http, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression)
267+
def new_client(logger, api_key, use_http, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, force_v1_routes)
265268
if use_http
266-
DatadogHTTPClient.new logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key
269+
DatadogHTTPClient.new logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key, force_v1_routes
267270
else
268271
DatadogTCPClient.new logger, use_ssl, no_ssl_validation, host, ssl_port, port
269272
end
@@ -301,20 +304,29 @@ class DatadogHTTPClient < DatadogClient
301304
require 'net/http'
302305
require 'net/http/persistent'
303306

304-
def initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key)
307+
def initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key, force_v1_routes = false)
305308
@logger = logger
306309
protocol = use_ssl ? "https" : "http"
307310
port = use_ssl ? ssl_port : port
308-
@uri = URI("#{protocol}://#{host}:#{port.to_s}/v1/input/#{api_key}")
311+
if force_v1_routes
312+
@uri = URI("#{protocol}://#{host}:#{port.to_s}/v1/input/#{api_key}")
313+
else
314+
@uri = URI("#{protocol}://#{host}:#{port.to_s}/api/v2/logs")
315+
end
309316
proxy_uri = :ENV
310317
if http_proxy
311318
proxy_uri = URI.parse(http_proxy)
312319
elsif ENV['HTTP_PROXY'] || ENV['http_proxy']
313320
logger.info("Using HTTP proxy defined in `HTTP_PROXY`/`http_proxy` env vars")
314321
end
315-
logger.info("Starting HTTP connection to #{protocol}://#{host}:#{port.to_s} with compression " + (use_compression ? "enabled" : "disabled"))
322+
logger.info("Starting HTTP connection to #{protocol}://#{host}:#{port.to_s} with compression " + (use_compression ? "enabled" : "disabled") + (force_v1_routes ? " using v1 routes" : " using v2 routes"))
316323
@client = Net::HTTP::Persistent.new name: "fluent-plugin-datadog-logcollector", proxy: proxy_uri
317324
@client.verify_mode = OpenSSL::SSL::VERIFY_NONE if no_ssl_validation
325+
unless force_v1_routes
326+
@client.override_headers["DD-API-KEY"] = api_key
327+
@client.override_headers["DD-EVP-ORIGIN"] = "fluent"
328+
@client.override_headers["DD-EVP-ORIGIN-VERSION"] = Datadog::FluentPlugin::GEM_VERSION
329+
end
318330
@client.override_headers["Content-Type"] = "application/json"
319331
if use_compression
320332
@client.override_headers["Content-Encoding"] = "gzip"

lib/fluent/plugin/version.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
module Datadog
4+
class FluentPlugin
5+
GEM_VERSION = '0.14.0'
6+
end
7+
end

0 commit comments

Comments
 (0)