ffwd-kafka 0.1.7 → 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd92cb26ba2f91f67dc006f07647f032c568104b
4
+ data.tar.gz: 4bebbf74c4d5f9f3636baada9ae758d598fb95c2
5
+ SHA512:
6
+ metadata.gz: 2d401625fccdcf2f8a4a603c60745e0d5787d72100c1c90fc9f66790c098701d013fcac355d76726a8d199508aa646d78ac0c610fbb283b817308c99cd14fa71
7
+ data.tar.gz: 0fb870d71df35ba0ebe49f243b0c151dc6033325cc1da5d5b6c9ea561cd232365fbdaf7d7f410fc708b06afe8328ccaed3448ab8f1d4064bcf3c73012b8adb87
@@ -29,12 +29,21 @@ module FFWD::Plugin::Kafka
29
29
 
30
30
  MAPPING = [:host, :ttl, :key, :time, :value, :tags, :attributes]
31
31
 
32
- def initialize producer, brokers, schema, router, partitioner
33
- @producer = producer
34
- @brokers = brokers
32
+ DEFAULT_PRODUCER = "ffwd"
33
+ DEFAULT_BROKERS = ["localhost:9092"]
34
+
35
+ def self.prepare config
36
+ config[:producer] ||= DEFAULT_PRODUCER
37
+ config[:brokers] ||= DEFAULT_BROKERS
38
+ config
39
+ end
40
+
41
+ def initialize schema, router, partitioner, config
35
42
  @schema = schema
36
43
  @router = router
37
44
  @partitioner = partitioner
45
+ @producer = config[:producer]
46
+ @brokers = config[:brokers]
38
47
  @reporter_meta = {:producer_type => "kafka", :producer => @producer}
39
48
  @instance = nil
40
49
  end
@@ -41,14 +41,14 @@ module FFWD::Plugin::Kafka
41
41
  ),
42
42
  ]
43
43
 
44
- def self.build opts
45
- attr = opts[:attribute] || DEFAULT_ATTRIBUTE
46
- new attr
44
+ def self.prepare config
45
+ config[:attribute] ||= DEFAULT_ATTRIBUTE
46
+ config
47
47
  end
48
48
 
49
- def initialize attr
50
- @attr = attr.to_sym
51
- @attr_s = attr.to_s
49
+ def initialize config
50
+ @attr = config[:attribute].to_sym
51
+ @attr_s = config[:attribute].to_s
52
52
  end
53
53
 
54
54
  # currently there is an issue where you can store both symbols and string
@@ -62,15 +62,19 @@ module FFWD::Plugin::Kafka
62
62
  end
63
63
  end
64
64
 
65
- def self.build_partitioner type, opts
66
- if type == :host
67
- return HostPartitioner
68
- end
65
+ DEFAULT_PARTITIONER = :host
69
66
 
70
- if type == :key
71
- return KeyPartitioner
72
- end
67
+ def self.prepare_partitioner config
68
+ type = (config[:type] ||= DEFAULT_PARTITIONER)
69
+ return config if type == :host
70
+ return config if type == :key
71
+ AttributePartitioner.prepare config
72
+ end
73
73
 
74
- return AttributePartitioner.build opts
74
+ def self.build_partitioner config
75
+ type = config[:type]
76
+ return HostPartitioner if type == :host
77
+ return KeyPartitioner if type == :key
78
+ return AttributePartitioner.new config
75
79
  end
76
80
  end
@@ -46,18 +46,25 @@ module FFWD::Plugin::Kafka
46
46
  ),
47
47
  ]
48
48
 
