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

master: Add an option to janitor to delete logs for specific builders. #6404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rufinio
Copy link
Contributor

@rufinio rufinio commented Feb 16, 2022

Contributor Checklist:

  • I have updated the unit tests
  • I have created a file in the newsfragments directory (and read the README.txt in that directory)
  • I have updated the appropriate documentation

There is a need for data from different builders to be kept for different lengths of time before it can be deleted.
This change adds the ability to specify the duration before data is deleted per buildername.

@rufinio rufinio force-pushed the janitorPerBuilder branch 14 times, most recently from fa26fff to 59cde30 Compare February 18, 2022 11:17
@@ -39,43 +40,67 @@ class LogChunksJanitor(BuildStep):
name = 'LogChunksJanitor'
renderables = ["logHorizon"]

def __init__(self, logHorizon):
def __init__(self, logHorizon=None, horizonPerBuilder=None):
Copy link
Member

Choose a reason for hiding this comment

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

Buildbot wants to gradually move to snake_case naming style like the rest of Python ecosystem. Replace all horizonPerBuilder with horizon_per_builder.

deleted = yield self.master.db.logs.deleteOldLogChunks(older_than_timestamp)
self.descriptionDone = ["deleted", str(deleted), "logchunks"]
if self.logHorizon is not None:
older_than_timestamp = datetime2epoch(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should fit in a single line I think (Buildbot uses 100 chars per line).

now() - self.logHorizon)
deleted = yield self.master.db.logs.deleteOldLogChunks(
older_than_timestamp=older_than_timestamp)
self.descriptionDone = ["deleted", str(deleted), "logchunks"]
Copy link
Member

Choose a reason for hiding this comment

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

This should be just before return I think, because if both if conditions are true then we would set descriptionDone before step is actually finished.

Copy link
Member

Choose a reason for hiding this comment

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

OK, now I see that only either logHorizon or horizonPerBuilder is not None, not both.

older_than_timestamp = datetime2epoch(now() - self.build_data_horizon)
deleted = yield self.master.db.build_data.deleteOldBuildData(
older_than_timestamp=older_than_timestamp)
self.descriptionDone = ["deleted", str(deleted), "build data key-value pairs"]
Copy link
Member

Choose a reason for hiding this comment

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

This should be just before return I think, because if both if conditions are true then we would set descriptionDone before step is actually finished.

return SUCCESS


class JanitorConfigurator(ConfiguratorBase):
""" Janitor is a configurator which create a Janitor Builder with all needed Janitor steps"""

def __init__(self, logHorizon=None, hour=0, build_data_horizon=None, **kwargs):
def __init__(self, logHorizon=None, hour=0, build_data_horizon=None, horizonPerBuilder=None,
**kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

weird indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    def __init__(self, logHorizon=None, hour=0, build_data_horizon=None, horizonPerBuilder=None,
        **kwargs):

leads to flake8 error E125.

    def __init__(self,
                 logHorizon=None,
                 hour=0,
                 build_data_horizon=None,
                 horizon_per_builder=None,
                 **kwargs):

should it be like this?

self.hour = hour
self.kwargs = kwargs
if ((self.logHorizon is not None or self.build_data_horizon is not None)
and self.horizonPerBuilder is not None):
Copy link
Member

Choose a reason for hiding this comment

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

Weird indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flake8 complains about my further solutions. Please show me how it should look like.

@@ -226,7 +289,7 @@ def setUp(self):

class TestRealDB(unittest.TestCase,
connector_component.ConnectorComponentMixin,
Tests):
RealTests):
Copy link
Member

Choose a reason for hiding this comment

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

Ugh :-( Thanks for noticing.

self.hour = hour
self.kwargs = kwargs
if ((self.logHorizon is not None or self.build_data_horizon is not None)
and self.horizonPerBuilder is not None):
bbconfig.error("JanitorConfigurator: horizonPerBuilder only " +
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to support all of logHorizon, build_data_horizon, log_horizon_per_builder and build_data_horizon_per_builder at the same time.

Having both global and per-builder log horizons makes sense because it's then possible to have a longer global horizon and shorter per-builder horizons. It also doesn't increase the complexity of the code.

Copy link
Member

@p12tic p12tic left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! I had several comments, most of them very simple to address.

I think it makes sense to support global horizon and per-builder horizons at the same time (see my comment with longer justification).

@rufinio
Copy link
Contributor Author

rufinio commented Apr 1, 2022

per-builder horizon offers the possibility of using wildcards. Thus, I think global horizon can be reached by setting name to wildcard.

@codecov
Copy link

codecov bot commented Jun 24, 2022

Codecov Report

Merging #6404 (120ae5b) into master (3ef08ef) will decrease coverage by 0.09%.
The diff coverage is 62.69%.

❗ Current head 120ae5b differs from pull request most recent head 7425235. Consider uploading reports for the commit 7425235 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6404      +/-   ##
==========================================
- Coverage   92.05%   91.95%   -0.10%     
==========================================
  Files         343      343              
  Lines       38744    38841      +97     
==========================================
+ Hits        35665    35718      +53     
- Misses       3079     3123      +44     
Impacted Files Coverage Δ
master/buildbot/db/builds.py 85.20% <11.53%> (-13.40%) ⬇️
master/buildbot/db/builders.py 80.19% <13.63%> (-18.54%) ⬇️
master/buildbot/db/build_data.py 94.28% <80.00%> (-1.27%) ⬇️
master/buildbot/configurators/janitor.py 97.53% <100.00%> (+0.60%) ⬆️
master/buildbot/db/logs.py 96.19% <100.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ef08ef...7425235. Read the comment docs.

@rufinio rufinio force-pushed the janitorPerBuilder branch 2 times, most recently from 4f034d0 to 4b6925c Compare June 27, 2022 07:39
@rufinio rufinio force-pushed the janitorPerBuilder branch 3 times, most recently from d2e9e9f to 9c482e6 Compare July 4, 2022 11:59
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

2 participants