fluent-plugin-rds-mysql-log 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3228cf8c54c9c3bc5a79742976dc646e549cee3a47fdbe2b0b403f3c326badd
4
- data.tar.gz: 97e43edd9c455691f4fc7ec881d6d76fdceaf3187587f8df059360c7eef65587
3
+ metadata.gz: 208c94e798557a8fd899d3c7cc21ab78c0f435896360315c8bda66f765767ced
4
+ data.tar.gz: 1205db429d34d5b4124680fb7d9dce912f16d86616c57c9aaf670608d03581a3
5
5
  SHA512:
6
- metadata.gz: 1c96f62c54275181ba8fc95f79f18e8b0106d73f87ef7100d01d95f0abf1d919fd76b79f7be4875056e97bd86460099d0d9d3b334b58448f0a062f0fe278d595
7
- data.tar.gz: 179a3823ec2ac89c1b9781a7db5caa99acdf19d1fb9e568b3388ed4e151149238cde851901645003f36be6749e405ca8a7e701c3de0d90c6342016ab2d184292
6
+ metadata.gz: 593abdfa3a97bec571a4d74de371d42200974423bc27be55ed0e6ef98ba0ec23bdcbdc152d5b600fd632613079925c7d881f1e9c4d0316e3e3d78654c8b97cc6
7
+ data.tar.gz: 2e94a21e667b1dad11b63f6acebc906081382d3102c5fe0148d753ca84cfee7f2eed23a95ecb7b14f4ebe1e89273b43e11981494d25dc3e599d7abeb2e6aec9e
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'fluent-plugin-rds-mysql-log'
8
- spec.version = '0.1.3'
8
+ spec.version = '0.1.6'
9
9
  spec.authors = ['Junaid Ali']
10
10
  spec.email = ['jonnie36@yahoo.com']
11
11
  spec.summary = 'Amazon RDS Mysql logs input plugin'
@@ -79,6 +79,14 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
79
79
  def is_audit_logs?
80
80
  @pos_info.keys.any? { |log_file_name| log_file_name =~ AUDIT_LOG_PATTERN }
81
81
  end
82
+
83
+ def should_track_marker?(log_file_name)
84
+ return false if log_file_name == "audit/server_audit.log"
85
+ return false if log_file_name == "general/mysql-general.log"
86
+ return false if log_file_name == "error/mysql-error-running.log"
87
+
88
+ true
89
+ end
82
90
 
83
91
  def get_and_parse_posfile
84
92
  begin
@@ -99,12 +107,7 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
99
107
 
100
108
  pos_match = /^(.+)\t(.+)$/.match(line)
101
109
  if pos_match
102
- if pos_match[1] =~ AUDIT_LOG_PATTERN
103
- pos_info[pos_match[1]] = 0
104
- else
105
- pos_info[pos_match[1]] = pos_match[2]
106
- end
107
-
110
+ pos_info[pos_match[1]] = pos_match[2]
108
111
  log.debug "log_file: #{pos_match[1]}, marker: #{pos_match[2]}"
109
112
  end
110
113
  end
@@ -117,39 +120,22 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
117
120
  end
118
121
  end
119
122
 
120
- def put_posfile
121
- # pos file write
122
- begin
123
- log.debug "pos file write"
124
- File.open(@pos_file, File::WRONLY|File::TRUNC) do |file|
125
- file.puts @pos_last_written_timestamp.to_s
126
-
127
- @pos_info.each do |log_file_name, marker|
128
- file.puts "#{log_file_name}\t#{marker}"
129
- end
130
- end
131
- rescue => e
132
- log.warn "pos file write error occurred: #{e.message}"
133
- end
134
- end
135
-
136
123
  def get_logfile_list
137
124
  begin
138
125
  log.debug "get logfile-list from rds: db_instance_identifier=#{@db_instance_identifier}, pos_last_written_timestamp=#{@pos_last_written_timestamp}"
139
126
 
140
- file_last_written = if is_audit_logs?
141
- # Use custom interval for audit logs
142
- (Time.now.to_i - @refresh_interval) * 1000
127
+ if is_audit_logs?
128
+ @rds.describe_db_log_files(
129
+ db_instance_identifier: @db_instance_identifier,
130
+ max_records: 10
131
+ )
143
132
  else
