logstash-output-charrington 0.3.0 → 0.3.1

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: a50e0dc6a545b094b6632682214046bedf1fe56842b17331c44b890157719ad6
4
- data.tar.gz: 1e64be923fef5c32b8a678052d76bf774dadf0214519f5a9aee87052638a90fd
3
+ metadata.gz: d16654dc603c8a1f7ad5e0c394c09c8a1bc018f040f81f22d16b2e13df0cba6d
4
+ data.tar.gz: 3d74abf0777655dbcd133dce2254dd6f026764ca31b0d76853d04c241f48bcfb
5
5
  SHA512:
6
- metadata.gz: 93f149aec77737579df06f0e82a49524bc49264d09d4938d67fed25a6b6606e495171f70863ca3b73fe7ea092097a64f43028411a2fb85ad58f5e9adc24c1f2b
7
- data.tar.gz: b277fd159871eae94471b3cc2329e5327a1904ccb5e1fffbc2c4f53d40f8b867ebe6346f38af374e3cd428307602a3712e05da5deab5a3eef451ed9733c3d3bf
6
+ metadata.gz: a2e8d0be10c3491ee93548351d898e631f2c5011e3b4998671aaa447ca77d07ee940dc4162d6ae6ae590bdac11bcdeed4574fa0d33b9d55c88caf7dd2022a4b4
7
+ data.tar.gz: 31eb24bbab66fbd069e723c684073fd1ce7c777146e538aab34709c2249a30eb45e543f1af75d1d80b38d6558cb6ff80bf008ee4468d3d4830250e66af24cd05
@@ -39,27 +39,17 @@ module Charrington
39
39
 
40
40
  def call
41
41
  insert_stmt = insert_statement
42
+
42
43
  stmt = connection.prepareStatement(insert_stmt)
43
44
  stmt = add_statement_event_params(stmt)
44
45
  stmt.execute
45
46
  should_retry
46
- rescue Java::OrgPostgresqlUtil::PSQLException => e
47
- case e.getSQLState()
48
- when "42P01"
49
- should_retry = Charrington::CreatePostgresTable.call(connection, event, schema, table_name, columns)
50
- when "42703"
51
- should_retry = Charrington::AlterPostgresTable.call(connection, event, schema, table_name, columns)
52
- else
53
- raise InsertFailed, "Charrington: Rescue from SQLException #{e.message}"
54
- end
55
- should_retry
56
47
  rescue Java::JavaSql::SQLException => e
57
- puts "catching SQLException #{e.message}"
58
48
  case e.getSQLState()
59
49
  when "42P01"
60
- should_retry = Charrington::CreateRedshiftTable.call(connection, event, schema, table_name, columns)
50
+ should_retry = create_table
61
51
  when "42703"
62
- should_retry = Charrington::AlterRedshiftTable.call(connection, event, schema, table_name, columns)
52
+ should_retry = alter_table
63
53
  else
64
54
  raise InsertFailed, "Charrington: Rescue from SQLException #{e.message}"
65
55
  end
@@ -74,6 +64,22 @@ module Charrington
74
64
 
75
65
  private
76
66
 
67
+ def create_table
68
+ if driver == "postgres"
69
+ Charrington::CreatePostgresTable.call(connection, event, schema, table_name, columns)
70
+ elsif driver == "redshift"
71
+ Charrington::CreateRedshiftTable.call(connection, event, schema, table_name, columns)
72
+ end
73
+ end
74
+
75
+ def alter_table
76
+ if driver == "postgres"
77
+ Charrington::AlterPostgresTable.call(connection, event, schema, table_name, columns)
78
+ elsif driver == "redshift"
79
+ Charrington::AlterRedshiftTable.call(connection, event, schema, table_name, columns)
80
+ end
81
+ end
82
+
77
83
  def cleanup
78
84
  @columns.clear if clearable(@columns)
79
85
  end
@@ -128,7 +128,7 @@ class LogStash::Outputs::Charrington < LogStash::Outputs::Base
128
128
  when /redshift/
129
129
  "redshift"
130
130
  else
131
- "postgresql"
131
+ "postgres"
132
132
  end
133
133
  end
134
134
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-charrington'
3
- s.version = '0.3.0'
3
+ s.version = '0.3.1'
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": "From Agent", "meta": { "type": "XML" } }'
12
+ message => '{"app_name": "Web App", "event": "schemaless", "meta": { "type": "XML" } }'
13
13
  codec => 'json'
14
14
  count => 1
15
15
  }
@@ -25,10 +25,10 @@ describe LogStash::Outputs::Charrington do
25
25
  end
26
26
 
27
27
  it 'creates a table and inserts a record' do
28
- drop_table('from_agent')
28
+ drop_table('schemaless')
29
29
  run_pipeline
