Class: FFWD::Plugin::Kafka::AttributeRouter
- Inherits:
-
Object
- Object
- FFWD::Plugin::Kafka::AttributeRouter
- Defined in:
- lib/ffwd/plugin/kafka/routers.rb
Overview
Use a custom attribute for partitioning.
Constant Summary collapse
- DEFAULT_METRIC_PATTERN =
"metrics-%s"
- DEFAULT_EVENT_PATTERN =
"events-%s"
- DEFAULT_ATTRIBUTE =
:site
- OPTIONS =
[ FFWD::Plugin.option( :metric_pattern, :default => DEFAULT_METRIC_PATTERN, :help => [ "Only used with :attribute router.", "Metric pattern to use, expects one %s placeholder for the value of the specified attribute." ] ), FFWD::Plugin.option( :event_pattern, :default => DEFAULT_METRIC_PATTERN, :help => [ "Only used with :attribute router.", "Event pattern to use, expects one %s placeholder for the value of the specified attribute." ] ), FFWD::Plugin.option( :attribute, :default => DEFAULT_ATTRIBUTE, :help => [ "Only used with :attribute router.", "Attribute name to use in pattern when router is :attribute." ] ), ]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config) ⇒ AttributeRouter
constructor
A new instance of AttributeRouter.
- #route_event(e) ⇒ Object
- #route_metric(m) ⇒ Object
- #value(d) ⇒ Object
Constructor Details
#initialize(config) ⇒ AttributeRouter
Returns a new instance of AttributeRouter.
63 64 65 66 67 68 |
# File 'lib/ffwd/plugin/kafka/routers.rb', line 63 def initialize config @metric_pattern = config[:metric_pattern] @event_pattern = config[:event_pattern] @attr = config[:attribute] @attr_s = @attr.to_s end |
Class Method Details
.build(config) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ffwd/plugin/kafka/routers.rb', line 56 def self.build config metric_pattern = config[:metric_pattern] || DEFAULT_METRIC_PATTERN event_pattern = config[:event_pattern] || DEFAULT_EVENT_PATTERN attr = config[:attribute] || DEFAULT_ATTRIBUTE new(metric_pattern, event_pattern, attr) end |
.prepare(config) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/ffwd/plugin/kafka/routers.rb', line 49 def self.prepare config config[:metric_pattern] ||= DEFAULT_METRIC_PATTERN config[:event_pattern] ||= DEFAULT_EVENT_PATTERN config[:attribute] ||= DEFAULT_ATTRIBUTE config end |
Instance Method Details
#route_event(e) ⇒ Object
78 79 80 81 |
# File 'lib/ffwd/plugin/kafka/routers.rb', line 78 def route_event e return nil unless v = value(e) @event_pattern % [v] end |
#route_metric(m) ⇒ Object
83 84 85 86 |
# File 'lib/ffwd/plugin/kafka/routers.rb', line 83 def route_metric m return nil unless v = value(m) @metric_pattern % [v] end |
#value(d) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/ffwd/plugin/kafka/routers.rb', line 70 def value d if v = d.attributes[@attr] return v end d.attributes[@attr_s] end |