Engine does not emit msgs read from kafka to elasticseasrch
I use fluent-plugin-kafka to fetch text messages from kafka and fluent-plugin-elasticsearch to deliver ElasticSearch as a centralized logging solution, fluentd engine seems not working for our case, however, use a file input or output plugin with them separately works fine.
Specifically, following two cases work fine:
- Read message from a file, and output to ES
- Read message from kafka, and output to a file
This does not work, and the output plugin does not even try to connect the ES host according to netstat:
- Read message from kafka, and output to ES
td-agent -vv does not produce debug message for me, so I added lots of logging into the code, but unable to locate the root cause, it looks like a bug inside the engine code somewhere to me. I am attaching my debug log, hope to get some clue here. Thanks!
Versions:
- CentOS 6.5
- td-agent-2.2.1-0.el6.x86_64
- fluent-plugin-kafka-0.0.15
- fluent-plugin-elasticsearch-1.0.0
/var/log/td-agent/td-agent.log:
2015-08-26 20:39:33 +0800 [info]: fluent/supervisor.rb:403:read_config: reading config file path="/etc/td-agent/td-agent.conf"
2015-08-26 20:39:33 +0800 [info]: fluent/supervisor.rb:279:supervise: starting fluentd-0.12.12
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered buffer plugin 'file'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered buffer plugin 'memory'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered filter plugin 'grep'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered filter plugin 'record_transformer'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered filter plugin 'stdout'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'debug_agent'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'dummy'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'exec'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'forward'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'gc_stat'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'http'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'monitor_agent'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'object_space'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'status'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'unix'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'syslog'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'tail'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'tcp'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'udp'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'copy'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'exec'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'exec_filter'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'file'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'forward'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'null'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'relabel'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'roundrobin'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'stdout'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'tcp'
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'unix'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-mixin-config-placeholders' version '0.3.0'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-mixin-plaintextformatter' version '0.2.6'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-debug' version '0.0.2'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-elasticsearch' version '1.0.0'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-kafka' version '0.0.15'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-mongo' version '0.7.10'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-rewrite-tag-filter' version '1.4.1'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-s3' version '0.5.9'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-scribe' version '0.10.14'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-td' version '0.10.27'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-td-monitoring' version '0.2.1'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluent-plugin-webhdfs' version '0.4.1'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:94:block in configure: gem 'fluentd' version '0.12.12'
2015-08-26 20:39:33 +0800 [info]: fluent/agent.rb:123:add_match: adding match pattern="debug.**" type="stdout"
2015-08-26 20:39:33 +0800 [info]: fluent/agent.rb:123:add_match: adding match pattern="applog" type="copy"
2015-08-26 20:39:33 +0800 [debug]: plugin/out_copy.rb:42:block in configure: adding store type="elasticsearch"
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered output plugin 'elasticsearch'
2015-08-26 20:39:33 +0800 [info]: fluent/agent.rb:123:add_match: adding match pattern="syslog" type="copy"
2015-08-26 20:39:33 +0800 [debug]: plugin/out_copy.rb:42:block in configure: adding store type="elasticsearch"
2015-08-26 20:39:33 +0800 [info]: fluent/root_agent.rb:142:add_source: adding source type="tail"
2015-08-26 20:39:33 +0800 [warn]: plugin/in_tail.rb:47:configure: 'pos_file PATH' parameter is not set to a 'tail' source.
2015-08-26 20:39:33 +0800 [warn]: plugin/in_tail.rb:48:configure: this parameter is highly recommended to save the position to resume tailing.
2015-08-26 20:39:33 +0800 [info]: fluent/root_agent.rb:142:add_source: adding source type="kafka"
2015-08-26 20:39:33 +0800 [trace]: fluent/plugin.rb:98:register_impl: registered input plugin 'kafka'
2015-08-26 20:39:33 +0800 [info]: fluent/engine.rb:101:configure: using configuration file: <ROOT>
<match debug.**>
type stdout
</match>
<source>
type tail
format none
path /var/log/tdtest.log
tag syslog
</source>
<source>
type kafka
host 192.168.159.116
port 9092
topics applog
format text
</source>
<match applog>
type copy
<store>
type elasticsearch
host 192.168.172.31
port 9200
type_name fluentd
index_name fluentd
logstash_format true
flush_interval 1s
</store>
</match>
<match syslog>
type copy
<store>
type elasticsearch
host 192.168.172.31
port 9200
type_name fluentd
index_name fluentd
logstash_format true
flush_interval 1s
</store>
</match>
</ROOT>
2015-08-26 20:39:33 +0800 [info]: plugin/in_tail.rb:477:initialize: following tail of /var/log/tdtest.log
Some output from my debug logging code, hope this is useful:
I, [2015-08-26T20:39:33.249366 #61471] INFO -- : out_elasticsearch plugin configured
I, [2015-08-26T20:39:33.282479 #61471] INFO -- : in_kafka initialized
I, [2015-08-26T20:39:33.282731 #61471] INFO -- : in_kafka configured, format is text
I, [2015-08-26T20:39:33.283126 #61471] INFO -- : out_elasticsearch plugin started
I, [2015-08-26T20:39:33.283309 #61471] INFO -- : out_elasticsearch plugin started
I, [2015-08-26T20:39:33.286019 #61471] INFO -- : in_kafka::TopicWatcher got consumer: topic=applog, format=text, partition=
I, [2015-08-26T20:39:33.286455 #61471] INFO -- : in_kafka just started its thread, format is text
I, [2015-08-26T20:39:34.289209 #61471] INFO -- : in_kafka::TopicWatcher::consume got a msg, msg.value=2015-08-26T20:30:01.206156+08:00 logstash-forwarder CROND[54912]: (root) CMD (/usr/lib64/sa/sa1 1 1)
I, [2015-08-26T20:39:34.289307 #61471] INFO -- : in_kafka::TopicWatcher::consume about to add to ES: msg_record=2015-08-26T20:30:01.206156+08:00 logstash-forwarder CROND[54912]: (root) CMD (/usr/lib64/sa/sa1 1 1)
I, [2015-08-26T20:39:34.289342 #61471] INFO -- : in_kafka::TopicWatcher::consume about to call Engine.emit_stream
I, [2015-08-26T20:39:34.289379 #61471] INFO -- : inside EngineClass.emit_stream: tag=applog, es=#<Fluent::MultiEventStream:0x007fefcaf60c18>
I, [2015-08-26T20:39:34.289442 #61471] INFO -- : EventRouter.match(): match(applog) returns #<Fluent::CopyOutput:0x007fefcafec510>
I, [2015-08-26T20:39:34.289474 #61471] INFO -- : EventRouter.emit_stream(): matcher=#<Fluent::CopyOutput:0x007fefcafec510>
I, [2015-08-26T20:39:34.289505 #61471] INFO -- : CopyOutput.emit(applog, ...), es.repeatable=true, @deep_copy=false
I, [2015-08-26T20:39:34.289579 #61471] INFO -- : CopyOutput.emit(applog, ...), about to call #<Fluent::OutputChain:0x007fefcaf57ca8>.next, chain.size=1, .offset=0
I, [2015-08-26T20:39:34.289618 #61471] INFO -- : BufferedOutput.emit(applog, #<Fluent::MultiEventStream:0x007fefcaf60c18>, #<Fluent::OutputChain:0x007fefcaf57ca8>, ) - emit_count is now 1
I, [2015-08-26T20:39:34.289735 #61471] INFO -- : BufferedOutput.emit: buffer object is #<Fluent::MemoryBuffer:0x007fefcf7b9eb0>
I, [2015-08-26T20:39:34.289770 #61471] INFO -- : BasicBuffer.emit(, <93>¦applogÎUݳ<86>Ú^@e2015-08-26T20:30:01.206156+08:00 logstash-forwarder CROND[54912]: (root) CMD (/usr/lib64/sa/sa1 1 1)
, #<Fluent::OutputChain:0x007fefcaf57ca8>)
I, [2015-08-26T20:39:34.289888 #61471] INFO -- : BasicBuffer.emit: storable=true
I, [2015-08-26T20:39:34.289928 #61471] INFO -- : EventRouter.emit_stream(): after matcher.emit(applog, #<Fluent::MultiEventStream:0x007fefcaf60c18>, ...)
Could you also paste the "Read message from kafka, and output to a file" configuration?
Thanks for reply! I could not access corp net right now, I will paste the config once reached the server tomorrow morning.
Bottom line: from the debug output you could see the input plugin received message from Kafka and delivered to BufferedOutput.
On the other hand, message written to the file tagged as "syslog" will appear in the frontend of the elasticsearch server right away. (I use Kibana)
What could be wrong?
Another thing: is -v a very new option?
Here are three tests I did this morning, problem reproduced. Please see detailed configuration and screenshots. Any help will be highly appreciated. Thanks!
From kafka to file (works fine)
Extracting messages from kafka and output to a file. Also attached a tmux screenshot to describe the test:
- pane 3: write a line into the source log file, rsyslogd delivers it to kafka
- pane 2: the official kafka demo consumer saw the message
- pane 5: the message also fetched by fluentd-plugin-kafka and written to the target file
- pane 4: note the kafka host is the partition leader because fluentd-plugin-kafka does not support using zookeeper host right now
2015-08-27 09:08:31 +0800 [info]: fluent/engine.rb:101:configure: using configuration file: <ROOT>
<source>
type kafka
host 192.168.159.116
port 9092
topics applog
format text
</source>
<match applog>
type file
path /tmp/app.log
append true
buffer_type memory
flush_interval 1s
buffer_path /tmp/app.log.*
</match>
</ROOT>

From file to ElasticSearch (works fine)
Reading messages from a file and output to ES. Also attached a tmux screenshot to describe the test:
- pane 2: write a line into the source log file
- pane 3: td-agent.log shows it connected to ES
- pane 4: issue a ES search call and got the message
a_message_for_es
2015-08-27 09:54:16 +0800 [info]: fluent/engine.rb:101:configure: using configuration file: <ROOT>
<source>
type tail
format none
path /var/log/tdtest.log
tag syslog
</source>
<match syslog>
type copy
<store>
type elasticsearch
host 192.168.172.31
port 9200
type_name fluentd
index_name fluentd
logstash_format true
flush_interval 1s
</store>
</match>
</ROOT>

From Kafka to ElasticSearch (DOES NOT WORK)
Reading messages from kafka and output to ES. Also attached a tmux screenshot to describe the test:
- pane 3: write a line into the source log file, rsyslogd delivers it to kafka
- pane 2: the official kafka demo consumer saw the message
- pane 4: td-agent.log did not see the expected message about connecting to ES
- pane 5:
watch -d -n 0.2 'netstat -an | grep 9200'did not see the connection to ES
2015-08-27 10:27:52 +0800 [info]: fluent/engine.rb:101:configure: using configuration file: <ROOT>
<source>
type kafka
host 192.168.159.116
port 9092
topics applog
format text
</source>
<match applog>
type copy
<store>
type elasticsearch
host 192.168.172.31
port 9200
type_name fluentd
index_name fluentd
logstash_format true
flush_interval 1s
</store>
</match>
</ROOT>

Thanks for detailed information! I will test it.
In the client() method of file lib/fluent/plugin/out_elasticsearch.rb I added a line to print out the call stack, when reading from file and output to ES I see following stack, I didn't see that at all when reading from Kafka and output to ES.
Want to understand what triggers the run method. Any hint?
Note I added many debugging log so line number might be different:
"/opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-elasticsearch-1.0.0/lib/fluent/plugin/out_elasticsearch.rb:176:in `send'",
"/opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-elasticsearch-1.0.0/lib/fluent/plugin/out_elasticsearch.rb:169:in `write'",
"/opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/buffer.rb:335:in `write_chunk'",
"/opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/buffer.rb:314:in `pop'",
"/opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/output.rb:338:in `try_flush'",
"/opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.12/lib/fluent/output.rb:153:in `run'"
You have copy in match on kafka and ES case.
Adding stdout plugin to elasticsearch match also doesn't output received logs?
I believe I found the issue - I use rsyslog to collect raw log from file and write plain text into kafka, however the out_elasticsearch plugin expects json format, see out_elasticsearch.rb#L127.
126 chunk.msgpack_each do |tag, time, record|
127 next unless record.is_a? Hash
128 if @logstash_format
I will look into related document to see how to resolve this, it's not a fluentd issue anyway :)
Thanks!
Ah, I see. It seems fluent-plugin-kafka's bug.
https://github.com/htgc/fluent-plugin-kafka/blob/dcf57ffa3a911d00b29f9bc4a6231f378f2aef3f/lib/fluent/plugin/in_kafka.rb#L131
This line should be parsed_record['message'] = record or similar. I will send a patch to fluent-plugin-kafka later.
Thanks! Probably need to add a message_key option as well. I will have a team mate do that soon.
Can we send the Apache logs catalina.out logs to kafka?