logstash-input-twitter 4.0.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/logstash/inputs/twitter.rb +16 -11
- data/lib/logstash/inputs/twitter/patches.rb +28 -0
- data/logstash-input-twitter.gemspec +1 -1
- data/spec/inputs/twitter_spec.rb +26 -3
- data/spec/integration/twitter_spec.rb +16 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a556dabd75cd5e9260c327a7bdffa6bfe5e7fe4f80457901505953d7dc31f2
|
4
|
+
data.tar.gz: c83225608136218ea6b950f158fcd1983b3455c533f37a4f01d768b1e6dc03e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cced602c79e40db401fb8a2547fc2a4756a9680b62ce31852f953bcc7a17942076378e04e403505403152f8d751b9a61f90d643ff406aa3cbc90e23438291fbe
|
7
|
+
data.tar.gz: 7e2cef7a66efcd33566dab11d6e293b07a6a3458d22c66372b28f63dcec676dcba2fff6e63c5aec7f41836109afda8d4233f1a4c7e76625c4bbbd8fff71c8900
|
data/CHANGELOG.md
CHANGED
@@ -128,17 +128,7 @@ class LogStash::Inputs::Twitter < LogStash::Inputs::Base
|
|
128
128
|
@event_generation_error_count = 0
|
129
129
|
|
130
130
|
begin
|
131
|
-
|
132
|
-
@stream_client.sample do |tweet|
|
133
|
-
return if stop?
|
134
|
-
tweet_processor(queue, tweet)
|
135
|
-
end
|
136
|
-
else
|
137
|
-
@stream_client.filter(twitter_options) do |tweet|
|
138
|
-
return if stop?
|
139
|
-
tweet_processor(queue, tweet)
|
140
|
-
end
|
141
|
-
end
|
131
|
+
do_run(queue)
|
142
132
|
rescue Twitter::Error::TooManyRequests => e
|
143
133
|
sleep_for = e.rate_limit.reset_in || @rate_limit_reset_in # 5 minutes default value from config
|
144
134
|
@logger.warn("Twitter too many requests error, sleeping for #{sleep_for}s")
|
@@ -151,6 +141,21 @@ class LogStash::Inputs::Twitter < LogStash::Inputs::Base
|
|
151
141
|
end
|
152
142
|
end # def run
|
153
143
|
|
144
|
+
def do_run(queue)
|
145
|
+
if @use_samples
|
146
|
+
@stream_client.sample do |tweet|
|
147
|
+
return if stop?
|
148
|
+
tweet_processor(queue, tweet)
|
149
|
+
end
|
150
|
+
else
|
151
|
+
@stream_client.filter(twitter_options) do |tweet|
|
152
|
+
return if stop?
|
153
|
+
tweet_processor(queue, tweet)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
private :do_run
|
158
|
+
|
154
159
|
def stop
|
155
160
|
@stream_client = nil
|
156
161
|
end
|
@@ -8,16 +8,23 @@ module LogStash
|
|
8
8
|
def self.patch
|
9
9
|
verify_version
|
10
10
|
patch_json
|
11
|
+
patch_http_request
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
15
16
|
def self.verify_version
|
16
17
|
raise("Incompatible Twitter gem version and the LogStash::Json.load") unless ::Twitter::Version.to_s == "6.2.0"
|
18
|
+
# NOTE: we're also known to work with twitter gem version 7.0 which uses http 4.x
|
19
|
+
raise("Incompatible HTTP gem version: #{HTTP::VERSION}") if HTTP::VERSION >= '5.0' || HTTP::VERSION < '3.0'
|
20
|
+
# after a major upgrade, unless CI is running integration specs, please run integration specs manually
|
17
21
|
end
|
18
22
|
|
19
23
|
def self.patch_json
|
20
24
|
::Twitter::Streaming::Response.module_eval do
|
25
|
+
unless method_defined? :on_body
|
26
|
+
raise "::Twitter::Streaming::Response#on_body not defined!" # patch bellow needs a review
|
27
|
+
end
|
21
28
|
def on_body(data)
|
22
29
|
@tokenizer.extract(data).each do |line|
|
23
30
|
next if line.empty?
|
@@ -31,6 +38,27 @@ module LogStash
|
|
31
38
|
end
|
32
39
|
end
|
33
40
|
|
41
|
+
def self.patch_http_request
|
42
|
+
# NOTE: we might decide to drop the patch at some point, for now proxies such as squid
|
43
|
+
# are opinionated about having full URIs in the http head-line (having only /path fails
|
44
|
+
# with 400 Bad Request in Squid 4.10).
|
45
|
+
::HTTP::Request.class_eval do
|
46
|
+
unless method_defined? :headline
|
47
|
+
raise "::HTTP::Request#headline not defined!" # patch bellow needs a review
|
48
|
+
end
|
49
|
+
def headline
|
50
|
+
request_uri =
|
51
|
+
if using_proxy? #&& !uri.https?
|
52
|
+
uri.omit(:fragment)
|
53
|
+
else
|
54
|
+
uri.request_uri
|
55
|
+
end
|
56
|
+
|
57
|
+
"#{verb.to_s.upcase} #{request_uri} HTTP/#{version}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
34
62
|
end
|
35
63
|
end
|
36
64
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-twitter'
|
3
|
-
s.version = '4.0.
|
3
|
+
s.version = '4.0.3'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "Reads events from the Twitter Streaming API"
|
6
6
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
data/spec/inputs/twitter_spec.rb
CHANGED
@@ -15,6 +15,8 @@ describe LogStash::Inputs::Twitter do
|
|
15
15
|
|
16
16
|
let(:plugin) { LogStash::Inputs::Twitter.new(config) }
|
17
17
|
|
18
|
+
let(:queue) { Queue.new }
|
19
|
+
|
18
20
|
describe "registration" do
|
19
21
|
|
20
22
|
it "not raise error" do
|
@@ -70,7 +72,6 @@ describe LogStash::Inputs::Twitter do
|
|
70
72
|
describe "fetching from sample" do
|
71
73
|
|
72
74
|
let(:input) { LogStash::Inputs::Twitter.new(config) }
|
73
|
-
let(:queue) { Queue.new }
|
74
75
|
|
75
76
|
let(:config) do
|
76
77
|
{
|
@@ -142,8 +143,6 @@ describe LogStash::Inputs::Twitter do
|
|
142
143
|
|
143
144
|
let(:input) { LogStash::Inputs::Twitter.new(config) }
|
144
145
|
|
145
|
-
let(:queue) { Queue.new }
|
146
|
-
|
147
146
|
let(:stream_client) { double("stream-client") }
|
148
147
|
|
149
148
|
let(:options) do
|
@@ -212,5 +211,29 @@ describe LogStash::Inputs::Twitter do
|
|
212
211
|
end
|
213
212
|
|
214
213
|
end
|
214
|
+
|
215
|
+
describe "proxy" do
|
216
|
+
|
217
|
+
before(:each) do
|
218
|
+
plugin.register
|
219
|
+
end
|
220
|
+
|
221
|
+
let(:config) do
|
222
|
+
super.merge( 'use_proxy' => true, 'proxy_address' => '127.0.0.1', 'proxy_port' => 12345 )
|
223
|
+
end
|
224
|
+
|
225
|
+
let(:proxy_socket) { double('proxy-socket') }
|
226
|
+
|
227
|
+
it "sends full URI requests" do
|
228
|
+
allow_any_instance_of(Twitter::Streaming::Connection).
|
229
|
+
to receive(:new_tcp_socket).with('127.0.0.1', 12345).and_return(proxy_socket)
|
230
|
+
header_line = 'POST https://stream.twitter.com/1.1/statuses/filter.json?track=foo%2Cbar HTTP/1.1'
|
231
|
+
expect(proxy_socket).to receive(:write).with(/^#{Regexp.escape(header_line)}/).
|
232
|
+
and_return(3000) # let the stack assume all content sent was consumed
|
233
|
+
# NOTE: this is just bogus - we're really just testing the HTTP header line ...
|
234
|
+
expect(proxy_socket).to receive(:readpartial).and_return nil
|
235
|
+
plugin.send(:do_run, queue)
|
236
|
+
end
|
237
|
+
end
|
215
238
|
end
|
216
239
|
end
|
@@ -5,6 +5,16 @@ require_relative "../spec_helper"
|
|
5
5
|
|
6
6
|
describe LogStash::Inputs::Twitter do
|
7
7
|
|
8
|
+
let(:events) do
|
9
|
+
input(config) do |_, queue|
|
10
|
+
event_count.times.collect { queue.pop }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:event_count) { 3 }
|
15
|
+
|
16
|
+
let(:event) { events.first }
|
17
|
+
|
8
18
|
describe "#receive [integration]", :integration => true do
|
9
19
|
|
10
20
|
context "keyword search" do
|
@@ -23,12 +33,6 @@ describe LogStash::Inputs::Twitter do
|
|
23
33
|
CONFIG
|
24
34
|
end
|
25
35
|
|
26
|
-
let(:events) do
|
27
|
-
input(config) do |pipeline, queue|
|
28
|
-
3.times.collect { queue.pop }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
36
|
it "receive a list of events from the twitter stream" do
|
33
37
|
expect(events.count).to eq(3)
|
34
38
|
end
|
@@ -49,28 +53,14 @@ describe LogStash::Inputs::Twitter do
|
|
49
53
|
CONFIG
|
50
54
|
end
|
51
55
|
|
52
|
-
let(:events) do
|
53
|
-
input(config) do |pipeline, queue|
|
54
|
-
3.times.collect { queue.pop }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
let(:event) { events.first }
|
59
|
-
|
60
56
|
it "receive a list of events from the twitter stream" do
|
61
57
|
expect(events.count).to eq(3)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "contains the hashtags" do
|
65
|
-
expect(event["hashtags"]).to be_truthy
|
66
|
-
end
|
67
58
|
|
68
|
-
|
69
|
-
expect(event["symbols"]).to be_truthy
|
70
|
-
end
|
59
|
+
event.tap { |event| puts "sample event: #{event.to_hash}" } if $VERBOSE
|
71
60
|
|
72
|
-
|
73
|
-
expect(event
|
61
|
+
expect(event.get("hashtags")).to be_truthy
|
62
|
+
expect(event.get("symbols")).to be_truthy
|
63
|
+
expect(event.get("user_mentions")).to be_truthy
|
74
64
|
end
|
75
65
|
|
76
66
|
end
|
@@ -88,20 +78,15 @@ describe LogStash::Inputs::Twitter do
|
|
88
78
|
full_tweet => true
|
89
79
|
use_proxy => true
|
90
80
|
proxy_address => '127.0.0.1'
|
91
|
-
proxy_port =>
|
81
|
+
proxy_port => 3128
|
92
82
|
}
|
93
83
|
}
|
94
84
|
CONFIG
|
95
85
|
end
|
96
86
|
|
97
|
-
let(:events) do
|
98
|
-
input(config) do |pipeline, queue|
|
99
|
-
3.times.collect { queue.pop }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
87
|
it "receive a list of events from the twitter stream" do
|
104
88
|
expect(events.count).to eq(3)
|
89
|
+
event.tap { |event| puts "sample event (using proxy): #{event.to_hash}" } if $VERBOSE
|
105
90
|
end
|
106
91
|
end
|
107
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-twitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|