Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/contour: Add support for json log formatter #4486

Merged
merged 1 commit into from
Apr 29, 2022

Conversation

tsaarni
Copy link
Member

@tsaarni tsaarni commented Apr 19, 2022

This change enables Contour logs in JSON format as discussed in #4414 (comment).

The PR proposes new command line argument --log-format over generally preferred configuration CRD or config file field. The reasoning for new command line argument is to allow setting formatter for all sub-commands, not only serve, and setting it as early as possible, before CR is fetched from the API server or before config file is read from filesystem.

Fixes #4414

Signed-off-by: Tero Saarni tero.saarni@est.tech

@tsaarni tsaarni requested a review from a team as a code owner April 19, 2022 16:08
@tsaarni tsaarni requested review from stevesloka and skriss and removed request for a team April 19, 2022 16:08
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
@tsaarni tsaarni force-pushed the tsaarni/issue4414 branch from 068240e to a336751 Compare April 19, 2022 16:12
@tsaarni tsaarni added the release-note/small A small change that needs one line of explanation in the release notes. label Apr 19, 2022
@codecov
Copy link

codecov bot commented Apr 19, 2022

Codecov Report

Merging #4486 (068240e) into main (e750132) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

❗ Current head 068240e differs from pull request most recent head a336751. Consider uploading reports for the commit a336751 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4486      +/-   ##
==========================================
- Coverage   76.69%   76.64%   -0.05%     
==========================================
  Files         139      139              
  Lines       12511    12518       +7     
==========================================
  Hits         9595     9595              
- Misses       2669     2676       +7     
  Partials      247      247              
Impacted Files Coverage Δ
cmd/contour/contour.go 0.00% <0.00%> (ø)

@tsaarni
Copy link
Member Author

tsaarni commented Apr 19, 2022

After specifying --log-format=json to set the Logrus JSON formatter, the logs looks like this:

{"level":"info","msg":"args: [serve --xds-address=0.0.0.0 --xds-port=8001 --envoy-service-http-port=8080 --envoy-service-https-port=8443 --contour-cafile=ca.crt --contour-cert-file=tls.crt --contour-key-file=tls.key --config-path=/home/tsaarni/work/devenvs/contour/configs/contour.yaml --log-format=json]","time":"2022-04-19T19:53:52+03:00"}
{"envoy-service-name":"envoy","envoy-service-namespace":"projectcontour","level":"info","msg":"Watching Service for Ingress status","time":"2022-04-19T19:53:52+03:00"}
{"context":"contourEventHandler","level":"info","msg":"started event handler","time":"2022-04-19T19:53:52+03:00"}
{"address":"127.0.0.1:6060","context":"debugsvc","level":"info","msg":"started HTTP server","time":"2022-04-19T19:53:52+03:00"}
{"address":"0.0.0.0:8000","context":"metricsvc","level":"info","msg":"started HTTP server","time":"2022-04-19T19:53:52+03:00"}
{"context":"xds","level":"info","msg":"waiting for informer caches to sync","time":"2022-04-19T19:53:52+03:00"}
{"context":"xds","level":"info","msg":"informer caches synced","time":"2022-04-19T19:53:52+03:00"}
{"caller":"leaderelection.go:248","context":"kubernetes","level":"info","msg":"attempting to acquire leader lease projectcontour/leader-elect...\n","time":"2022-04-19T19:53:52+03:00"}
{"address":"0.0.0.0:8001","context":"xds","level":"info","msg":"started xDS server type: \"contour\"","time":"2022-04-19T19:53:52+03:00"}
{"caller":"leaderelection.go:258","context":"kubernetes","level":"info","msg":"successfully acquired lease projectcontour/leader-elect\n","time":"2022-04-19T19:53:52+03:00"}
{"context":"StatusUpdateHandler","level":"info","msg":"started status update handler","time":"2022-04-19T19:53:52+03:00"}
{"context":"loadBalancerStatusWriter","level":"info","loadbalancer-address":"","msg":"received a new address for status.loadBalancer","time":"2022-04-19T19:53:52+03:00"}
{"context":"contourEventHandler","last_update":109610913,"level":"info","msg":"performing delayed update","outstanding":5,"time":"2022-04-19T19:53:52+03:00"}
{"connection":1,"context":"xds","error":"context canceled","level":"error","msg":"stream terminated","node_id":"envoy-pszrb","node_version":"v1.21.1","resource_names":null,"response_nonce":"1","time":"2022-04-19T19:54:47+03:00","type_url":"type.googleapis.com/envoy.config.cluster.v3.Cluster","version_info":"1"}
{"connection":2,"context":"xds","error":"context canceled","level":"error","msg":"stream terminated","node_id":"envoy-pszrb","node_version":"v1.21.1","resource_names":["default/echoserver/http"],"response_nonce":"1","time":"2022-04-19T19:54:47+03:00","type_url":"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment","version_info":"1"}
{"connection":3,"context":"xds","error":"context canceled","level":"error","msg":"stream terminated","node_id":"envoy-pszrb","node_version":"v1.21.1","resource_names":["ingress_http"],"response_nonce":"1","time":"2022-04-19T19:54:47+03:00","type_url":"type.googleapis.com/envoy.config.route.v3.RouteConfiguration","version_info":"1"}
{"connection":4,"context":"xds","error":"context canceled","level":"error","msg":"stream terminated","node_id":"envoy-pszrb","node_version":"v1.21.1","resource_names":null,"response_nonce":"1","time":"2022-04-19T19:54:47+03:00","type_url":"type.googleapis.com/envoy.config.listener.v3.Listener","version_info":"1"}

Copy link
Member

@youngnick youngnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, we're trying to avoid adding command line flags in general, but I agree this is a good exception.

@sunjayBhatia sunjayBhatia added this to the 1.21.0 milestone Apr 29, 2022
@sunjayBhatia
Copy link
Member

worth merging for 1.21 i think, missed the RC but not a huge change, should be easy to cherry-pick

@sunjayBhatia sunjayBhatia merged commit 34febcd into projectcontour:main Apr 29, 2022
sunjayBhatia pushed a commit to sunjayBhatia/contour that referenced this pull request Apr 29, 2022
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
@tsaarni
Copy link
Member Author

tsaarni commented Apr 29, 2022

Thanks @sunjayBhatia! I should have asked myself if this will still fit into the release :)

skriss pushed a commit to skriss/contour that referenced this pull request May 9, 2022
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
skriss pushed a commit that referenced this pull request May 9, 2022
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/small A small change that needs one line of explanation in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

severity instead of level in logging
3 participants