Fluent_d tag rewrite

66 views
Skip to first unread message

Yogi

unread,
Sep 19, 2018, 9:31:39 AM9/19/18
to Fluentd Google Group
Hello Guys,

Currently we have tagged out logs in a way that every log entry from servers(forwarder) come prefixed with the tag. Now our requirement is to prefix that with an environment variable({ENV['STAGE']}) declared in container(aggregator). 

I tried with rewrite_tag_filter but it seems we can only do it for log message but not the key itself ? Or is there any other way of doing it ?


Current setup :

serverTag-LogLines


Desired setup :

ContainerEnvironmentVariable.ServerTag-LogLines



Thanks





Mr. Fiber

unread,
Sep 20, 2018, 5:58:05 AM9/20/18
to Fluentd Google Group
One way is using route plugin like below:

<source>
  @type forward
</source>

<match test.**>
  @type route
  <route **>
    add_tag_prefix "#{ENV['STAGE']}"
  </route>
</match>

# ENV['STAGE'] is 'dev', events are routed to this match. e.g. test.foo -> dev.test.foo
<match dev.**>
  @type stdout
</match>


Masahiro

--
You received this message because you are subscribed to the Google Groups "Fluentd Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fluentd+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yogi

unread,
Sep 21, 2018, 11:04:53 AM9/21/18
to Fluentd Google Group
Thanks a lot Masahiro. That worked. 
I was wondering whether we have conditional forwarding available with this plugin ? I mean, we don't want to forward logs from any other environment except prod. 
e.g. 
if ENV['STAGE'] is 'dev - Don't forward
if ENV['STAGE'] is 'int' - Don't forward
if ENV['STAGE'] is 'prod' - forward

Yogesh

Yogi

unread,
Sep 24, 2018, 5:39:59 AM9/24/18
to Fluentd Google Group
Currently i am using following code, which is routing logs from all the environment to MYSERVER. I was able to add the environment tag ahead of log lines with Masahiro's help. Now i am not sure how can i use a condition under the <store> configuration so that only PROD logs will be forwarded to MYSERVER and rest all shouldn't. Could you please help me on this ?

<source>
  @type forward
</source>
<match *.**>
  @type route
  <route **>
     add_tag_prefix "#{ENV['stage']}"
  </route>
</match>
<match *.**>
  @type stdout
</match>   
 <match *.application.**>
   @type copy
   <store>
     @type forward
     <server>
       name MYSERVER
       host SERVERIP
       port 24224
     </server>
   </store>


Yogi

On Thursday, September 20, 2018 at 11:58:05 AM UTC+2, repeatedly wrote:
Reply all
Reply to author
Forward
0 new messages