update usage of deprecated utcnow() in service request aggregator #13373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
I was a bit annoyed to see this every single time I ran a test:
Changes
Basically utcnow is deprecated. The code was creating a naive datetime just to calculate an interval, and then attaching it to the payload adding a Zulu marker.
I just create now the forced UTC equivalent from the beginning
datetime.datetime.now(datetime.UTC). I am not sure if the backend would work with the standard isoformat(), so I kept the Zulu based format.This is a critical piece of analytics, so let me know if I miss something important in the picture.
Tests
Just made sure that
tests/unit/utils/analytics/test_service_call_aggregator.pypasses. It does not test the payload, but at least parses it and checks the times are relative to each other.Related
There are other pieces of the code that use the deprecated method, which is a nice code janitor job. Expect more.