Bug 55186 - [UDM REST API] Add correlation/request ID header to responses and log
[UDM REST API] Add correlation/request ID header to responses and log
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0-2-errata
Assigned To: Florian Best
Iván.Delgado
https://git.knut.univention.de/univen...
:
Depends on:
Blocks: 55324 56970
  Show dependency treegraph
 
Reported: 2022-09-11 07:57 CEST by Daniel Tröder
Modified: 2024-01-09 19:59 CET (History)
1 user (show)

See Also:
What kind of report is it?: Feature Request
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Large environments, Troubleshooting
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2022-09-11 07:57:58 CEST
UCS and UCS@school are being deployed in systems of growing complexity. Debuggung problems in those systems is becoming increasingly difficult, as more and more decoupled systems are interacting in an asynchronously way. The support (and also development) is having an increasingly hard time debugging request chains.

A Correlation ID is a unique, randomly generated identifier value that is added to every request and response. In a microservice architecture, the initial Correlation ID is passed to each sub-processes. If a sub-system also makes sub-requests, it will also pass the Correlation ID to those systems. Debugging or tracing requests becomes much easier, as it is possible to search all logs for the same Correlation ID.

The UDM REST API is used both directly and indirectly by multiple UCS@school REST APIs. When those APIs issue requests to the UDM REST API, they (will) emit a "X-Request-ID" HTTP header (name is configurable). (The value is a uuid4() string.)

The UDM REST API should

a) return the received header in its response headers.
b) log the header (shorted to ~10 chars) in its log file.
Comment 1 Daniel Tröder univentionstaff 2022-09-11 09:21:21 CEST
Example in the BFF-Users app:
-------------------------------------------------------------------------------
curl -X 'GET' \
  'http://10.207.110.216/ucsschool/bff-users/v1/users/detail/demo_student' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJh...'
-------------------------------------------------------------------------------
Response headers:

 access-control-expose-headers: X-Request-ID 
 x-request-id: 4c2b138f0bdd4dce8956199703613072 
 ...
-------------------------------------------------------------------------------
tail  /var/log/univention/ucsschool-bff-users/http.log

2022-09-11 09:18:49 INFO  [70][4c2b138f0b] h11_impl.send:477  172.17.42.1:56876 - "GET /users/detail/demo_student HTTP/1.1" 200
-------------------------------------------------------------------------------
Comment 2 Daniel Tröder univentionstaff 2022-09-11 09:44:29 CEST
Interesting pages I found regarding tornado and correlation IDs:

* https://github.com/tornadoweb/tornado/issues/2216
* https://divak-tornado.readthedocs.io/en/latest/users-guide.html
Comment 3 Florian Best univentionstaff 2022-10-19 14:46:43 CEST
The UDM REST API now accepts a uuid4 formatted `X-Request-Id` http request header and uses that in log messages for access-log and errors.
The header value is send back as `X-Request-Id` response header. If no request header is set a uuid4 is generated.

As UDM uses the C implementation of univention-debug we cannot prefix UDM log messages with the ID. This will be outsourced into Bug #55324.

univention-directory-manager-rest.yaml
13f06d034562 | feat(udm-rest): set X-Request-Id header for traceability

univention-directory-manager-rest (10.0.4-5)
13f06d034562 | feat(udm-rest): set X-Request-Id header for traceability
05375c40a0e5 | fix(udm-rest-client): prepare to receive HTTP 202 Accepted when moving objects
c550ef90d6bf | chore(udm-rest): use async builtin functions
b2e11e45c24a | fix(udm-rest): fix translation of gettext string
51591c9ad2d0 | style(udm-rest): pyupgrade --keep-percent-format --py37-plus
Comment 4 Iván.Delgado univentionstaff 2022-10-20 09:09:33 CEST
Verified:
 * The response header contain x-request-id
 * Advisory
 * ucs-test-udm-rest