logstash-output-charrington 0.3.12 → 0.3.13
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/lib/logstash/outputs/charrington.rb +4 -1
- data/lib/logstash/outputs/charrington/create_postgres_table.rb +16 -4
- data/lib/logstash/outputs/charrington/create_redshift_table.rb +2 -2
- data/lib/logstash/outputs/charrington/insert.rb +4 -3
- data/lib/logstash/outputs/charrington/process.rb +5 -4
- data/logstash-output-charrington.gemspec +1 -1
- data/spec/outputs/charrington_spec.rb +38 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bb02ce087011aef5d96e4a5ea26e7151ff87d185e24b2812a24c95319c322b0
|
4
|
+
data.tar.gz: 6a5ea166ed113d948d766339f35f049e68bd2309e23899e25c7ae5e9345dce33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a963e2a2c2a6e182fcb63c202b857e55814e7dc4cf7983bc7e34e3f3af7141ecb9c7bd656c52d15559905f978993cc9442e33ce29f927e0140e0fc2553fadf1
|
7
|
+
data.tar.gz: e257a03e1a42b74c14b01b0a4cd5e67ad285e8a8de9e3a3b7f5bd934c8c97c228149808e1d429bf17d3f1ee3658ba9b84bc326a16b163f0212a1a9f9abe14c28
|
@@ -85,6 +85,8 @@ class LogStash::Outputs::Charrington < LogStash::Outputs::Base
|
|
85
85
|
# The database schema
|
86
86
|
config :schema, validate: :string, required: false
|
87
87
|
|
88
|
+
config :transformer, validate: :string, default: 'redshift'
|
89
|
+
|
88
90
|
def register
|
89
91
|
@logger.info('JDBC - Starting up')
|
90
92
|
|
@@ -105,7 +107,8 @@ class LogStash::Outputs::Charrington < LogStash::Outputs::Base
|
|
105
107
|
schema: schema,
|
106
108
|
max_retries: @max_flush_exceptions,
|
107
109
|
retry_initial_interval: @retry_initial_interval,
|
108
|
-
driver: driver
|
110
|
+
driver: driver,
|
111
|
+
transformer: @transformer }
|
109
112
|
Charrington::Process.call(connection, event, opts)
|
110
113
|
rescue => e
|
111
114
|
@logger.error("Unable to process event. Event dropped. #{e.message}")
|
@@ -7,18 +7,19 @@ module Charrington
|
|
7
7
|
|
8
8
|
include Service
|
9
9
|
include LogStash::Util::Loggable
|
10
|
-
attr_reader :connection, :event, :table_name, :columns, :schema
|
10
|
+
attr_reader :connection, :event, :table_name, :columns, :schema, :opts, :transformer
|
11
11
|
attr_accessor :column_types
|
12
12
|
|
13
13
|
Error = Class.new(StandardError)
|
14
14
|
CreateFailed = Class.new(Error)
|
15
15
|
|
16
|
-
def initialize(connection, event, schema, table_name, columns)
|
16
|
+
def initialize(connection, event, schema, table_name, columns, opts = {})
|
17
17
|
@connection = connection
|
18
18
|
@event = event.to_hash
|
19
19
|
@table_name = table_name
|
20
20
|
@schema = schema
|
21
21
|
@columns = columns
|
22
|
+
@transformer = opts[:transformer]
|
22
23
|
@column_types = initial_columns
|
23
24
|
end
|
24
25
|
|
@@ -61,8 +62,19 @@ module Charrington
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def initial_columns
|
64
|
-
|
65
|
-
|
65
|
+
if transformer == "postgres"
|
66
|
+
[
|
67
|
+
"id SERIAL PRIMARY KEY",
|
68
|
+
"inserted_at TIMESTAMP DEFAULT NOW()"
|
69
|
+
]
|
70
|
+
else
|
71
|
+
[
|
72
|
+
"original_timestamp TIMESTAMP DEFAULT NOW()",
|
73
|
+
"received_at TIMESTAMP DEFAULT NOW()",
|
74
|
+
"timestamp TIMESTAMP DEFAULT NOW()",
|
75
|
+
"uuid_ts TIMESTAMP DEFAULT NOW()"
|
76
|
+
]
|
77
|
+
end
|
66
78
|
end
|
67
79
|
|
68
80
|
def create_table
|
@@ -7,13 +7,13 @@ module Charrington
|
|
7
7
|
|
8
8
|
include Service
|
9
9
|
include LogStash::Util::Loggable
|
10
|
-
attr_reader :connection, :event, :table_name, :columns, :schema
|
10
|
+
attr_reader :connection, :event, :table_name, :columns, :schema, :opts
|
11
11
|
attr_accessor :column_types
|
12
12
|
|
13
13
|
Error = Class.new(StandardError)
|
14
14
|
CreateFailed = Class.new(Error)
|
15
15
|
|
16
|
-
def initialize(connection, event, schema, table_name, columns)
|
16
|
+
def initialize(connection, event, schema, table_name, columns, opts = {})
|
17
17
|
@connection = connection
|
18
18
|
@event = event.to_hash
|
19
19
|
@schema = schema
|
@@ -12,7 +12,7 @@ module Charrington
|
|
12
12
|
include Service
|
13
13
|
include LogStash::Util::Loggable
|
14
14
|
attr_accessor :event, :should_retry
|
15
|
-
attr_reader :connection, :schema, :table_name, :columns, :driver
|
15
|
+
attr_reader :connection, :schema, :table_name, :columns, :driver, :opts
|
16
16
|
attr_reader :event_as_json_keyword, :enable_event_as_json_keyword
|
17
17
|
|
18
18
|
Error = Class.new(StandardError)
|
@@ -36,6 +36,7 @@ module Charrington
|
|
36
36
|
@enable_event_as_json_keyword = opts[:enable_event_as_json_keyword]
|
37
37
|
@event_as_json_keyword = opts[:event_as_json_keyword]
|
38
38
|
@driver = opts[:driver]
|
39
|
+
@opts = opts
|
39
40
|
end
|
40
41
|
|
41
42
|
def call
|
@@ -72,9 +73,9 @@ module Charrington
|
|
72
73
|
|
73
74
|
def create_table
|
74
75
|
if driver == "postgres"
|
75
|
-
Charrington::CreatePostgresTable.call(connection, event, schema, table_name, columns)
|
76
|
+
Charrington::CreatePostgresTable.call(connection, event, schema, table_name, columns, opts)
|
76
77
|
elsif driver == "redshift"
|
77
|
-
Charrington::CreateRedshiftTable.call(connection, event, schema, table_name, columns)
|
78
|
+
Charrington::CreateRedshiftTable.call(connection, event, schema, table_name, columns, opts)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
@@ -7,7 +7,7 @@ module Charrington
|
|
7
7
|
|
8
8
|
include Service
|
9
9
|
include LogStash::Util::Loggable
|
10
|
-
attr_reader :event, :connection, :opts, :max_retries, :schema, :retry_max_interval, :driver
|
10
|
+
attr_reader :event, :connection, :opts, :max_retries, :schema, :retry_max_interval, :driver, :transformer
|
11
11
|
attr_accessor :retry_interval, :should_retry
|
12
12
|
|
13
13
|
Error = Class.new(StandardError)
|
@@ -24,6 +24,7 @@ module Charrington
|
|
24
24
|
@retry_max_interval = opts[:retry_max_interval] || 2
|
25
25
|
@retry_interval = opts[:retry_initial_interval] || 2
|
26
26
|
@driver = opts[:driver]
|
27
|
+
@transformer = opts[:transformer]
|
27
28
|
|
28
29
|
@attempts = 1
|
29
30
|
@should_retry = true
|
@@ -31,12 +32,12 @@ module Charrington
|
|
31
32
|
|
32
33
|
def call
|
33
34
|
while should_retry do
|
34
|
-
transformed = case
|
35
|
+
transformed = case transformer
|
35
36
|
when "redshift"
|
36
|
-
self.logger.info "Found
|
37
|
+
self.logger.info "Found transformer of #{transformer} for driver of #{driver} with event of: #{event}"
|
37
38
|
Charrington::TransformRedshift.call(event)
|
38
39
|
else
|
39
|
-
self.logger.info "Found
|
40
|
+
self.logger.info "Found transformer of #{transformer} for driver of #{driver} with event of: #{event}"
|
40
41
|
Charrington::TransformPostgres.call(event)
|
41
42
|
end
|
42
43
|
self.logger.info "Transformed event into: #{transformed}"
|
@@ -20,6 +20,7 @@ describe LogStash::Outputs::Charrington do
|
|
20
20
|
connection_string => '#{@url}'
|
21
21
|
driver_jar_path => '#{driver_path}'
|
22
22
|
schema => ''
|
23
|
+
transformer => 'postgres'
|
23
24
|
}
|
24
25
|
}
|
25
26
|
CONFIG
|
@@ -49,6 +50,7 @@ describe LogStash::Outputs::Charrington do
|
|
49
50
|
connection_string => '#{@url}'
|
50
51
|
driver_jar_path => '#{driver_path}'
|
51
52
|
schema => ''
|
53
|
+
transformer => 'postgres'
|
52
54
|
}
|
53
55
|
}
|
54
56
|
CONFIG
|
@@ -81,6 +83,7 @@ describe LogStash::Outputs::Charrington do
|
|
81
83
|
connection_string => '#{@url}'
|
82
84
|
driver_jar_path => '#{driver_path}'
|
83
85
|
schema => ''
|
86
|
+
transformer => 'postgres'
|
84
87
|
}
|
85
88
|
}
|
86
89
|
CONFIG
|
@@ -113,6 +116,7 @@ describe LogStash::Outputs::Charrington do
|
|
113
116
|
connection_string => '#{@url}'
|
114
117
|
driver_jar_path => '#{driver_path}'
|
115
118
|
schema => ''
|
119
|
+
transformer => 'postgres'
|
116
120
|
}
|
117
121
|
}
|
118
122
|
CONFIG
|
@@ -153,6 +157,7 @@ describe LogStash::Outputs::Charrington do
|
|
153
157
|
connection_string => '#{@url}'
|
154
158
|
driver_jar_path => '#{driver_path}'
|
155
159
|
schema => '#{schema}'
|
160
|
+
transformer => 'postgres'
|
156
161
|
}
|
157
162
|
}
|
158
163
|
CONFIG
|
@@ -186,6 +191,7 @@ describe LogStash::Outputs::Charrington do
|
|
186
191
|
connection_string => '#{@url}'
|
187
192
|
driver_jar_path => '#{driver_path}'
|
188
193
|
schema => ''
|
194
|
+
transformer => 'postgres'
|
189
195
|
}
|
190
196
|
}
|
191
197
|
CONFIG
|
@@ -199,4 +205,36 @@ describe LogStash::Outputs::Charrington do
|
|
199
205
|
end
|
200
206
|
end
|
201
207
|
|
208
|
+
describe 'a new payload with one event transformed to be redshift shape' do
|
209
|
+
let(:config) do
|
210
|
+
<<-CONFIG
|
211
|
+
input {
|
212
|
+
generator {
|
213
|
+
message => '{"app_name": "Web App", "event": "schemaless", "meta": { "type": "XML" }, "published_at": "2019-07-29T20:09:18Z" }'
|
214
|
+
codec => 'json'
|
215
|
+
count => 1
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
output {
|
220
|
+
charrington {
|
221
|
+
connection_string => '#{@url}'
|
222
|
+
driver_jar_path => '#{driver_path}'
|
223
|
+
schema => ''
|
224
|
+
transformer => 'redshift'
|
225
|
+
}
|
226
|
+
}
|
227
|
+
CONFIG
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'creates a table and inserts a record with data the shape of redshift' do
|
231
|
+
drop_table('schemaless')
|
232
|
+
run_pipeline
|
233
|
+
expect(query('SELECT * FROM schemaless')).to match_array([
|
234
|
+
{:anonymous_id=>"", :app_name=>"Web App", :event=>"schemaless", :event_text=>"schemaless", :id=>a_kind_of(String), :original_timestamp=>a_kind_of(String), :received_at=>a_kind_of(String), :sent_at=>"2019-07-29 20:09:18", :timestamp=>a_kind_of(String), :type=>"XML", :uuid_ts=>a_kind_of(String)}
|
235
|
+
])
|
236
|
+
expect(query('SELECT COUNT(1) FROM schemaless').first[:count]).to eq("1")
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
202
240
|
end
|