30
- expect(query('SELECT * FROM from_agent')).to match_array([{id: "1", app_name: "Web App", event: "From Agent", inserted_at: a_kind_of(String), :meta_type => "XML"}])
31
- expect(query('SELECT COUNT(1) FROM from_agent').first[:count]).to eq("1")
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 COUNT(1) FROM schemaless').first[:count]).to eq("1")
32
32
  end
33
33
  end
34
34
 
@@ -38,8 +38,8 @@ describe LogStash::Outputs::Charrington do
38
38
  input {
39
39
  generator {
40
40
  lines => [
41
- '{"app_name": "Web App", "event": "From Agent", "meta": { "type": "XML" } }',
42
- '{"app_name": "Web App", "event": "From Agent", "meta": { "type": "XML", "file_name": "virus.pdf" } }'
41
+ '{"app_name": "Web App", "event": "metadata", "meta": { "type": "XML" } }',
42
+ '{"app_name": "Web App", "event": "metadata", "meta": { "type": "XML", "file_name": "virus.pdf" } }'
43
43
  ]
44
44
  codec => 'json'
45
45
  count => 1
@@ -56,13 +56,13 @@ describe LogStash::Outputs::Charrington do
56
56
  end
57
57
 
58
58
  it 'creates a table and inserts the first record and alters the table for the second record' do
59
- drop_table('from_agent')
59
+ drop_table('metadata')
60
60
  run_pipeline
61
- expect(query('SELECT * FROM from_agent')).to match_array([
62
- {app_name: 'Web App', event: 'From Agent', id: '1', inserted_at: a_kind_of(String), meta_file_name: nil, meta_type: 'XML'},
63
- {app_name: 'Web App', event: 'From Agent', id: '2', inserted_at: a_kind_of(String), meta_file_name: 'virus.pdf', meta_type: 'XML'}
61
+ expect(query('SELECT * FROM metadata')).to match_array([
62
+ {app_name: 'Web App', event: 'metadata', id: '1', inserted_at: a_kind_of(String), meta_file_name: nil, meta_type: 'XML'},
63
+ {app_name: 'Web App', event: 'metadata', id: '2', inserted_at: a_kind_of(String), meta_file_name: 'virus.pdf', meta_type: 'XML'}
64
64
  ])
65
- expect(query('SELECT COUNT(1) FROM from_agent').first[:count]).to eq("2")
65
+ expect(query('SELECT COUNT(1) FROM metadata').first[:count]).to eq("2")
66
66
  end
67
67
  end
68
68
 
@@ -71,7 +71,7 @@ describe LogStash::Outputs::Charrington do
71
71
  <<-CONFIG
72
72
  input {
73
73
  generator {
74
- message => '{"app_name": "Web App", "event": "From Agent", "meta": { "type": "XML" } }'
74
+ message => '{"app_name": "Web App", "event": "existing", "meta": { "type": "XML" } }'
75
75
  codec => 'json'
76
76
  count => 1
77
77
  }
@@ -88,15 +88,15 @@ describe LogStash::Outputs::Charrington do
88
88
 
89
89
  it 'can insert into an existing table' do
90
90
  # setup pre-existing data
91
- drop_table('from_agent')
92
- create_table('CREATE TABLE from_agent (id SERIAL PRIMARY KEY, inserted_at TIMESTAMP DEFAULT NOW(), app_name VARCHAR(255))')
93
- insert("INSERT INTO from_agent (app_name) VALUES ('Not Agent')")
94
- expect(query('SELECT * FROM from_agent')).to match_array([{id: "1", inserted_at: a_kind_of(String), app_name: "Not Agent"}])
91
+ drop_table('existing')
92
+ create_table('CREATE TABLE existing (id SERIAL PRIMARY KEY, inserted_at TIMESTAMP DEFAULT NOW(), app_name VARCHAR(255))')
93
+ insert("INSERT INTO existing (app_name) VALUES ('Not Agent')")
94
+ expect(query('SELECT * FROM existing')).to match_array([{id: "1", inserted_at: a_kind_of(String), app_name: "Not Agent"}])
95
95
 
96
96
  run_pipeline
97
- expect(query('SELECT * FROM from_agent')).to match_array([
97
+ expect(query('SELECT * FROM existing')).to match_array([
98
98
  {id: '1', app_name: 'Not Agent', event: nil, inserted_at: a_kind_of(String), meta_type: nil},
99
- {id: '2', app_name: 'Web App', event: 'From Agent', inserted_at: a_kind_of(String), meta_type: 'XML'}
99
+ {id: '2', app_name: 'Web App', event: 'existing', inserted_at: a_kind_of(String), meta_type: 'XML'}
100
100
  ])
101
101
  end
102
102
  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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dconger