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

ID generator for celery extension #51

Merged
merged 9 commits into from Sep 29, 2022
Merged

ID generator for celery extension #51

merged 9 commits into from Sep 29, 2022

Conversation

dapryor
Copy link

@dapryor dapryor commented Sep 12, 2022

Refer to #50

Please review and I can address any requested changes :)

Added customizable generator options to celery extension to better match capabilities of the correlation id middleware

  • Added optional "header_key" param to asgi_correlation_id.extensions.celery.load_correlation_id
  • Added optional "generator" param to asgi_correlation_id.extensions.celery.load_correlation_id
  • Added optional "generator" param to asgi_correlation_id.extensions.celery.load_celery_current_and_parent_ids

…tch capabilities of the correlation id middleware

* Added optional "header_key" param to asgi_correlation_id.extensions.celery.load_correlation_id
* Added optional "generator" param to asgi_correlation_id.extensions.celery.load_correlation_id
* Added optional "generator" param to asgi_correlation_id.extensions.celery.load_celery_current_and_parent_ids
@sondrelg
Copy link
Member

I think this looks good 👍

Would you mind adding one or two tests, and would you mind updating the .github/workflows/tests.yml final line to say if: matrix.python-version == '3.10'.6? A bit pedantic perhaps, but nice to maintain the 100% 🤷‍♂️

@dapryor
Copy link
Author

dapryor commented Sep 13, 2022

I am actually going to rethink this PR a bit. We have access to celery and we just realized we can't correlate between the actual task id and the id that these functions create.

I'm still investigating, but it looks like the actual task id comes in through the kwargs of

@task_prerun.connect(weak=False)
def worker_prerun(task: 'Task', **kwargs: Any) -> None:
    ...

I am going to see if we can either provide a generator to match how it is currently done or use the default task id so we can correlate with flower.

@dapryor
Copy link
Author

dapryor commented Sep 14, 2022

After investigating further, it is possible to get the task_id from the task_prerun hook.

task_prerun = Signal(
    name='task_prerun',
    providing_args={'task_id', 'task', 'args', 'kwargs'},
)

I am going to add this as an opt-in parameter so as not to break people's existing code.

@sondrelg
Copy link
Member

Not sure how the current implementation would break existing code, but sounds good. Let me know when it's ready for another look 👍

@dapryor
Copy link
Author

dapryor commented Sep 14, 2022

What is currently in this pr should not break existing code since I defaulted the new arguments with the values that were hardcoded.

The addition I will be making that lets it use the celery task id will also not break existing code since I will make it Optional and opt-in.

I will hopefully get to updating this this week.

@sondrelg

This comment was marked as off-topic.

@JonasKs

This comment was marked as off-topic.

@dapryor

This comment was marked as off-topic.

@sondrelg

This comment was marked as off-topic.

@JonasKs

This comment was marked as off-topic.

@sondrelg
Copy link
Member

@dapryor are you still working on this? 🙂

@dapryor
Copy link
Author

dapryor commented Sep 28, 2022

@sondrelg Yes :) Apologies. I have been busy with work. Will get back to this soon

David Pryor (dapryor) added 2 commits September 28, 2022 16:55
…ilter and standardized the string trimming process for the filtering logic

* changed type from int to Optional[int] for optional parameter 'uuid_length' in CeleryTracingIdsFilter
* changed default value from 32 to None for optional parameter 'uuid_length' in CeleryTracingIdsFilter
* created and utilized function `_trim_string` to standardize string trimming logic in filters
* added test to test string trimming for CeleryTracingIdsFilter
* added test to ensure the default behavior of the new filter matched the behavior of the old filter.  This assumes default generators are used
…he internally generated celery_id

* Added optional argument `use_internal_celery_task_id` to `load_celery_current_and_parent_ids`
* When `use_internal_celery_task_id` is set to True, the internal celery task ID will be used and the generator function will be ignored
* Updated README with information on this new argument
@dapryor
Copy link
Author

dapryor commented Sep 28, 2022

@sondrelg I have updated the PR. It includes the signature change from #52 and the extra parameter for allowing the internal celery task id to be used.

I honestly would like some help with the celery test since the current structure of those test is async with a session celery app. This doesn't seem to lend itself well to test that change signal functions of the session app. Plus celery testing is already a huge pain...

@sondrelg
Copy link
Member

Looks good, thanks @dapryor 👏

@sondrelg sondrelg merged commit 42cf859 into snok:main Sep 29, 2022
@sondrelg
Copy link
Member

The new version (3.1.0) is now release. Would you mind verifying that it works ok for you @dapryor?

@davidpryor
Copy link
Contributor

@sondrelg everything seems to be working! will open an issue if i hit anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants