kaltura / nginx-kafka-log-module

Send Kafka messages from Nginx
BSD 2-Clause "Simplified" License
65 stars 22 forks source link

Work in if section or new option for kafka_log #8

Open k0st1an opened 4 years ago

k0st1an commented 4 years ago

Thanks for the module! But, please, add the ability to work inside if. This will help to cancel the logging of some requests:

server {
  set $kafka_log 1;
  location / {
    if ($uri_match_trackers) {
      set $not_logging T;
    }
    if ($arg_is_attributed = 0) {
      set $not_logging "${not_logging}T";
    }
    if ($not_logging = "TT") {
      set $kafka_log 0;
    }
    if ($kafka_log) {
      kafka_log kafka:test '{"timestamp":"$msec"}';
    }
    proxy_pass http://tracker;
  }
}

Now I get the error:

nginx: [emerg] "kafka_log" directive is not allowed here

The configuration can be like this:

server {
  kafka_log kafka:test '{"timestamp":"$msec"}';
  location / {
    if ($uri_match_trackers) {
      set $not_logging T;
    }
    if ($arg_is_attributed = 0) {
      set $not_logging "${not_logging}T";
    }
    if ($not_logging = "TT") {
      kafka_log off;
    }
    proxy_pass http://tracker;
  }
}
krychu90 commented 3 years ago

I have the same problem. It would be nice to have something like access_log has:


access_log logs/access.log combined if=$true;
erankor commented 3 years ago

You can do it by using a variable for topic and having it evaluate to an empty string when you don't want to send the message. If topic is empty, the module doesn't send a message.