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

Unit test Ceph cache and fix timezone awareness #2723

Merged
merged 7 commits into from
Oct 5, 2022

Conversation

mayaCostantini
Copy link
Contributor

Related Issues and Dependencies

Fixes #2722
Related to #2666

This introduces a breaking change

  • No

This should yield a new module release

  • Yes

@sesheta sesheta added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 4, 2022
@mayaCostantini
Copy link
Contributor Author

/hold

@sesheta sesheta added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 4, 2022
@mayaCostantini
Copy link
Contributor Author

/unhold

@sesheta sesheta removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 4, 2022
@mayaCostantini
Copy link
Contributor Author

/retest

@mayaCostantini
Copy link
Contributor Author

/assign @harshad16
Ready for review

- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc)
).total_seconds()

if time_lived <= 14400.0:
return time_lived
return 14400.0 - time_lived

return 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return a timedelta object instead of a raw number of seconds ?

If not, I think we should at least use it internally to the function.

@@ -46,11 +46,11 @@ def retrieve_document_ttl(self, document_id: str) -> float:

# Uses UTC time to be environment agnostic (no timezone)
time_lived = (
datetime.now()
datetime.now(timezone.utc)
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc)
).total_seconds()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
).total_seconds()
)

@@ -46,11 +46,11 @@ def retrieve_document_ttl(self, document_id: str) -> float:

# Uses UTC time to be environment agnostic (no timezone)
time_lived = (
datetime.now()
datetime.now(timezone.utc)
- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc)
).total_seconds()

if time_lived <= 14400.0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if time_lived <= 14400.0:
if time_lived <= timedelta(hours=4):

(this makes it clearer that 14400 seconds == 4 hours)

- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc)
).total_seconds()

if time_lived <= 14400.0:
return time_lived
return 14400.0 - time_lived
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 14400.0 - time_lived
return timedelta(hours=4) - time_lived

or if we don't want to return a timedelta

Suggested change
return 14400.0 - time_lived
return (timedelta(hours=4) - time_lived).total_seconds()

- self.ceph.retrieve_document_attr(object_key=document_id, attr="LastModified").replace(tzinfo=timezone.utc)
).total_seconds()

if time_lived <= 14400.0:
return time_lived
return 14400.0 - time_lived

return 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0.0
return timedelta()

Only if we switch to a timedelta return.

@VannTen
Copy link
Member

VannTen commented Oct 5, 2022

Btw, side comment: I'm not sure datetime is a good fit for a TTL. For that we don't need fancy handling of timezone/DST, just a unix timestamp, don't we ?

time would probably better. Unfortunately s3 "lastmodified" only give us a datetime. Hum. Let's not bother for now, I'll keep that on a note and see if it warrant another issue.

@VannTen
Copy link
Member

VannTen commented Oct 5, 2022 via email

@sesheta sesheta added the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2022
@sesheta
Copy link
Member

sesheta commented Oct 5, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: VannTen

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sesheta sesheta added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 5, 2022
@sesheta sesheta merged commit 1d96bb2 into thoth-station:master Oct 5, 2022
@mayaCostantini mayaCostantini deleted the cache-test branch October 5, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write unit tests for Ceph cache interface
4 participants