49
- def self.build opts
50
- metric_pattern = opts[:metric_pattern] || DEFAULT_METRIC_PATTERN
51
- event_pattern = opts[:event_pattern] || DEFAULT_EVENT_PATTERN
52
- attr = opts[:attribute] || DEFAULT_ATTRIBUTE
49
+ def self.prepare config
50
+ config[:metric_pattern] ||= DEFAULT_METRIC_PATTERN
51
+ config[:event_pattern] ||= DEFAULT_EVENT_PATTERN
52
+ config[:attribute] ||= DEFAULT_ATTRIBUTE
53
+ config
54
+ end
55
+
56
+ def self.build config
57
+ metric_pattern = config[:metric_pattern] || DEFAULT_METRIC_PATTERN
58
+ event_pattern = config[:event_pattern] || DEFAULT_EVENT_PATTERN
59
+ attr = config[:attribute] || DEFAULT_ATTRIBUTE
53
60
  new(metric_pattern, event_pattern, attr)
54
61
  end
55
62
 
56
- def initialize metric_pattern, event_pattern, attr
57
- @metric_pattern = metric_pattern
58
- @event_pattern = event_pattern
59
- @attr = attr.to_sym
60
- @attr_s = attr.to_s
63
+ def initialize config
64
+ @metric_pattern = config[:metric_pattern]
65
+ @event_pattern = config[:event_pattern]
66
+ @attr = config[:attribute]
67
+ @attr_s = @attr.to_s
61
68
  end
62
69
 
63
70
  def value d
@@ -79,11 +86,17 @@ module FFWD::Plugin::Kafka
79
86
  end
80
87
  end
81
88
 
82
- def self.build_router type, opts
83
- if type == :attribute
84
- return AttributeRouter.build opts
85
- end
89
+ DEFAULT_ROUTER = :attribute
90
+
91
+ def self.prepare_router config
92
+ type = (config[:type] ||= DEFAULT_ROUTER)
93
+ return AttributeRouter.prepare config if type == :attribute
94
+ raise "Unsupported router type: #{type}"
95
+ end
86
96
 
97
+ def self.build_router config
98
+ type = config[:type]
99
+ return AttributeRouter.new config if type == :attribute
87
100
  raise "Unsupported router type: #{type}"
88
101
  end
89
102
  end
@@ -16,7 +16,7 @@
16
16
  module FFWD
17
17
  module Plugin
18
18
  module Kafka
19
- VERSION = "0.1.7"
19
+ VERSION = "0.2.0"
20
20
  end
21
21
  end
22
22
  end
@@ -28,24 +28,19 @@ module FFWD::Plugin
28
28
  include FFWD::Plugin
29
29
  include FFWD::Logging
30
30
 
31
- DEFAULT_PRODUCER = "ffwd"
32
- DEFAULT_BROKERS = ["localhost:9092"]
33
- DEFAULT_PARTITIONER = :host
34
- DEFAULT_ROUTER = :attribute
35
-
36
31
  register_plugin "kafka",
37
32
  :description => "A plugin for the collectd binary protocol.",
