logstash-output-charrington 0.3.9 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e031c490f1a81f62f0a781e259ce3872712255e014e11a41fc7420e120368fd8
4
- data.tar.gz: f54fb87f22fed7eda64e068897a2942323f08fb54dd9cac4972ce58a3ae0217e
3
+ metadata.gz: 3e19aa1ec683b1b07dd8bd6cb7b715e382d9bcf97f839339be15c47e49749db3
4
+ data.tar.gz: 845b806354d17539f84b7b3b31c6925a1c5220d85364a89d61086e3734fa7084
5
5
  SHA512:
6
- metadata.gz: eeef47c0d66f3b1533adb9eb539e4db501b190b1ac47c89b1ad71c1e12f6748b7a957fbb4f3e08c58e75d45ae50186469e871ceb7e487a7595e81901a04f1ef7
7
- data.tar.gz: 8f8da734bb7054bf04da564032a2d17402c905e2160ed03a78dc05f35b05faf6d67312566cc278c88ca521c2f8f86ef03d9ac9d3cd42e02d096fde38f4022eb0
6
+ metadata.gz: f3f61f69b23d8a28db703c1ca76952056953cd223a715322db5b0f422a1ad18d561e0d28dacb2518eaaa8799c3a9b08b718818129a41a5cd54e430dbd33c11fc
7
+ data.tar.gz: 6dff6e868f6264a77c70af63f018f8ab150f8097e03acf4521b2e068e61dce49baa3dc520aabc71be60bcf276bf33f90a8d5271d2f5e7b360c7a265b8b1e5f84
@@ -36,6 +36,11 @@ module Charrington
36
36
 
37
37
  def set_column_types
38
38
  columns.each do |column|
39
+ if column == "published_at" || column == "sent_at"
40
+ column_types << "#{column} TIMESTAMP"
41
+ next
42
+ end
43
+
39
44
  case event[column]
40
45
  when Time, LogStash::Timestamp
41
46
  column_types << "#{column} TIMESTAMP"
@@ -41,6 +41,9 @@ module Charrington
41
41
  if column == "id"
42
42
  column_types << "#{column} VARCHAR(512) NOT NULL distkey CONSTRAINT #{table_name}_pkey primary key"
43
43
  next
44
+ elsif column == "sent_at"
45
+ column_types << "#{column} TIMESTAMP"
46
+ next
44
47
  end
45
48
  case event[column]
46
49
  when Time, LogStash::Timestamp
@@ -23,16 +23,13 @@ module Charrington
23
23
  def initialize(connection, event, opts = {})
24
24
  raise EventNil, "Table name is nil" if event.nil?
25
25
  @event = event.to_hash
26
- event_name = event["event"].to_s.downcase.strip
26
+ event_name = event["event"].to_s.strip
27
27
  raise TableNameNil, "Table name is nil" if event_name.empty?
28
28
 
29
29
  @connection = connection
30
30
  @schema = opts[:schema].empty? ? '' : "#{opts[:schema]}."
31
31
 
32
- @table_name = "#{event_name
33
- .gsub(/[^a-z0-9]+/, "_")
34
- .gsub(/\A_+/, "")
35
- .gsub(/_+\z/, "")}"
32
+ @table_name = underscore(event_name)
36
33
 
37
34
  @columns = event.keys
38
35
  @should_retry = false
@@ -120,6 +117,14 @@ module Charrington
120
117
  pos = idx + 1
121
118
  value = event[key]
122
119
 
120
+ if key == 'published_at' || key == 'sent_at'
121
+ format = java.text.SimpleDateFormat.new("yyyy-MM-dd'T'HH:mm:ss'Z'")
122
+ parsed = format.parse(value)
123
+ time = java.sql.Timestamp.new(parsed.getTime)
124
+ stmt.setTimestamp(pos, time)
125
+ next
126
+ end
127
+
123
128
  case value
124
129
  when Time
125
130
  stmt.setString(pos, value.strftime(STRFTIME_FMT))
@@ -158,6 +163,17 @@ module Charrington
158
163
  obj.is_a? Hash or obj.is_a? Array
159
164
  end
160
165
 
166
+ def underscore(str)
167
+ str.
168
+ gsub(/::/, '/').
169
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
170
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
171
+ downcase.
172
+ gsub(/[^a-z0-9]+/, "_").
173
+ gsub(/\A_+/, "").
174
+ gsub(/_+\z/, "")
175
+ end
176
+
161
177
  ### SQL
162
178
 
163
179
  def execute(connection, sql)
@@ -62,7 +62,14 @@ module Charrington
62
62
  end
63
63
 