144
- # Use default timestamp for other logs
145
- @pos_last_written_timestamp
133
+ @rds.describe_db_log_files(
134
+ db_instance_identifier: @db_instance_identifier,
135
+ file_last_written: @pos_last_written_timestamp,
136
+ max_records: 10,
137
+ )
146
138
  end
147
-
148
- @rds.describe_db_log_files(
149
- db_instance_identifier: @db_instance_identifier,
150
- file_last_written: file_last_written,
151
- max_records: 10,
152
- )
153
139
  rescue => e
154
140
  log.warn "RDS Client describe_db_log_files error occurred: #{e.message}"
155
141
  end
@@ -162,12 +148,8 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
162
148
  # save maximum written timestamp value
163
149
  @pos_last_written_timestamp = item[:last_written] if @pos_last_written_timestamp < item[:last_written]
164
150
 
165
- log_file_name = item[:log_file_name]
166
- marker = if is_audit_logs?
167
- "0"
168
- else
169
- @pos_info[log_file_name] || "0"
170
- end
151
+ log_file_name = item[:log_file_name]
152
+ marker = should_track_marker?(log_file_name) ? @pos_info[log_file_name] || "0" : "0"
171
153
 
172
154
  log.debug "download log from rds: log_file_name=#{log_file_name}, marker=#{marker}"
