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

Redo volumes,disks,images cleanup #171

Merged
merged 1 commit into from
Dec 6, 2022
Merged

Conversation

asmorodskyi
Copy link
Collaborator

@asmorodskyi asmorodskyi commented Nov 14, 2022

Initially when data storage cleanup logic was created
we wanted to make it very flexable from one side
and very coutious from another. After more than 2 years
of practical usage of the tool we can clearly state that
half of implemented features not needed

@asmorodskyi asmorodskyi marked this pull request as draft November 14, 2022 16:06
@mimi1vx
Copy link
Collaborator

mimi1vx commented Nov 14, 2022

I'm all pro for drop of unneded code :D

Copy link
Collaborator

@ricardobranco777 ricardobranco777 left a comment

Choose a reason for hiding this comment

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

Small suggestions. Otherwise LGTM

ocw/lib/gce.py Show resolved Hide resolved
ocw/lib/azure.py Outdated Show resolved Hide resolved
ocw/lib/azure.py Outdated Show resolved Hide resolved
ocw/lib/azure.py Outdated Show resolved Hide resolved
@asmorodskyi asmorodskyi marked this pull request as ready for review November 21, 2022 11:30
@codecov
Copy link

codecov bot commented Nov 21, 2022

Codecov Report

Base: 80.21% // Head: 67.61% // Decreases project coverage by -12.59% ⚠️

Coverage data is based on head (84b1ea2) compared to base (bea53b6).
Patch coverage: 92.10% of modified lines in pull request are covered.

❗ Current head 84b1ea2 differs from pull request most recent head db13069. Consider uploading reports for the commit db13069 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #171       +/-   ##
===========================================
- Coverage   80.21%   67.61%   -12.60%     
===========================================
  Files          25       13       -12     
  Lines        2072     1056     -1016     
===========================================
- Hits         1662      714      -948     
+ Misses        410      342       -68     
Impacted Files Coverage Δ
webui/settings.py 98.16% <ø> (ø)
ocw/lib/gce.py 54.66% <86.66%> (-6.05%) ⬇️
ocw/lib/azure.py 74.35% <91.66%> (-4.96%) ⬇️
ocw/lib/EC2.py 67.69% <95.23%> (-3.59%) ⬇️
ocw/lib/provider.py 86.36% <100.00%> (-4.89%) ⬇️
tests/generators.py
tests/test_azure.py
tests/test_ec2.py
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@ricardobranco777 ricardobranco777 left a comment

Choose a reason for hiding this comment

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

Some small suggestions. These could be easily catched with flake8 or pylint.

ocw/lib/azure.py Outdated Show resolved Hide resolved
ocw/lib/azure.py Outdated Show resolved Hide resolved
ocw/lib/EC2.py Outdated
self.cleanup_snapshots(cleanup_ec2_max_snapshot_age_days)
if cleanup_ec2_max_volumes_age_days >= 0:
self.cleanup_volumes(cleanup_ec2_max_volumes_age_days)
cleanup_ec2_max_age_days = PCWConfig.get_feature_property('cleanup', 'ec2-max-age-days', self._namespace)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need the extra variable for ec2 here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

historical reasons , I think we will keep this for next commits ...

templates/pcw.ini Outdated Show resolved Hide resolved
Copy link
Collaborator

@grisu48 grisu48 left a comment

Choose a reason for hiding this comment

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

Overall: I like PRs that delete more code than adding 👍 🙂

I left some comment and some questions though but in general this looks like a good improvement to me.

ocw/lib/EC2.py Outdated Show resolved Hide resolved
ocw/lib/EC2.py Outdated Show resolved Hide resolved
ocw/lib/azure.py Outdated Show resolved Hide resolved
ocw/lib/gce.py Outdated Show resolved Hide resolved
ocw/lib/provider.py Outdated Show resolved Hide resolved
"""
delta_in_hours = PCWConfig.get_feature_property('cleanup', 'max-age-hours', self._namespace)
max_allowed_age = datetime.now(timezone.utc) - timedelta(hours=delta_in_hours)
return max_allowed_age > age
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name of the method is older_than_max_age_hours but this comparison does exactly the opposite 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a bit of confusion in this method - age is not an age (i.e. a duration) but a timestamp, i.e. a certain point in time. Suggestion:

def is_outdated(self, timestamp):
    delta = PCWConfig.get_feature_property('cleanup', 'max-age-hours', self._namespace)       # maximum allowed delta
    delta = timedelta(delta)
    now = datetime.now(timezone.utc)
    # Resource is outdated, if the given timestamp plus allowed delta exceeds the current timestamp
    return (timestamp + delta) > now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the code which you suggesting will not give expected behavior . I can show you in example .
Let's say max-age-hours=7 and if I call it with is_outdated("01-01-2022 21-00") it will gives me false . your method may be called is_still_valid because it will return true only for timestamps which didn't cross max-age-hours

Copy link
Collaborator

Choose a reason for hiding this comment

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

True, the last line should be return now > (timestamp > delta)

templates/pcw.ini Show resolved Hide resolved
templates/pcw.ini Show resolved Hide resolved
tests/test_ec2.py Show resolved Hide resolved
tests/test_gce.py Outdated Show resolved Hide resolved
ocw/lib/EC2.py Outdated Show resolved Hide resolved
ocw/lib/azure.py Outdated Show resolved Hide resolved
Initially when data storage cleanup logic was created
we wanted to make it very flexable from one side
and very coutious from another. After more than 2 years
of practical usage of the tool we can clearly state that
half of implemented features don't have real use case. This commit
is dropping not needed functionality keeping only what necessary
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.

5 participants