Skip to content

Use getTimeRotatingLogger for WMCore REST #11955

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

d-ylee
Copy link
Contributor

@d-ylee d-ylee commented Apr 1, 2024

Fixes/Is a part of #11922

Status

In development | not-tested

Description

Should set up a Python TimedRotatingFileHandler to replace the usage of rotatelogs

Is it backward compatible (if not, which system it affects?)

MAYBE
Should only be used when |rotatelogs ... is not used during deployment

Related PRs

dmwm/CMSKubernetes#1452
dmwm/CMSKubernetes#1604

External dependencies / deployment changes

Potentially remove the use of rotatelogs.

@d-ylee d-ylee requested review from vkuznet and amaltaro April 1, 2024 21:34
@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests no longer failing
  • Python3 Pylint check: failed
    • 17 warnings and errors that must be fixed
    • 4 warnings
    • 110 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 40 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15002/artifact/artifacts/PullRequestReport.html

Copy link
Contributor

@vkuznet vkuznet left a comment

Choose a reason for hiding this comment

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

Dennis, changes are fine but I don't know how getTimeRotatingLogger works and will rely on you that you tested it and confirmed that it works as expected.

@d-ylee d-ylee marked this pull request as draft April 8, 2024 13:58
@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 changes in unstable tests
  • Python3 Pylint check: failed
    • 18 warnings and errors that must be fixed
    • 4 warnings
    • 115 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 52 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15003/artifact/artifacts/PullRequestReport.html

@d-ylee
Copy link
Contributor Author

d-ylee commented Apr 9, 2024

@amaltaro I was testing this and it was rotating the logs, but not retaining them or adding the date. I found out that the date was originally provided in rotatelogs when calling wmc-httpd:

With rotatelogs:
https://github.com/dmwm/CMSKubernetes/blob/326de33e3769e2f66e088c91093d3179a8d1cc12/docker/pypi/reqmgr2ms-unmerged/run.sh#L145

Without rotatelogs:
https://github.com/dmwm/CMSKubernetes/blob/a6dfdee30f4a2cabc308663f2f3a9b215e08e991/docker/pypi/reqmgr2ms-unmerged/run.sh#L145

Now, I changed MyTimedRotatingFileHandler to add the YearMonthDate string when initializing the logger. I'm not sure if we want to inject the date via Python, or if we want to 100% replicate how we use rotatelogs by passing what we had originally in rotatelogs and replace %Y%m%d string in the MyTimedRotatingFileHandler.__init__ function with a todayStr.

Example
In run.sh:

wmc-httpd -r -d $STATEDIR -l "$LOGDIR/$srv-%Y%m%d-`hostname -s`.log 86400" $CFGFILE

In WMLogging.MyTimedRotatingFileHandler.__init__

 def __init__(self, logName, interval, backupCount):
        # Add todayStr to log name, like with rotatelogs
        todayStr = date.today().strftime("%Y%m%d")
        filename = logName.replace('%Y%m%d', todayStr)
        super(MyTimedRotatingFileHandler, self).__init__(filename, when=interval,
                                                         backupCount=backupCount)

@d-ylee d-ylee marked this pull request as ready for review April 9, 2024 03:10
@d-ylee
Copy link
Contributor Author

d-ylee commented Apr 9, 2024

To add a note:
This function doesn't do what the docstring says:

def doRollover(self):
"""
_doRollover_
Rotate the log file and add the date between the log name
and its extension, e.g.:
reqmgr2.log becomes reqmgr2-20170815.log
"""
self.stream.close()
# replace yesterday's date by today
yesterdayStr = (date.today() - timedelta(1)).strftime("%Y%m%d")
todayStr = date.today().strftime("%Y%m%d")
self.baseFilename = self.baseFilename.replace(yesterdayStr, todayStr)
if self.encoding:
self.stream = codecs.open(self.baseFilename, 'w', self.encoding)
else:
self.stream = open(self.baseFilename, 'w')
self.rolloverAt = self.rolloverAt + self.interval

The new date string is replaced, not added. So if the string doesn't contain yesterdayStr, then the string isn't added and the baseName remains the same.

@d-ylee d-ylee requested a review from vkuznet April 9, 2024 03:58
Copy link
Contributor

@vkuznet vkuznet left a comment

Choose a reason for hiding this comment

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

Dennis, the changes are fine but I would suggest to improve description and add to it exact syntax how to use this when we invoke python program., in other words, so far we use wmc-httpd -r -d $STATEDIR -l "|rotatelogs $LOGDIR/$srv-%Y%m%d-`hostname -s`.log 86400" $CFGFILE and it would be beneficial to have an example how we will call similar daemon (or python command) with new logger.

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 5062326 to 3358120 Compare April 9, 2024 20:53
@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: failed
    • 1 new failures
    • 1 tests no longer failing
    • 1 tests added
    • 1 changes in unstable tests
  • Python3 Pylint check: failed
    • 16 warnings and errors that must be fixed
    • 4 warnings
    • 119 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 57 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15007/artifact/artifacts/PullRequestReport.html

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 3358120 to 5a54b57 Compare April 10, 2024 14:53
@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 2 changes in unstable tests
  • Python3 Pylint check: failed
    • 16 warnings and errors that must be fixed
    • 4 warnings
    • 120 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 58 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15008/artifact/artifacts/PullRequestReport.html

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 5a54b57 to 6228aa0 Compare April 10, 2024 16:40
@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: failed
    • 7 new failures
    • 1 tests added
    • 1 changes in unstable tests
  • Python3 Pylint check: failed
    • 16 warnings and errors that must be fixed
    • 4 warnings
    • 112 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 31 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15009/artifact/artifacts/PullRequestReport.html

@d-ylee
Copy link
Contributor Author

d-ylee commented Apr 10, 2024

test this please

@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
  • Python3 Pylint check: failed
    • 16 warnings and errors that must be fixed
    • 4 warnings
    • 112 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 31 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15010/artifact/artifacts/PullRequestReport.html

Copy link
Contributor

@amaltaro amaltaro left a comment

Choose a reason for hiding this comment

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

@d-ylee I left a few comments/questions along the code.
I also wanted to point out to this line:

self.logfile = ["rotatelogs", "%s/%s-%%Y%%m%%d.log" % (self.statedir, self.appname), "86400"]

which IMO should be removed with this PR. In other words, I would say the log file name option has to be as simple as -l filename.log or -l filename_date.log and that is it. No need to accept pipe, rotatelogs and time in secs. Any thoughts?

@@ -619,5 +625,8 @@ def main():
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the option above in the if statement should be removed and we define this option to be in the format of -l my_logfile.log only. In other words, |, rotatelogs and 86400 (integer with time in seconds) are no longer an acceptable option. What do you think?

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 958a24a to a43ebca Compare April 17, 2024 13:39
@d-ylee
Copy link
Contributor Author

d-ylee commented Apr 17, 2024

@amaltaro If we remove the lines in RESTDaemon as you suggested, should we also remove this:

if isinstance(self.logfile, list):
subproc = Popen(self.logfile, stdin=PIPE, stdout=devnull, stderr=devnull,
bufsize=0, close_fds=True, shell=False)
logger = subproc.stdin

I think this was used to setup streaming to rotatelogs.

The other thing is that the line you referenced:

self.logfile = ["rotatelogs", "%s/%s-%%Y%%m%%d.log" % (self.statedir, self.appname), "86400"]

...gets overwritten if we provide -l:

if opts.logfile:
if opts.logfile.startswith("|"):
server.logfile = re.split(r"\s+", opts.logfile[1:])
else:
server.logfile = opts.logfile
# setup rotating log
getTimeRotatingLogger(None, server.logfile)

So the change will have the RESTDaemon default to logging to a file.

@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: failed
    • 1 new failures
    • 1 tests added
    • 1 changes in unstable tests
  • Python3 Pylint check: failed
    • 18 warnings and errors that must be fixed
    • 4 warnings
    • 111 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15019/artifact/artifacts/PullRequestReport.html

@amaltaro
Copy link
Contributor

@d-ylee yes, I think you are correct about the Popen and I am inclined to say that we should completely remove that, as we no longer expect (accept?) a list type parameter for the logfile.

