fluent-plugin-nsq 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ # coding: utf-8
2
+
3
+ module Fluent
4
+ class NSQInput < Input
5
+ Plugin.register_input('nsq', self)
6
+
7
+ config_param :topic, :string, default: nil
8
+ config_param :channel, :string, default: 'fluent_nsq_input'
9
+ config_param :nsqlookupd, :string, default: nil
10
+ config_param :tag, :string, default: '_key'
11
+ config_param :time_key, :string, default: nil
12
+ config_param :tag_source, default: :key do |val|
13
+ case val.downcase
14
+ when 'key'
15
+ :key
16
+ when 'topic'
17
+ :topic
18
+ when 'static'
19
+ :static
20
+ else
21
+ fail ConfigError, 'tag_source should be either "key", "static" or "topic"'
22
+ end
23
+ end
24
+
25
+ def initialize
26
+ super
27
+ require 'cool.io'
28
+ require 'nsq'
29
+ end
30
+
31
+ def configure(conf)
32
+ super
33
+
34
+ fail ConfigError, 'Missing nsqlookupd' unless @nsqlookupd
35
+ fail ConfigError, 'Missing topic' unless @topic
36
+ fail ConfigError, 'Missing channel' unless @channel
37
+ end
38
+
39
+ def start
40
+ super
41
+ lookupds = @nsqlookupd.split(',')
42
+ @consumer = Nsq::Consumer.new(
43
+ nsqlookupd: lookupds,
44
+ topic: @topic,
45
+ channel: @channel
46
+ )
47
+ @running = true
48
+ @thread = Thread.new(&method(:consume))
49
+ end
50
+
51
+ def shutdown
52
+ super
53
+ @running = false
54
+ @consumer.terminate
55
+ end
56
+
57
+ private
58
+ def consume
59
+ while @running
60
+ consume_one
61
+ end
62
+ end
63
+
64
+ def consume_one
65
+ msg = @consumer.pop
66
+ record = JSON.parse(msg.body)
67
+ record_tag = tag_for_record(record)
68
+ record_time = time_for_record(record, msg)
69
+ Engine.emit(record_tag, record_time, record)
70
+ msg.finish
71
+ rescue => e
72
+ log.warn("nsq: #{e}")
73
+ msg.requeue if msg
74
+ end
75
+
76
+ def tag_for_record(record)
77
+ case @tag_source
78
+ when :static
79
+ @tag
80
+ when :key
81
+ record[@tag]
82
+ when :topic
83
+ @topic
84
+ end
85
+ end
86
+
87
+ def time_for_record(record, msg)
88
+ if @time_key
89
+ record[@time_key]
90
+ else
91
+ msg.timestamp
92
+ end
93
+ end
94
+ end
95
+ end
@@ -1,5 +1,4 @@
1
1
  # coding: utf-8
2
- require 'nsq'
3
2
 
4
3
  module Fluent
5
4
  class NSQOutput < BufferedOutput
@@ -10,6 +9,7 @@ module Fluent
10
9
 
11
10
  def initialize
12
11
  super
12
+ require 'nsq'
13
13
  end
14
14
 
15
15
  def configure(conf)
@@ -0,0 +1,65 @@
1
+ require 'test/unit'
2
+
3
+ require 'fluent/test'
4
+ require 'fluent/plugin/in_nsq'
5
+
6
+ require 'date'
7
+
8
+ require 'helper'
9
+
10
+ $:.push File.expand_path("../lib", __FILE__)
11
+ $:.push File.dirname(__FILE__)
12
+
13
+ class TestNSQInput < Test::Unit::TestCase
14
+ TCONFIG = %[
15
+ nsqlookupd localhost:4161
16
+ topic logs_in
17
+ time_key _ts
18
+ ]
19
+ def setup
20
+ #Nsq.logger = Logger.new(STDOUT)
21
+ Fluent::Test.setup
22
+ end
23
+
24
+ def test_configure
25
+ d = create_driver
26
+ assert_not_nil d.instance.topic
27
+ end
28
+
29
+ def create_driver(conf=TCONFIG)
30
+ Fluent::Test::InputTestDriver.new(Fluent::NSQInput).configure(conf)
31
+ end
32
+
33
+ def create_producer
34
+ Nsq::Producer.new(
35
+ nsqlookupd: ['127.0.0.1:4161'],
36
+ topic: 'logs_in'
37
+ )
38
+ end
39
+
40
+ def sample_record
41
+ {_ts: Time.now, _key: 'somekey', age:26, request_id: '42', parent_id: 'parent', sub: {field: {pos: 15}}}
42
+ end
43
+
44
+ def test_wrong_config
45
+ assert_raise Fluent::ConfigError do
46
+ create_driver('')
47
+ end
48
+ end
49
+
50
+ def test_sample_record_loop
51
+ d = create_driver
52
+ d.run do
53
+ prod = create_producer
54
+ sleep(1)
55
+ prod.write(sample_record.to_json)
56
+ prod.write(sample_record.to_json)
57
+ prod.write(sample_record.to_json)
58
+ prod.write(sample_record.to_json)
59
+ sleep(1)
60
+ prod.terminate
61
+ end
62
+ puts("emitz")
63
+ puts(d.emits)
64
+ end
65
+ end
@@ -13,7 +13,7 @@ $:.push File.dirname(__FILE__)
13
13
  class TestNSQOutput < Test::Unit::TestCase
