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

Modify file_size help doc string #1401

Merged
merged 12 commits into from
Oct 7, 2022

Conversation

j-c-cook
Copy link
Contributor

@j-c-cook j-c-cook commented Sep 29, 2022

In hindsight, I'm not sure that the statement, "(or for the case of blf, maximum buffer size before compression and flush to file)" should be in the help doc string for the logger.

The BLFWriter file_size function is a bit more nuanced than is described there. Compression is not accounted for when checking the size of _buffer_size, and therefore if the rollover is caused by the _buffer_size being exceeded, then the resulting file created will have a smaller file size than the file_size requested. If max_container_size << max_bytes then the size of the file will approach the specified max_bytes.

  • Provide an explanation for the nuanced file size rollover in the BLFWriter doc string

@codecov
Copy link

codecov bot commented Sep 29, 2022

Codecov Report

Merging #1401 (442d484) into develop (b2b2a80) will decrease coverage by 0.94%.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1401      +/-   ##
===========================================
- Coverage    66.19%   65.25%   -0.95%     
===========================================
  Files           86       81       -5     
  Lines         9068     8767     -301     
===========================================
- Hits          6003     5721     -282     
+ Misses        3065     3046      -19     

@j-c-cook
Copy link
Contributor Author

@zariiii9003 Do I have this explanation correct of how the file_size function behaves for BLFWriter? Do you think this explanation should be moved from the logger help doc string and into the BLFWriter function? To me it seems (1) perhaps it over complicates the logger help doc string and (2) its not an adequate description of the behavior.

can/logger.py Outdated
Comment on lines 196 to 197
help="Maximum file size in bytes. Rotate log file when size threshold "
"is reached.",
Copy link
Owner

Choose a reason for hiding this comment

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

👍🏼

can/io/blf.py Outdated Show resolved Hide resolved
can/logger.py Outdated Show resolved Hide resolved
can/io/logger.py Outdated
Comment on lines 328 to 333
# BLFWriter specific
_128_kb = 128 * 1024
if kwargs.get('max_container_size', 1) and max_bytes > 0:
kwargs['max_container_size'] = \
_128_kb if max_bytes > _128_kb else max_bytes * 0.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zariiii9003 This would get rid of the nuance. I'm anticipating that you are not going to like the BLFWriter specific code inside of the SizedRotatingLogger constructor, but let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, i don't like this here 😄
Also i do not understand what this does tbh, what's the purpose of this? And why is the default value of kwargs.get('max_container_size', 1) =1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If max_container_size is not defined then set the max_container_size. If max_container_size is not defined then set the value to be 128 kb unless the file_size is less than 128 kb. In that case set the max_container_size to 10% of the file_size.

I'm reverting the commits because I agree that its not a good location.

can/logger.py Outdated Show resolved Hide resolved
can/logger.py Outdated Show resolved Hide resolved
can/io/logger.py Outdated
Comment on lines 328 to 333
# BLFWriter specific
_128_kb = 128 * 1024
if kwargs.get('max_container_size', 1) and max_bytes > 0:
kwargs['max_container_size'] = \
_128_kb if max_bytes > _128_kb else max_bytes * 0.1

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, i don't like this here 😄
Also i do not understand what this does tbh, what's the purpose of this? And why is the default value of kwargs.get('max_container_size', 1) =1?

j-c-cook and others added 4 commits October 3, 2022 08:41
Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com>
This reverts commit 3afb140.
@zariiii9003
Copy link
Collaborator

@j-c-cook Can i merge this?

@j-c-cook
Copy link
Contributor Author

j-c-cook commented Oct 7, 2022

@j-c-cook Can i merge this?

Yes. As long as you think it’s appropriate to have the details contained in the parenthesis. That it does not crowd up the help description printout. I’ve wondered if it’s more than necessary, and if we should just keep it at #1401 (comment).

@zariiii9003
Copy link
Collaborator

There are parameters with longer descriptions so i think it's fine.
Alternatively we could disable support for problematic suffixes like gzip and soonish mf4. The original implementation restricted the supported file formats, we could go back to that.

@j-c-cook
Copy link
Contributor Author

j-c-cook commented Oct 7, 2022

There are parameters with longer descriptions so i think it's fine.

In that case, merge at will.

Alternatively we could disable support for problematic suffixes like gzip and soonish mf4. The original implementation restricted the supported file formats, we could go back to that.

I do agree that this may be useful, but think it should possibly be apart of a separate PR since we may have some details to resolve. For example, I think it would be useful if the dictionary was in the following format, given that some implementations do work with gzip:

supported_writers = {
    BLFWriter: [".blf"],
    CanutilsLogWriter: [".log", ".log.gz"]
}

Note: #1378 is currently a known open issue relating to the topic.

@zariiii9003 zariiii9003 merged commit b639560 into hardbyte:develop Oct 7, 2022
j-c-cook added a commit to j-c-cook/python-can that referenced this pull request Nov 11, 2022
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

3 participants