173
155
  logs = @rds.download_db_log_file_portion(
@@ -179,12 +161,7 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
179
161
  raw_records = get_logdata(logs)
180
162
 
181
163
  #emit
182
- parse_and_emit(raw_records, log_file_name) unless raw_records.nil?
183
-
184
- # Save new last_written timestamp **only for non-audit logs**
185
- unless log_file_name =~ AUDIT_LOG_PATTERN
186
- @pos_last_written_timestamp = item[:last_written] if @pos_last_written_timestamp < item[:last_written]
187
- end
164
+ parse_and_emit(raw_records, log_file_name) unless raw_records&.empty?
188
165
  end
189
166
  end
190
167
  rescue => e
@@ -197,10 +174,12 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
197
174
  raw_records = []
198
175
  begin
199
176
  logs.each do |log|
200
- # save got line's marker
201
- @pos_info[log_file_name] = log.marker
177
+ next if log.log_file_data.nil? || log.log_file_data.empty?
202
178
 
203
179
  raw_records += log.log_file_data.split("\n")
180
+
181
+ # Update marker only if we actually got some data
182
+ @pos_info[log_file_name] = log.marker if should_track_marker?(log_file_name)
204
183
  end
205
184
  rescue => e
206
185
  log.warn e.message
@@ -262,6 +241,24 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
262
241
  log.warn e.message
263
242
  end
264
243
  end
244
+
245
+ def put_posfile
246
+ # pos file write
247
+ begin
248
+ log.debug "pos file write"
249
+ File.open(@pos_file, File::WRONLY|File::TRUNC) do |file|
250
+ log.debug "Writing pos file with timestamp=#{@pos_last_written_timestamp} and pos_info=#{@pos_info.inspect}"
251
+ @pos_info.delete_if { |file, _| !should_track_marker?(file) }
252
+ file.puts @pos_last_written_timestamp.to_s
253
+
254
+ @pos_info.each do |log_file_name, marker|
255
+ file.puts "#{log_file_name}\t#{marker}"
256
+ end
257
+ end
258
+ rescue => e
259
+ log.warn "pos file write error occurred: #{e.message}"
260
+ end
261
+ end
265
262
 
266
263
  class TimerWatcher < Coolio::TimerWatcher
267
264
  def initialize(interval, repeat, &callback)
@@ -56,7 +56,7 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
56
56
  aws_client_stub = Aws::RDS::Client.new(stub_responses: {
57
57
  describe_db_log_files: {
58
58
  describe_db_log_files: [
59
- { log_file_name: 'server_audit.log', last_written: 123456789, size: 123 }
59
+ { log_file_name: 'audit/server_audit.log', last_written: 123456789, size: 123 }
60
60
  ],
61
61
  marker: 'old_marker'
62
62
  },
@@ -73,7 +73,7 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
73
73
  d.run(timeout: 3, expect_emits: 1)
74
74
  events = d.events
75
75
 
76
- assert_equal(events[0][2]["log_file_name"], 'server_audit.log')
76
+ assert_equal(events[0][2]["log_file_name"], 'audit/server_audit.log')
77
77
  assert_equal(events[0][2]["message"], "UPDATE table SET id=123, updated_at=\'2025-04-03 19:38:08.681797\', is_weight_saved=1 WHERE table.id = 1234")
78
78
  end
79
79
 
@@ -85,7 +85,7 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
85
85
  describe_db_log_files: {
86
86
  describe_db_log_files: [
87
87
  {
88
- log_file_name: 'error.log',
88
+ log_file_name: 'error/mysql-error-running.log',
89
89
  last_written: 123456789,
90
90
  size: 123
91
91
  }
@@ -108,7 +108,7 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
108
108
 
109
109
  events = d.events
110
110
 
111
- assert_equal(events[0][2]["log_file_name"], 'error.log')
111
+ assert_equal(events[0][2]["log_file_name"], 'error/mysql-error-running.log')
112
112
  assert_equal(events[0][2]["message"], "IP address '1.2.3.4' could not be resolved: Name or service not known")
113
113
 
114
114
  # Ensure non-audit logs used `pos_last_written_timestamp`
@@ -118,30 +118,42 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
118
118
  def test_get_audit_log_files
119
119
  use_iam_role
120
120
  d = create_driver
121
-
121
+ first_log_line = "20250403 19:41:01,ip-1-1-1-1,service,1.2.3.4,12345678,1234567890,QUERY,test_db,'UPDATE table SET id=123, updated_at=\'2025-04-03 19:38:08.681797\', is_weight_saved=1 WHERE table.id = 1234',0,,"
122
+ second_log_line = "20250403 19:42:01,ip-1-1-1-1,service,1.2.3.4,12345678,1234567890,QUERY,test_db,'UPDATE table SET id=456, updated_at=\'2025-04-03 19:38:08.681797\', is_weight_saved=1 WHERE table.id = 5678',0,,"
123
+
122
124
  aws_client_stub = Aws::RDS::Client.new(stub_responses: {
123
125
  describe_db_log_files: {
124
126
  describe_db_log_files: [
125
127
  {
126
- log_file_name: 'server_audit.log',
128
+ log_file_name: 'audit/server_audit.log',
127
129
  last_written: Time.now.to_i,
128
130
  size: 123
129
131
  }
130
132
  ],
131
133
  marker: 'marker'
132
134
  },
133
- download_db_log_file_portion: {
134
- log_file_data: "20250403 19:41:01,ip-1-1-1-1,service,1.2.3.4,12345678,1234567890,QUERY,test_db,'UPDATE table SET id=123, updated_at=\'2025-04-03 19:38:08.681797\', is_weight_saved=1 WHERE table.id = 1234',0,,",
135
- marker: 'marker',
136
- additional_data_pending: false
137
- }
135
+ download_db_log_file_portion: [
136
+ {
137
+ log_file_data: first_log_line,
138
+ marker: 'marker',
139
+ additional_data_pending: false
140
+ },
141
+ {
142
+ log_file_data: second_log_line,
143
+ marker: 'marker',
144
+ additional_data_pending: false
145
+ }
146
+ ]
138
147
  })
139
148
 
140
149
  d.instance.instance_variable_set(:@rds, aws_client_stub)
141
- d.run(timeout: 3, expect_emits: 1)
150
+ d.run(timeout: 3, expect_emits: 2)
142
151
 
143
152
  events = d.events
144
- assert_equal(events[0][2]["log_file_name"], 'server_audit.log')
153
+ assert_equal(2, events.size)
154
+ assert_equal(events[0][2]["log_file_name"], 'audit/server_audit.log')
145
155
  assert_equal(events[0][2]["message"], "UPDATE table SET id=123, updated_at=\'2025-04-03 19:38:08.681797\', is_weight_saved=1 WHERE table.id = 1234")
156
+ assert_equal(events[1][2]["log_file_name"], 'audit/server_audit.log')
157
+ assert_equal(events[1][2]["message"], "UPDATE table SET id=456, updated_at=\'2025-04-03 19:38:08.681797\', is_weight_saved=1 WHERE table.id = 5678")
146
158
  end
147
159
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-rds-mysql-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junaid Ali
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-07 00:00:00.000000000 Z
10
+ date: 2025-04-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: aws-sdk-ec2