Setup OpenShift 4 IngressController Access logs to output in json format.
Issue
- How can I set the IngressController logs to output in json format.
Resolution
-
Add
logging,httpLogFormat, andhttpCaptureHeadersto the ingresscontroller objectapiVersion: operator.openshift.io/v1 kind: IngressController metadata: name: default namespace: openshift-ingress-operator spec: logging: access: destination: type: Container httpCaptureHeaders: request: - maxLength: 253 name: Host httpLogFormat: '{"type":"router-log","log_format":"http","nodename":"%H","timestamp":"%[date,ltime(%Y/%m/%d %T)]","http_method":"%HM","url":"http://%[capture.req.hdr(0)]%HU","status_code":"%ST","client_ip":"%ci","client_port":"%cp","server_ip":"%si","server_port":"%sp","frontend_name":"%ft","backend_name":"%b","backend_server":"%s","retries":"%rc","bytes_uploaded":"%U","bytes_read":"%B","request_time":"%TR","wait_time":"%Tw","connect_time":"%Tc","response_time":"%Tr","total_time":"%Ta","termination_state":"%ts"}' -
View logs and parse out the json data.
$ oc logs router-default-78df5dd744-56wfq -c logs | awk -F \{ '/router-log/{printf "\{" $2}' | jq { "type": "router-log", "log_format": "http", "nodename": "worker-1.openshift.lab", "timestamp": "2024/11/12 21:05:23", "http_method": "GET", "url": "http://hello-node-test-http.apps.openshift.lab/healthz", "status_code": "200", "client_ip": "9.9.88.90", "client_port": "33578", "server_ip": "4.4.2.31", "server_port": "9376", "frontend_name": "public", "backend_name": "be_http:test-http:hello-node", "backend_server": "pod:hello-node-65d6c95457-nm6n7:hello-node:8080-9376:4.4.2.31:9376", "retries": "0", "bytes_uploaded": "144", "bytes_read": "147", "request_time": "0", "wait_time": "0", "connect_time": "0", "response_time": "0", "total_time": "0", "termination_state": "--" }
More information can be found here regarding log format:
OCP Ingress Docs
Content from cbonte.github.io is not included.Haproxy Docs
SBR
Product(s)
Components
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.