contour icon indicating copy to clipboard operation
contour copied to clipboard

Option to output Contour logs as JSON

Open bgagnon opened this issue 5 years ago • 5 comments

This is only about Contour's logs, not Envoy logs.

The request is to add a CLI flag that turns on JSON formatting for the logs. The default output is structured and tuned for readability on the shell:

time="2019-07-23T14:20:13Z" level=info msg="performing delayed update" context=HoldoffNotifier last_update=113.299889ms pending=3

With JSON, we'd have something like:

{"time":"2019-07-23T14:20:13Z","level":"info","msg":"performing delayed update","context":"HoldoffNotifier","last_update":"113.299889ms","pending":"3"}

This is optimized for structured logging stacks (ie. Elasticsearch/ELK).

bgagnon avatar Jul 23 '19 14:07 bgagnon

Logrus has a built-in JSON formatter, so this should be trivial to implement: https://github.com/sirupsen/logrus#formatters

Just need to agree on the CLI flag name.

bgagnon avatar Jul 23 '19 14:07 bgagnon

Thank you for raising this issue. I am assigning this to the unplanned milestone and we will evaluate it after Contour 1.0 has been released.

To give you an idea of my thinking, if contour is outputting so much information that it needs to be consumed and analysed by ELK, then it should become more circumspect, not change the format to make it easier to filter.

davecheney avatar Aug 20 '19 08:08 davecheney

if contour is outputting so much information that it needs to be consumed and analyzed by ELK, then it should become more circumspect, not change the format to make it easier to filter

Contour can log less and be structured; these two goals are orthogonal.

Visualization in Kibana or Grafana is often dependent on having structured fields, and so are alerts based on logs (we prefer metrics for this, but sometimes logs is all we have due the cardinality of some fields).

The decision to drop, retain or post-process a log message is also made easier when the rules can leverage structured fields. It is possible to use regular expressions and Lucene queries in grep fashion, but it is very error prone and rarely click-and-go in visualization tools.

I totally understand that in some cases, logs is just scrolling text on my screen, hence the suggestion to make this an optional toggle. I wouldn't develop/debug Contour with this option turned on.

bgagnon avatar Oct 11 '19 04:10 bgagnon

Thank you for you’re reply. The more experienced I get with the paradigm of logs vs metrics the more I’m convinced that most of what contour emits as a log line should actually be a metric.

My guiding philosophy is an applications should only say something if it’s something that needs to be responded too. Contours current logging approach fails that bar significantly.

davecheney avatar Oct 11 '19 04:10 davecheney