14
14
  TCONFIG = %[
15
15
  nsqlookupd localhost:4161
16
- topic logs
16
+ topic logs_out
17
17
  ]
18
18
  def setup
19
19
  #Nsq.logger = Logger.new(STDOUT)
@@ -35,7 +35,7 @@ class TestNSQOutput < Test::Unit::TestCase
35
35
 
36
36
  def test_wrong_config
37
37
  assert_raise Fluent::ConfigError do
38
- d = create_driver('test','')
38
+ create_driver('test','')
39
39
  end
40
40
  end
41
41
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-nsq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - lxfontes
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-11-05 00:00:00.000000000 Z
13
+ date: 2014-11-13 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: fluentd
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ~>
19
21
  - !ruby/object:Gem::Version
@@ -21,6 +23,7 @@ dependencies:
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ~>
26
29
  - !ruby/object:Gem::Version
@@ -28,6 +31,7 @@ dependencies:
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: nsq-ruby
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
36
  - - ~>
33
37
  - !ruby/object:Gem::Version
@@ -35,6 +39,7 @@ dependencies:
35
39
  type: :runtime
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ~>
40
45
  - !ruby/object:Gem::Version
@@ -42,6 +47,7 @@ dependencies:
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: rake
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
52
  - - ~>
47
53
  - !ruby/object:Gem::Version
@@ -49,6 +55,7 @@ dependencies:
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
60
  - - ~>
54
61
  - !ruby/object:Gem::Version
@@ -62,33 +69,37 @@ extensions: []
62
69
  extra_rdoc_files: []
63
70
  files:
64
71
  - fluent-plugin-nsq.gemspec
72
+ - lib/fluent/plugin/in_nsq.rb
65
73
  - lib/fluent/plugin/out_nsq.rb
66
74
  - test/helper.rb
75
+ - test/plugin/test_in_nsq.rb
67
76
  - test/plugin/test_out_nsq.rb
68
77
  homepage: https://github.com/uken/fluent-plugin-nsq
69
78
  licenses:
70
79
  - MIT
71
- metadata: {}
72
80
  post_install_message:
73
81
  rdoc_options: []
74
82
  require_paths:
75
83
  - lib
76
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
77
86
  requirements:
78
87
  - - ! '>='
79
88
  - !ruby/object:Gem::Version
80
89
  version: '0'
81
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
82
92
  requirements:
83
93
  - - ! '>='
84
94
  - !ruby/object:Gem::Version
85
95
  version: '0'
86
96
  requirements: []
87
97
  rubyforge_project:
88
- rubygems_version: 2.3.0
98
+ rubygems_version: 1.8.23
89
99
  signing_key:
90
- specification_version: 4
100
+ specification_version: 3
91
101
  summary: output plugin for fluentd
92
102
  test_files:
93
103
  - test/helper.rb
104
+ - test/plugin/test_in_nsq.rb
94
105
  - test/plugin/test_out_nsq.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODc2NjIxMzUyYWVmZDY1MDYyMTk0ODQwMDczNjE3ZDM0Y2QxNzA1Yg==
5
- data.tar.gz: !binary |-
6
- MTFmYjVkODU5M2VkYjg2MzFmYjY5YjM0MWUzZTc0ZTdlYWQ0NzNhOA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- YTkwMzgyMjc4NTlhM2ZkYjE5N2JlMzFjNDQxZWFjZDNlYjcyNDZhM2FmM2E4
10
- ZTJhMGIwMDc5ZGQyYTE5MjY1YWNhMmMxNWRkMWJiYjIyNDllMzFiNmY5MTA2
11
- NjQ2MWI1YzBjYzkwYzAyNzAzMDdmNDkyYzNjYzY1NjIxMWQ2ZTI=
12
- data.tar.gz: !binary |-
13
- OGFiMzg0N2ZiYzJmOGRkM2Y3ZTIwZWEwYTE5NmYxM2FkZDRlNzdjZTEzM2Zj
14
- NjFiM2YyM2M3ZDRhZDI5NzA5NGIxNjI5NTU4NzU5NGFmNmM2YTQ4MDRlMjky
15
- ZWRkMjcyMzg0ZWU5YTIzOGUxODMyNDZiN2VmZTcxMzE0ZmRkZjE=