64
64
  def underscore_event_name(event_name)
65
- event_name.to_s.downcase.strip.gsub(/[^a-z0-9]+/, "_")
65
+ event_name.
66
+ gsub(/::/, '/').
67
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
68
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
69
+ downcase.
70
+ gsub(/[^a-z0-9]+/, "_").
71
+ gsub(/\A_+/, "").
72
+ gsub(/_+\z/, "")
66
73
  end
67
74
 
68
75
  def transform_session_stuff(hash)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-charrington'
3
- s.version = '0.3.9'
3
+ s.version = '0.3.12'
4
4
 
5
5
  s.licenses = ['Apache-2.0']
6
6
  s.homepage = 'https://gitlab.podium.com/engineering/analytics/logstash-output-charrington'
@@ -9,7 +9,7 @@ describe LogStash::Outputs::Charrington do
9
9
  <<-CONFIG
10
10
  input {
11
11
  generator {
12
- message => '{"app_name": "Web App", "event": "schemaless", "meta": { "type": "XML" } }'
12
+ message => '{"app_name": "Web App", "event": "schemaless", "meta": { "type": "XML" }, "published_at": "2019-07-29T20:09:18Z" }'
13
13
  codec => 'json'
14
14
  count => 1
15
15
  }
@@ -19,6 +19,7 @@ describe LogStash::Outputs::Charrington do
19
19
  charrington {
20
20
  connection_string => '#{@url}'
21
21
  driver_jar_path => '#{driver_path}'
22
+ schema => ''
22
23
  }
23
24
  }
24
25
  CONFIG
@@ -27,7 +28,7 @@ describe LogStash::Outputs::Charrington do
27
28
  it 'creates a table and inserts a record' do
28
29
  drop_table('schemaless')
29
30
  run_pipeline
30
- expect(query('SELECT * FROM schemaless')).to match_array([{id: "1", app_name: "Web App", event: "schemaless", inserted_at: a_kind_of(String), :meta_type => "XML"}])
31
+ expect(query('SELECT * FROM schemaless')).to match_array([{id: "1", app_name: "Web App", event: "schemaless", inserted_at: a_kind_of(String), :meta_type => "XML", :published_at => "2019-07-29 20:09:18"}])
31
32
  expect(query('SELECT COUNT(1) FROM schemaless').first[:count]).to eq("1")
32
33
  end
33
34
  end
@@ -47,6 +48,7 @@ describe LogStash::Outputs::Charrington do
47
48
  charrington {
48
49
  connection_string => '#{@url}'
49
50
  driver_jar_path => '#{driver_path}'
51
+ schema => ''
50
52
  }
51
53
  }
52
54
  CONFIG
@@ -78,6 +80,7 @@ describe LogStash::Outputs::Charrington do
78
80
  charrington {
79
81
  connection_string => '#{@url}'
80
82
  driver_jar_path => '#{driver_path}'
83
+ schema => ''
81
84
  }
82
85
  }
83
86
  CONFIG
@@ -109,6 +112,7 @@ describe LogStash::Outputs::Charrington do
109
112
  charrington {
110
113
  connection_string => '#{@url}'
111
114
  driver_jar_path => '#{driver_path}'
115
+ schema => ''
112
116
  }
113
117
  }
114
118
  CONFIG
@@ -166,6 +170,33 @@ describe LogStash::Outputs::Charrington do
166
170
  end
167
171
  end
168
172
 
169
- end
173
+ describe 'a new payload with one event camelCase' do
174
+ let(:config) do
175
+ <<-CONFIG
176
+ input {
177
+ generator {
178
+ message => '{"app_name": "Web App", "event": "camelCase this", "meta": { "type": "XML" } }'
179
+ codec => 'json'
180
+ count => 1
181
+ }
182
+ }
170
183
 
184
+ output {
185
+ charrington {
186
+ connection_string => '#{@url}'
187
+ driver_jar_path => '#{driver_path}'
188
+ schema => ''
189
+ }
190
+ }
191
+ CONFIG
192
+ end
171
193
 
194
+ it 'creates a table and inserts a record' do
195
+ drop_table('camel_case_this')
196
+ run_pipeline
197
+ expect(query('SELECT * FROM camel_case_this')).to match_array([{id: "1", app_name: "Web App", event: "camelCase this", inserted_at: a_kind_of(String), :meta_type => "XML"}])
198
+ expect(query('SELECT COUNT(1) FROM camel_case_this').first[:count]).to eq("1")
199
+ end
200
+ end
201
+
202
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-charrington
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - dconger
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-07-29 00:00:00.000000000 Z
13
+ date: 2019-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement