Class: Fluent::Plugin::UpiParser
- Inherits:
-
Parser
- Object
- Parser
- Fluent::Plugin::UpiParser
- Defined in:
- lib/fluent/plugin/parser_upi_logs.rb
Overview
Parser for UPI which supports prediction and router logs
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #parse(binary) {|time, JSON.parse(record.to_json({ preserve_proto_fieldnames: true }))| ... } ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/fluent/plugin/parser_upi_logs.rb', line 19 def configure(conf) super if Google::Protobuf::DescriptorPool.generated_pool.lookup(@class_name).nil? raise Fluent::ConfigError, "unrecognised class_name '#{class_name}'" end # Lookup will only work for proto that are declared by the require statements @protobuf_descriptor = Google::Protobuf::DescriptorPool.generated_pool.lookup(@class_name).msgclass end |
#parse(binary) {|time, JSON.parse(record.to_json({ preserve_proto_fieldnames: true }))| ... } ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/fluent/plugin/parser_upi_logs.rb', line 29 def parse(binary) record = @protobuf_descriptor.decode(binary) time = Fluent::EventTime.now # Record are returned in json format. 'to_h' is not used directly as it will retain all fields with zero value # '.to_json' will omit empty fields from the proto and then parsed with JSON lib puts time yield time, JSON.parse(record.to_json({ preserve_proto_fieldnames: true })) end |