Given that this line:

self.logfile = ["rotatelogs", "%s/%s-%%Y%%m%%d.log" % (self.statedir, self.appname), "86400"] 

was being used as default and get overwritten by the -l option. How about we keep this default value, but with the following difference:

self.logfile = "%s/%s-%%Y%%m%%d.log".format(self.statedir, self.appname, todayStr) 

or perhaps simply:

self.logfile = "%s/%s.log".format(self.statedir, self.appname) 

?

For now, I'd suggest to keep it in a different commit, just in case we regret this change :)

@d-ylee
Copy link
Contributor Author

d-ylee commented Jul 16, 2024

test this please

@cmsdmwmbot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests no longer failing
    • 1 tests added
    • 1 changes in unstable tests
  • Python3 Pylint check: failed
    • 18 warnings and errors that must be fixed
    • 4 warnings
    • 111 comments to review
  • Pylint py3k check: succeeded
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/DMWM-WMCore-PR-test/15106/artifact/artifacts/PullRequestReport.html

@cmsdmwmbot
Copy link

Can one of the admins verify this patch?

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from a43ebca to dbe1fc2 Compare April 1, 2025 19:39
@d-ylee
Copy link
Contributor Author

d-ylee commented Apr 10, 2025

@amaltaro Is there anything we should add to this pull request?

@anpicci
Copy link
Contributor

anpicci commented Apr 14, 2025

Hi @d-ylee @amaltaro , given that with #12181 we changed the names of the WM pypi packages, should we propagate that to the developments made here?

@amaltaro
Copy link
Contributor

test this please

@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 3 changes in unstable tests
  • Python3 Pylint check: failed
    • 18 warnings and errors that must be fixed
    • 4 warnings
    • 109 comments to review
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/683/artifact/artifacts/PullRequestReport.html

@amaltaro
Copy link
Contributor

Once we have this change in, we can likely remove the dependency on apache2-utils from the dmwm-base image:
https://github.com/dmwm/CMSKubernetes/blob/master/docker/pypi/dmwm-base/Dockerfile#L6C82-L6C95

I don't know if anything is used from this package, but rotatelogs is:

_reqmgr2@reqmgr2-f44b4f784-4d9j5:/data$ dpkg -S rotatelogs
apache2-utils: /usr/share/man/man8/rotatelogs.8.gz
apache2-utils: /usr/bin/rotatelogs

@d-ylee
Copy link
Contributor Author

d-ylee commented May 13, 2025

@amaltaro I created a PR here for removing apache2-utils from our Debian-based dmwm-base.

dmwm/CMSKubernetes#1610

dmwm-alma9-base doesn't install rotatelogs, so no change should be needed in this PR: dmwm/CMSKubernetes#1604

@d-ylee
Copy link
Contributor Author

d-ylee commented May 20, 2025

After doing the testing for CMSKubernetes#1604, there are some issues during the rollover period of the log file, with the file not actually being renamed. I am doing more further investigation.

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 629a2c4 to 6092fbf Compare May 22, 2025 21:11
@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 5 changes in unstable tests
  • Python3 Pylint check: failed
    • 22 warnings and errors that must be fixed
    • 4 warnings
    • 112 comments to review
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/719/artifact/artifacts/PullRequestReport.html

@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 3 changes in unstable tests
  • Python3 Pylint check: failed
    • 22 warnings and errors that must be fixed
    • 4 warnings
    • 112 comments to review
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/720/artifact/artifacts/PullRequestReport.html

@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 2 changes in unstable tests
  • Python3 Pylint check: failed
    • 22 warnings and errors that must be fixed
    • 4 warnings
    • 112 comments to review
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/721/artifact/artifacts/PullRequestReport.html

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 6d34d12 to 6d8a7f4 Compare May 23, 2025 15:39
@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 4 changes in unstable tests
  • Python3 Pylint check: failed
    • 17 warnings and errors that must be fixed
    • 4 warnings
    • 111 comments to review
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/722/artifact/artifacts/PullRequestReport.html

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 6d8a7f4 to b35a3fc Compare May 29, 2025 18:01
@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 3 changes in unstable tests
  • Python3 Pylint check: failed
    • 17 warnings and errors that must be fixed
    • 4 warnings
    • 112 comments to review
  • Pycodestyle check: succeeded
    • 33 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/728/artifact/artifacts/PullRequestReport.html

