-
Notifications
You must be signed in to change notification settings - Fork 25
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
conditionally format log_records #171
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #171 +/- ##
==========================================
+ Coverage 73.20% 73.27% +0.06%
==========================================
Files 25 25
Lines 1911 1916 +5
==========================================
+ Hits 1399 1404 +5
Misses 512 512 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, had a comment
Instead of storing every log message as a record, only store the formatted logs (if a formatter was provided). A formatter can be supplied by setting `_log_records_formatter` on the `Step` class/instance. Co-authored-by: Zach Burnett <[email protected]>
This PR is good. Perhaps for a future PR, I would go one step further and get rid of any So really, there should not be a |
Instead of storing every log message as a record, only store the formatted logs (if a formatter was provided). A formatter can be supplied by setting
_log_records_formatter
on theStep
class/instance.This prevents the
Step._log_records
from keeping references toargs
provided for logging calls. An example of a particularly problematic one is:stpipe/src/stpipe/step.py
Line 429 in 9952c36
This will (with stpipe main) store a reference to the input datamodel within the log record. This creates a chain of references that prevents garbage collecting
args
(and the input datamodel) because:args
refs the datamodelLogRecord
refsargs
_log_records
refs theLogRecord
Step
instance refs_log_records
Pipeline
refs theStep
This means (on main) any datamodel used as an input to a
Step
will be kept in memory until thePipeline
is garbage collected.This PR fixes the issue by formatting the
LogRecord
to a string before storing it in_log_records
. This changes the API forStep.log_records
so it now returns a list of strings (instead of a list ofLogRecord
instances). The only known user oflog_records
is romancal (which will require a minor update for this PR, more on that below).The romancal CI failure here is expected as a minor change will be needed in romancal (see spacetelescope/romancal#1327).
Fixes #169
jwst regtests with this PR all pass:
https://plwishmaster.stsci.edu:8081/blue/organizations/jenkins/RT%2FJWST-Developers-Pull-Requests/detail/JWST-Developers-Pull-Requests/1616/pipeline/194
romancal regtests will require spacetelescope/romancal#1327 to pass but pass with that PR:
https://github.com/spacetelescope/RegressionTests/actions/runs/10063338609/job/27821316132
Plan for merging
Since romancal currently depends on stpipe main the merging of this PR and the romancal PR spacetelescope/romancal#1327 will require some coordination. One possible option is to update the romancal PR to remove the dependency to my branch and then merge this stpipe PR then immediately merge the romancal PR.
I've opened both PRs for review but please hold off merging until both PRs are ready to go.