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

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: 9b755fb7acda5fbc4825668d0351c4ed8b8259127a18027ff372ec1648ea6843
4
- data.tar.gz: 4791ffd4877d9eaeba8b28a6674ff1365d096d44b961113c9f1a7ac27aed6115
3
+ metadata.gz: a3228cf8c54c9c3bc5a79742976dc646e549cee3a47fdbe2b0b403f3c326badd
4
+ data.tar.gz: 97e43edd9c455691f4fc7ec881d6d76fdceaf3187587f8df059360c7eef65587
5
5
  SHA512:
6
- metadata.gz: 9450bbed8aa34dfa3a1d4c06606b224d8c0cc11705292c1b6e11d02be963199fe5926c1875a2f34e94e999040c3152b305379a45083ae1fe5418212339c71550
7
- data.tar.gz: ba76f33506086245ad6d1c2968466df20b1ca8541a18366ed1170333267bd3b99c860e955a092d547977f2764600ccbc9411d5187d57f85a7e75d0e0d22408d1
6
+ metadata.gz: 1c96f62c54275181ba8fc95f79f18e8b0106d73f87ef7100d01d95f0abf1d919fd76b79f7be4875056e97bd86460099d0d9d3b334b58448f0a062f0fe278d595
7
+ data.tar.gz: 179a3823ec2ac89c1b9781a7db5caa99acdf19d1fb9e568b3388ed4e151149238cde851901645003f36be6749e405ca8a7e701c3de0d90c6342016ab2d184292
data/README.md CHANGED
@@ -7,7 +7,7 @@ This plugin has been created to deal with audit and error logs of mysql.
7
7
 
8
8
  ## Installation
9
9
 
10
- $ fluentd-gem install fluent-plugin-rds-mysql-log
10
+ $ gem install fluent-plugin-rds-mysql-log
11
11
 
12
12
  ## AWS ELB Settings
13
13
  - settings see: [Mysql Database Log Files](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.Mysql.html)
@@ -17,7 +17,7 @@ log:
17
17
  ```
18
18
  SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
19
19
  ```
20
- Do env setting follows:
20
+ Do env settings follows:
21
21
  ```
22
22
  SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt (If you using amazon linux)
23
23
  ```
@@ -40,7 +40,7 @@ SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt (If you using amazon linux)
40
40
  </source>
41
41
  ```
42
42
 
43
- ### Example setting
43
+ ### Example settings
44
44
  ```config
45
45
  <source>
46
46
  type rds_mysql_log
@@ -5,13 +5,14 @@ $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.0'
8
+ spec.version = '0.1.3'
9
9
  spec.authors = ['Junaid Ali']
10
10
  spec.email = ['jonnie36@yahoo.com']
11
11
  spec.summary = 'Amazon RDS Mysql logs input plugin'
12
12
  spec.description = 'fluentd plugin for Amazon RDS Mysql logs input'
13
13
  spec.homepage = 'https://github.com/iamjunaidali/fluent-plugin-rds-mysql-log.git'
14
14
  spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.7.0'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -75,6 +75,10 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
75
75
  log.warn "EC2 Client error occurred: #{e.message}"
76
76
  end
77
77
  end
78
+
79
+ def is_audit_logs?
80
+ @pos_info.keys.any? { |log_file_name| log_file_name =~ AUDIT_LOG_PATTERN }
81
+ end
78
82
 
79
83
  def get_and_parse_posfile
80
84
  begin
@@ -83,21 +87,28 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
83
87
 
84
88
  pos_last_written_timestamp = 0
85
89
  pos_info = {}
90
+
86
91
  File.open(@pos_file, File::RDONLY) do |file|
87
92
  file.each_line do |line|
93
+
88
94
  pos_match = /^(\d+)$/.match(line)
89
95
  if pos_match
90
- pos_last_written_timestamp = pos_match[1].to_i
96
+ pos_last_written_timestamp = pos_match[1].to_i
91
97
  log.debug "pos_last_written_timestamp: #{pos_last_written_timestamp}"
92
98
  end
93
99
 
94
100
  pos_match = /^(.+)\t(.+)$/.match(line)
95
101
  if pos_match
96
- pos_info[pos_match[1]] = pos_match[2]
97
- p pos_info
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
+
98
108
  log.debug "log_file: #{pos_match[1]}, marker: #{pos_match[2]}"
99
109
  end
100
110
  end
111
+
101
112
  @pos_last_written_timestamp = pos_last_written_timestamp
102
113
  @pos_info = pos_info
103
114
  end
@@ -126,11 +137,7 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
126
137
  begin
127
138
  log.debug "get logfile-list from rds: db_instance_identifier=#{@db_instance_identifier}, pos_last_written_timestamp=#{@pos_last_written_timestamp}"
128
139
 
129
- # Separate audit logs from other logs
130
-
131
- audit_logs_exist = @pos_info.keys.any? { |log_file_name| log_file_name =~ AUDIT_LOG_PATTERN }
132
-
133
- file_last_written = if audit_logs_exist
140
+ file_last_written = if is_audit_logs?
134
141
  # Use custom interval for audit logs
135
142
  (Time.now.to_i - @refresh_interval) * 1000
136
143
  else
@@ -155,9 +162,12 @@ class Fluent::Plugin::RdsMysqlLogInput < Fluent::Plugin::Input
155
162
  # save maximum written timestamp value
156
163
  @pos_last_written_timestamp = item[:last_written] if @pos_last_written_timestamp < item[:last_written]
157
164
 
158
- # log file download
159
- log_file_name = item[:log_file_name]
160
- marker = @pos_info[log_file_name] || "0"
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
161
171
 
162
172
  log.debug "download log from rds: log_file_name=#{log_file_name}, marker=#{marker}"
163
173
  logs = @rds.download_db_log_file_portion(
@@ -75,8 +75,6 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
75
75
 
76
76
  assert_equal(events[0][2]["log_file_name"], '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
-
79
- # assert_equal(d.instance.instance_variable_get(:@pos_info)['server_audit.log'], 'new_marker')
80
78
  end
81
79
 
82
80
  def test_get_non_audit_log_files
@@ -140,18 +138,10 @@ class RdsMysqlLogInputTest < Test::Unit::TestCase
140
138
  })
141
139
 
142
140
  d.instance.instance_variable_set(:@rds, aws_client_stub)
143
-
144
- d.instance.instance_variable_set(:@pos_last_written_timestamp, (Time.now.to_i - (2*2000)))
145
-
146
- test_start_time = Time.now.to_i
147
- buffer_time = 5 * d.instance.refresh_interval * 20000
148
-
149
141
  d.run(timeout: 3, expect_emits: 1)
150
142
 
151
143
  events = d.events
152
144
  assert_equal(events[0][2]["log_file_name"], 'server_audit.log')
153
145
  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")
154
-
155
- assert_operator events[0][1].to_i, :>=, (test_start_time - (buffer_time))
156
146
  end
157
147
  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.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junaid Ali
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-04 00:00:00.000000000 Z
10
+ date: 2025-04-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: aws-sdk-ec2
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: 2.7.0
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - ">="