Project

Profile

Help

Story #4689

Updated by bmbouter almost 4 years ago

## Motivation 

 Pulp as a multi-process system needs should allow users to make debugging easy. Currently install django-cid\[0\] and configure it is hard to: 

 1. Identify which log statements are related to a specific API request 
 2. Filter out with all of those the settings it supports. This story should mostly require testing that aren't 
 3. Do this across multiple processes 

 Additionally, there is a use case where an external system wants to provide the correlation id, e.g. Katello wants to submit the correlation ID as part of the request. 


 ## Solution 

 Use [django-cid](https://django-correlation-id.readthedocs.io/en/latest/) by default, possible and document that it's available documenting it for users to use. 


 ## Implementation 

 ### Enabling in Pulp itself users. 

 1. Add django-cid as an installed app \[0\] https://django-correlation-id.readthedocs.io/en/latest/ 
 2. Reconfigure the default Django logger config in [settings.py](https://github.com/pulp/pulpcore/blob/master/pulpcore/app/settings.py#L178-L190) to incorporate the CID 
 3. Add user documentation identifying the types of things they can additionally configure 
 4. Add a test to assert Pulp viewset logs contain an autogenerated CID 

 ### Enabling in the App 

 1. Add a test to assert content app logs contain an autogenerated CID 

 ### Enabling in Tasking System 

 1. Have the [`enqueue_with_reservation`](https://github.com/pulp/pulpcore/blob/b94abd64d76ea4554e6750ff38ce458eaa888cc8/pulpcore/tasking/tasks.py#L162) method add a new kwarg named `_pulp_logging_cid`. All tasks shall have this added in as an additional kwarg. The value of the kwarg should be gotten at dispatch time using [`get_cid`](https://django-correlation-id.readthedocs.io/en/latest/api.html#cid.locals.get_cid). 

 2. Have the [`_queue_reserved_task`](https://github.com/pulp/pulpcore/blob/b94abd64d76ea4554e6750ff38ce458eaa888cc8/pulpcore/tasking/tasks.py#L51) method call [`set_cid()`](https://django-correlation-id.readthedocs.io/en/latest/api.html#cid.locals.set_cid) with the value of the kwarg _pulp_logging_cid. This will enable the correlation ID in the resource_manager logs for that task also. 

 3. Have the [`perform_job`](https://github.com/pulp/pulpcore/blob/master/pulpcore/tasking/worker.py#L75) call [`set_cid()`](https://django-correlation-id.readthedocs.io/en/latest/api.html#cid.locals.set_cid) with the value of the kwarg _pulp_logging_cid. Then since we don't want to actually pass it to the RQ task itself, pop it off of the kwargs for the task. This will enable the correlation ID in all pulp task logs also.

Back