fluent-plugin-datadog-log 0.1.0.rc12 → 0.1.0.rc13

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
  SHA1:
3
- metadata.gz: f70d2fad0fa032bae35bc5169d83cd48387e2951
4
- data.tar.gz: eb00f95517613fdffff3dfa89112403acd30c023
3
+ metadata.gz: 3f7fcfdfa0667c08f2d6a9af5609357cc27c43a4
4
+ data.tar.gz: 1e782d80952ebc9b82339cf1b49b796ee20b407f
5
5
  SHA512:
6
- metadata.gz: 7a2f3238a1b1fc6f0c69d49da6c82013235d1414117cc7837a9bfdf112a48cb3cf6a57cc6f1f6b91fec8524c9a26aadabfc9fd569d0a282f4490d8fbfb5de690
7
- data.tar.gz: 3e900e5766e8b5419af768ec765fd2e075c78b69ac8946fb4f7c62d1c26848d55125160f4684bc5b23e42d9b078a84a3225eadc1e1d91feeb8c0e4a9ad19a753
6
+ metadata.gz: 76c99159bec7e09eab80546f6b1d67188cc4fc97e1f3c1471d4fcee1c2872e5a1100268ba739ba7e7a474a97a7b5e9e23814011db5fc4d6cdcf8674eee068abe
7
+ data.tar.gz: 18f6a73b24a7914147b900f94b33f7d60ba9f040d5c5c467d01ad67271d4c944c0c8ef3cbfa2ed0e3c4aded8ded4195ab197410e1193a6439aa5c6a9a82817db
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-datadog-log (0.1.0.rc12)
4
+ fluent-plugin-datadog-log (0.1.0.rc13)
5
5
  fluentd (~> 1.0.0)
6
6
  json (~> 1.8)
7
7
  net_tcp_client (~> 2.0.1)
@@ -8,7 +8,7 @@ eos
8
8
  gem.homepage = \
9
9
  'https://github.com/mumoshu/fluent-plugin-datadog-log'
10
10
  gem.license = 'Apache-2.0'
11
- gem.version = '0.1.0.rc12'
11
+ gem.version = '0.1.0.rc13'
12
12
  gem.authors = ['Yusuke KUOKA']
13
13
  gem.email = ['ykuoka@gmail.com']
14
14
  gem.required_ruby_version = Gem::Requirement.new('>= 2.0')
@@ -8,7 +8,7 @@ eos
8
8
  gem.homepage = \
9
9
  'https://github.com/mumoshu/fluent-plugin-datadog-log'
10
10
  gem.license = 'Apache-2.0'
11
- gem.version = '0.1.0.rc8'
11
+ gem.version = '0.1.0.rc12'
12
12
  gem.authors = ['Yusuke KUOKA']
13
13
  gem.email = ['ykuoka@gmail.com']
14
14
  gem.required_ruby_version = Gem::Requirement.new('>= 2.0')
@@ -17,12 +17,13 @@ eos
17
17
  gem.test_files = gem.files.grep(/^(test)/)
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_runtime_dependency 'fluentd', '~> 0.14'
20
+ gem.add_runtime_dependency 'fluentd', '~> 1.0.0'
21
21
  # gem.add_runtime_dependency 'datadog-log-api-client', '~> 0.1'
22
22
  gem.add_runtime_dependency 'json', '~> 1.8'
23
23
 
24
24
  gem.add_dependency 'net_tcp_client', '~> 2.0.1'
25
25
  gem.add_dependency 'prometheus-client', '~> 0.7.1'
26
+ gem.add_dependency 'semantic_logger', '~> 4.2.0'
26
27
 
27
28
  gem.add_development_dependency 'mocha', '~> 1.1'
28
29
  gem.add_development_dependency 'rake', '~> 10.3'
