fluent-plugin-rds-mysql-log 0.1.3 → 0.1.5
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 +4 -4
- data/fluent-plugin-rds-mysql-log.gemspec +1 -1
- data/lib/fluent/plugin/in_rds_mysql_log.rb +44 -47
- data/test/plugin/test_in_rds_mysql_log.rb +25 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d9944b03c4974a63ee62fdbb1337b0e230022a300a9f9ddb21c7966ac5917fa
|
4
|
+
data.tar.gz: 9c331cb21f94f2ab6a00cd196dd1a014a449e629be8d8920d7113f5ed41ec930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad22c2ee1f23446bfbe0d19dc9a6a4e4de121d43b7eae3a0c945009019f1adf2d77190a8564039e58f28bd57223be20a44f7f41cbb22ca07371989c9cbccfca4
|
7
|
+
data.tar.gz: f76bf589f490c1e9dd81ba5da40bbf587d53c0a89da1147586f015021fb7dc4a7c00f7aef534451a64bbd07e0976a9150c69fbbef420434f39369428cb67ac02
|
@@ -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.
|
8
|
+
spec.version = '0.1.5'
|
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 true if log_file_name == "audit/server_audit.log"
|
85
|
+
return true if log_file_name == "general/mysql-general.log"
|
86
|
+
return true if log_file_name == "error/mysql-error-running.log"
|
87
|
+
|
88
|
+
false
|
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
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
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
|
-
|
145
|
-
|
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 =
|
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
|
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
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
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:
|
150
|
+
d.run(timeout: 3, expect_emits: 2)
|
142
151
|
|
143
152
|
events = d.events
|
144
|
-
assert_equal(
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Junaid Ali
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
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
|