38
33
  :options => [
39
34
  FFWD::Plugin.option(
40
- :producer, :default => DEFAULT_PRODUCER,
35
+ :producer, :default => FFWD::Plugin::Kafka::Output::DEFAULT_PRODUCER,
41
36
  :help => ["Name of the producer."]
42
37
  ),
43
38
  FFWD::Plugin.option(
44
- :port, :default => DEFAULT_BROKERS,
39
+ :port, :default => FFWD::Plugin::Kafka::Output::DEFAULT_BROKERS,
45
40
  :help => ["Brokers to connect to."]
46
41
  ),
47
42
  FFWD::Plugin.option(
48
- :partitioner, :default => DEFAULT_PARTITIONER,
43
+ :partitioner, :default => FFWD::Plugin::Kafka::DEFAULT_PARTITIONER,
49
44
  :help => [
50
45
  "Partitioner to use, the partitioner decides what partition key is used for a specific message.",
51
46
  ":host - Base partition key of the host of the event/metric.",
@@ -54,7 +49,7 @@ module FFWD::Plugin
54
49
  ]
55
50
  ),
56
51
  FFWD::Plugin.option(
57
- :router, :default => DEFAULT_ROUTER,
52
+ :router, :default => FFWD::Plugin::Kafka::DEFAULT_ROUTER,
58
53
  :help => [
59
54
  "Router to use, the router decides which topic to use for a specific message."
60
55
  ]
@@ -63,17 +58,29 @@ module FFWD::Plugin
63
58
  FFWD::Plugin::Kafka::AttributePartitioner::OPTIONS +
64
59
  FFWD::Plugin::Kafka::AttributeRouter::OPTIONS
65
60
 
66
- def self.setup_output opts, core
67
- producer = opts[:producer] || DEFAULT_PRODUCER
68
- brokers = opts[:brokers] || DEFAULT_BROKERS
69
- partitioner = FFWD::Plugin::Kafka.build_partitioner(
70
- opts[:partitioner] || DEFAULT_PARTITIONER, opts)
71
- router = FFWD::Plugin::Kafka.build_router(
72
- opts[:router] || DEFAULT_ROUTER, opts)
73
- schema = FFWD.parse_schema opts
61
+ class Setup
62
+ attr_reader :config
63
+
64
+ def initialize config
65
+ @config = Output.prepare Hash[config]
66
+ @config = FFWD.prepare_schema @config
67
+ @config[:partitioner] = FFWD::Plugin::Kafka.prepare_partitioner(
68
+ @config[:partitioner] || {})
69
+ @config[:router] = FFWD::Plugin::Kafka.prepare_router(
70
+ @config[:router] || {})
71
+ end
72
+
73
+ def connect core
74
+ partitioner = FFWD::Plugin::Kafka.build_partitioner @config[:partitioner]
75
+ router = FFWD::Plugin::Kafka.build_router @config[:router]
76
+ schema = FFWD.parse_schema @config
77
+ output = Output.new schema, router, partitioner, @config
78
+ FFWD.producing_client core.output, output, @config
79
+ end
80
+ end
74
81
 
75
- producer = Output.new producer, brokers, schema, router, partitioner
76
- FFWD.producing_client core.output, producer, opts
82
+ def self.setup_output config
83
+ Setup.new config
77
84
  end
78
85
  end
79
86
  end
metadata CHANGED
@@ -1,48 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffwd-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - John-John Tedro
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: poseidon
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ffwd
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '='
36
32
  - !ruby/object:Gem::Version
37
- version: 0.1.7
33
+ version: 0.2.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '='
44
39
  - !ruby/object:Gem::Version
45
- version: 0.1.7
40
+ version: 0.2.0
46
41
  description:
47
42
  email:
48
43
  - udoprog@spotify.com
@@ -50,35 +45,34 @@ executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
53
- - lib/ffwd/plugin/kafka.rb
54
- - lib/ffwd/plugin/kafka/version.rb
48
+ - lib/ffwd/plugin/kafka/output.rb
55
49
  - lib/ffwd/plugin/kafka/producer.rb
56
- - lib/ffwd/plugin/kafka/partitioners.rb
57
50
  - lib/ffwd/plugin/kafka/routers.rb
58
- - lib/ffwd/plugin/kafka/output.rb
51
+ - lib/ffwd/plugin/kafka/version.rb
52
+ - lib/ffwd/plugin/kafka/partitioners.rb
53
+ - lib/ffwd/plugin/kafka.rb
59
54
  homepage: https://github.com/spotify/ffwd
60
55
  licenses:
61
56
  - Apache 2.0
57
+ metadata: {}
62
58
  post_install_message:
63
59
  rdoc_options: []
64
60
  require_paths:
65
61
  - lib
66
62
  required_ruby_version: !ruby/object:Gem::Requirement
67
- none: false
68
63
  requirements:
69
- - - ! '>='
64
+ - - '>='
70
65
  - !ruby/object:Gem::Version
71
66
  version: '0'
72
67
  required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
68
  requirements:
75
- - - ! '>='
69
+ - - '>='
76
70
  - !ruby/object:Gem::Version
77
71
  version: '0'
78
72
  requirements: []
79
73
  rubyforge_project:
80
- rubygems_version: 1.8.23
74
+ rubygems_version: 2.0.3
81
75
  signing_key:
82
- specification_version: 3
76
+ specification_version: 4
83
77
  summary: Kafka support for FFWD.
84
78
  test_files: []