@d-ylee
Copy link
Contributor Author

d-ylee commented May 30, 2025

@amaltaro While doing some investigation today, I noticed that MSUnmerged is creating 3 log files:

  1. heartbeatMonitor: Created from the CherryPyPeriodicTask heartbeat monitor task; defined in config-unmerged.py (affected by this PR)
  2. reqmgr2ms-unmerged-<timestamp>.log: Created from the main daemon (affected by this PR)
  3. reqmgr2ms-unmerged.log: Created from CherryPy REST API Logger; contents are the result of logging via cherrpy.log(), as seen here:
    cherrypy.log("INFO: final CherryPy configuration: %s" % pformat(cpconfig))

[1] and [2] both utilize the WMTimedRotatingFileHandler that is being worked on in this PR.

[3] on the other hand seems to be something separate. Should the CherryPy RESTApi logs be in the same file as [2]?

@dmwm-bot
Copy link

dmwm-bot commented Jun 5, 2025

Jenkins results:

  • Python3 Unit tests: succeeded
    • 1 tests added
    • 2 changes in unstable tests
  • Python3 Pylint check: failed
    • 17 warnings and errors that must be fixed
    • 4 warnings
    • 216 comments to review
  • Pycodestyle check: succeeded
    • 52 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/758/artifact/artifacts/PullRequestReport.html

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 8554b05 to 03be719 Compare June 6, 2025 15:40
@dmwm-bot
Copy link

dmwm-bot commented Jun 6, 2025

Jenkins results:

  • Python3 Unit tests: failed
    • 1 tests added
    • 4 changes in unstable tests
  • Python3 Pylint check: failed
    • 24 warnings and errors that must be fixed
    • 8 warnings
    • 115 comments to review
  • Pycodestyle check: succeeded
    • 36 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/759/artifact/artifacts/PullRequestReport.html

@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch 2 times, most recently from 87bb3c5 to 171da3f Compare June 11, 2025 19:30
@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: failed
    • 1 tests added
    • 4 changes in unstable tests
  • Python3 Pylint check: failed
    • 24 warnings and errors that must be fixed
    • 8 warnings
    • 115 comments to review
  • Pycodestyle check: succeeded
    • 36 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/770/artifact/artifacts/PullRequestReport.html

d-ylee added 2 commits June 24, 2025 12:27
Use getTimeRotatingLogger for WMCore REST

Added date to filename for MyTimedRotatingFileHandler if it doesn't have it

Added usage for wmc-httpd LOG-FILE arg

Renamed MyTimedRotatingFileHandler to WMTimedRotatingFileHandler

Simplified WMTimedRotatingFileHandler to use namer function

Remove unused code and docstrings

Fixed service log rotation

Add QueueHandler for cherrypy, remove redirecting logging

QueueHandler for cherrypy logs

Added a queue listener thread that aggregates all logs that are handled
with the WMTimedRotatingLogger

Removed redirecting logging to a subprocess or a file using file
descriptors
Updated WMLogging test to test a quick log rotation

Fix some pylint errors in WMLogging_t.py

Replace existing log rotation test
@d-ylee d-ylee force-pushed the 11922-build-a-msunmerged-docker-image-based-on-almalinux branch from 171da3f to 6647c4e Compare June 24, 2025 17:27
@dmwm-bot
Copy link

Jenkins results:

  • Python3 Unit tests: failed
    • 1 tests added
  • Python3 Pylint check: failed
    • 24 warnings and errors that must be fixed
    • 8 warnings
    • 115 comments to review
  • Pycodestyle check: succeeded
    • 36 comments to review

Details at https://cmssdt.cern.ch/dmwm-jenkins/view/All/job/WMCore-PR-Report/797/artifact/artifacts/PullRequestReport.html

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

Successfully merging this pull request may close these issues.

6 participants