fluent-plugin-postgresql-csvlog 0.9.2 → 0.10.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2393ec76502b4127cd874027d99eada9e184dba85edfec3c2a9cfe1a88de54ee
|
4
|
+
data.tar.gz: 2f61b0b0d4e27a302f90449af833dba0e985406d98f15be773ac379146a958d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b537e7458f9fa38bb0b88672e137a345739f22ab92f8a3d9fe3cf0e26f9e958995c2f7fdb51afc649ac5f55e608ddd431ef904dd757e651f1b223be58703d7d6
|
7
|
+
data.tar.gz: 7724c6961993e7e50ef38ebfa22b874fd4578eb8d8057d2cac76fe761f723a5631e1a227c791c7debf24c2631bc4eea1c2febe929f723a5584c52adbb2b91a49
|
@@ -2,7 +2,7 @@ $:.push File.expand_path('lib', __dir__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'fluent-plugin-postgresql-csvlog'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.10.0'
|
6
6
|
s.authors = ['stanhu']
|
7
7
|
s.email = ['stanhu@gmail.com']
|
8
8
|
s.homepage = 'https://gitlab.com/gitlab-org/fluent-plugins/fluent-plugin-postgresql-csvlog'
|
@@ -16,6 +16,9 @@ module Fluent::Plugin
|
|
16
16
|
desc 'Name of field to store SQL query fingerprint'
|
17
17
|
config_param :fingerprint_key, :string, default: 'fingerprint'
|
18
18
|
|
19
|
+
desc 'Truncate the query if it exceeds the number of bytes'
|
20
|
+
config_param :max_length, :integer, default: 3 * 1024 * 1024
|
21
|
+
|
19
22
|
def filter(_tag, _time, record)
|
20
23
|
statement = record[@input_key]
|
21
24
|
|
@@ -25,12 +28,23 @@ module Fluent::Plugin
|
|
25
28
|
record[@fingerprint_key] = PgQuery.fingerprint(normalized) if @fingerprint_key
|
26
29
|
|
27
30
|
record.delete(@input_key)
|
28
|
-
record[@output_key] = normalized
|
31
|
+
record[@output_key] = truncate_query(record, normalized)
|
29
32
|
|
30
33
|
record
|
31
34
|
rescue PgQuery::ParseError
|
32
35
|
record['pg_query_error'] = true
|
33
36
|
record
|
34
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def truncate_query(record, normalized)
|
42
|
+
return normalized if normalized.length < @max_length
|
43
|
+
|
44
|
+
record['truncated_query'] = true
|
45
|
+
# Assume UTF-8 encoding for PostgreSQL queries
|
46
|
+
utf8_query = normalized.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
|
47
|
+
utf8_query[0, @max_length]
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
@@ -31,6 +31,26 @@ class PostgreSQLRedactorTest < Test::Unit::TestCase
|
|
31
31
|
assert_equal('SELECT * FROM projects WHERE id = $1', d.filtered[0].last['sql'])
|
32
32
|
end
|
33
33
|
|
34
|
+
test 'truncates logs' do
|
35
|
+
d = create_driver(<<~CONF
|
36
|
+
max_length 10
|
37
|
+
CONF
|
38
|
+
)
|
39
|
+
|
40
|
+
inputs = [
|
41
|
+
{ 'message' => 'duration: 2357.1 ms execute <unnamed>: SELECT * FROM projects WHERE id = 1',
|
42
|
+
'query' => %(SELECT * FROM projects WHERE id = 1),
|
43
|
+
'duration_s' => 2.3571 }
|
44
|
+
]
|
45
|
+
|
46
|
+
d.run(default_tag: @tag) do
|
47
|
+
inputs.each { |input| d.feed(input) }
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal(%w[duration_s fingerprint message sql truncated_query], d.filtered[0].last.keys.sort)
|
51
|
+
assert_equal('SELECT * F', d.filtered[0].last['sql'])
|
52
|
+
end
|
53
|
+
|
34
54
|
test 'handles parse errors' do
|
35
55
|
d = create_driver
|
36
56
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-postgresql-csvlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stanhu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|