@@ -0,0 +1,153 @@
1
+ require 'openssl'
2
+
3
+ require 'semantic_logger'
4
+
5
+ SemanticLogger.default_level = :warn
6
+ SemanticLogger.add_appender(io: STDOUT, formatter: :json)
7
+
8
+ require 'net/tcp_client'
9
+ require 'socket'
10
+ require 'time'
11
+
12
+ # Datadog provides various helpers to programatically access Datadog services
13
+ module Datadog
14
+ # Log provides various helpers and classes to support programatically
15
+ # accessing Datadog Log Management
16
+ module Log
17
+ TRUNCATED_MSG = '...TRUNCATED...'
18
+
19
+ TRUNCATED_LEN = TRUNCATED_MSG.size
20
+
21
+ # MaxMessageLen is the maximum length for any message we send to the intake
22
+ # see https://github.com/DataDog/datadog-log-agent/blob/2394da8c79a6cadbcd1e98d6c89c437becec2732/pkg/config/constants.go#L9-L10
23
+ DD_MAX_MESSAGE_LEN = 1 * 1000 * 1000
24
+
25
+ MAX_MESSAGE_LEN = DD_MAX_MESSAGE_LEN - TRUNCATED_LEN
26
+
27
+ def truncate_message(msg)
28
+ if msg.size > DD_MAX_MESSAGE_LEN
29
+ msg.slice(0, MAX_MESSAGE_LEN) + TRUNCATED_MSG
30
+ else
31
+ msg
32
+ end
33
+ end
34
+
35
+ # Given a list of tags, build_tags_payload generates the bytes array
36
+ # that will be inserted into messages
37
+ # @see https://github.com/DataDog/datadog-log-agent/blob/2394da8c79a6cadbcd1e98d6c89c437becec2732/pkg/config/integration_config.go#L180
38
+ def build_tags_payload(config_tags:, source:, source_category:)
39
+ payload = ''
40
+
41
+ payload = "[dd ddsource=\"#{source}\"]" if !source.nil? && source != ''
42
+
43
+ if !source_category.nil? && source_category != ''
44
+ payload = "#{payload}[dd ddsourcecategory=\"#{source_category}\"]"
45
+ end
46
+
47
+ if !config_tags.nil? && config_tags != ''
48
+ config_tags = config_tags.join(',') if config_tags.is_a? ::Array
49
+ payload = "#{payload}[dd ddtags=\"#{config_tags}\"]"
50
+ end
51
+
52
+ payload
53
+ end
54
+
55
+ # https://github.com/DataDog/datadog-log-agent/blob/db13b53dfdd036d43acfb15089a43eb31548f09f/pkg/processor/processor.go#L65
56
+ def build_extra_content(timestamp:, hostname:, service:, tags_payload:)
57
+ "<46>0 #{timestamp} #{hostname} #{service} - - #{tags_payload}"
58
+ end
59
+
60
+ def build_api_key_str(api_key:, logset:)
61
+ if !logset.nil? && logset != ''
62
+ "#{api_key}/#{logset}"
63
+ else
64
+ api_key
65
+ end
66
+ end
67
+
68
+ # build_payload returns a processed payload from a raw message
69
+ # @param [String] api_key_str
70
+ # @param [String] extra_content
71
+ # @param [String] msg
72
+ def create_payload(api_key_str:, msg:, extra_content:)
73
+ "#{api_key_str} #{extra_content} #{msg}\n"
74
+ end
75
+
76
+ # Client supports building/sending payloads to Datadog Log Management
77
+ class Client
78
+ include ::Datadog::Log
79
+
80
+ def initialize(
81
+ log_dd_url: 'intake.logs.datadoghq.com',
82
+ log_dd_port: 10516,
83
+ api_key:,
84
+ hostname:,
85
+ skip_ssl_validation: false
86
+ )
87
+ @log_dd_url = log_dd_url
88
+ @log_dd_port = log_dd_port
89
+ @api_key = api_key
90
+ @hostname = hostname
91
+ @skip_ssl_validation = skip_ssl_validation
92
+
93
+ init_api_client
94
+ end
95
+
96
+ # rubocop:disable Metrics/ParameterLists
97
+ def send_payload(
98
+ logset: 'main',
99
+ msg:,
100
+ datetime: nil,
101
+ service:,
102
+ source:,
103
+ source_category:,
104
+ tags:
105
+ )
106
+ # rubocop:enable Metrics/ParameterLists
107
+
108
+ datetime = DateTime.now if datetime.nil?
109
+
110
+ # new_offset(0) is required.
111
+ # otherwise datadog will silently throws away the log..
112
+ timestamp_str = datetime.new_offset(0).rfc3339(6)
113
+ payload = create_payload(
114
+ api_key_str: build_api_key_str(api_key: @api_key, logset: logset),
115
+ msg: truncate_message(msg),
116
+ extra_content: build_extra_content(
117
+ timestamp: timestamp_str,
118
+ hostname: @hostname,
119
+ service: service,
120
+ tags_payload: build_tags_payload(
121
+ config_tags: tags,
122
+ source: source,
123
+ source_category: source_category
124
+ )
125
+ )
126
+ )
127
+ @conn.retry_on_connection_failure do
128
+ @conn.write(payload)
129
+ end
130
+ payload
131
+ end
132
+
133
+ def shutdown
134
+ @conn.close unless @conn.nil?
135
+ end
136
+
137
+ class << self
138
+ def from_env
139
+ new(api_key: ENV['DD_LOG_API_KEY'], hostname: Socket.gethostname)
140
+ end
141
+ end
142
+
143
+ private
144
+
145
+ def init_api_client
146
+ ssl = true
147
+ ssl = { verify_mode: OpenSSL::SSL::VERIFY_NONE } if @skip_ssl_validation
148
+ server = "#{@log_dd_url}:#{@log_dd_port}"
149
+ @conn = Net::TCPClient.new(server: server, ssl: ssl)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -18,8 +18,8 @@ require 'socket'
18
18
  require 'time'
19
19
  require 'yaml'
20
20
  require 'fluent/plugin/output'
21
- require 'datadog/log'
22
21
 
22
+ require_relative 'datadog_log'
23
23
  require_relative 'monitoring'
24
24
 
25
25
  module Fluent::Plugin
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-datadog-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc12
4
+ version: 0.1.0.rc13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke KUOKA
@@ -167,14 +167,12 @@ files:
167
167
  - fluent-plugin-datadog-log.gemspec
168
168
  - fluent-plugin-datadog-log.gemspec~
169
169
  - fluent-plugin-datadog.gemspec~
170
- - lib/datadog/log.rb
171
170
  - lib/datadog/log.rb~
171
+ - lib/fluent/plugin/datadog_log.rb
172
+ - lib/fluent/plugin/datadog_log.rb~
172
173
  - lib/fluent/plugin/monitoring.rb
173
174
  - lib/fluent/plugin/out_datadog_log.rb
174
175
  - lib/fluent/plugin/out_datadog_log.rb~
175
- - pkg/fluent-plugin-datadog-log-0.1.0.rc10.gem
176
- - pkg/fluent-plugin-datadog-log-0.1.0.rc11.gem
177
- - pkg/fluent-plugin-datadog-log-0.1.0.rc12.gem
178
176
  - test/helper.rb
179
177
  - test/plugin/base_test.rb
180
178
  - test/plugin/constants.rb