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

[plugins] maxage and all_logs on all plugins #3681

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

Conversation

Akrog
Copy link
Contributor

@Akrog Akrog commented Jun 21, 2024

This patch makes 2 options settable globally and per-plugin: maxage and all_logs.

Examples:

sos report --all-logs --maxage=1
sos report -k container_log.all-logs=on,container_log.maxage=1
sos report --all-logs --maxage=1 -k container_log.all-logs=off,container_log.maxage=2

This adds flexibility to what users want to retrieve.


Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname [email protected]?
  • Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?
  • Are all passwords or private data gathered by this PR obfuscated?

@Akrog Akrog mentioned this pull request Jun 21, 2024
6 tasks
Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/sosreport-sos-3681
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Comment on lines 1685 to 1701
if self.get_option('since'):
since = self.get_option('since')

# User's plugin option argument takes precedence over plugin passed arg
maxage = self.get_option('maxage') or maxage

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall not we unify the code here? Both manipulations perform the same at the end, the unification would improve clarity of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I don't understand what you mean by "unify the code".

The kdump plugin passes the maxage argument, so this code preserves existing behavior 1. Otherwise this would become a breaking change.

Comment on lines 204 to 209
report_grp.add_argument("--maxage", action="store",
dest="maxage", default=None, type=int,
help="Escapes archived files older (according "
"to `mktime`) than this many hours. This will "
"also affect --all-logs (sets the default for "
"all plugins)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be clear for users the option takes values in hours? Esp. if --since is primarily in days (default expected format is a day, optionally time)? Should not we rename it to, I dont know, --maxhours? (that sounds badly to me, I like the --maxage more).

I can easily be wrong here. I really dont know what users' perception would be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the suggested change to maxhours, as it has the benefit of including the unit in the name and not force people to look at the description to figure it out.

I'll make the change.

@Akrog Akrog force-pushed the maxage-default-plugin-opt branch from 6dd2683 to afbfafe Compare June 21, 2024 15:28
@pmoravec
Copy link
Contributor

I meant that

        since = None
        if self.get_option('since'):
            since = self.get_option('since')
        
        # User's plugin option argument takes precedence over plugin passed arg
        maxhours = self.get_option('maxhours') or maxhours

applies same logical change to either since or maxhours option. For the sake of code coherence, we should use same construction in either assignment, so let have there either:

        since = self.get_option('since') or None
        
        # User's plugin option argument takes precedence over plugin passed arg
        maxhours = self.get_option('maxhours') or maxhours

or:

        since = None
        if self.get_option('since'):
            since = self.get_option('since')
        
        # User's plugin option argument takes precedence over plugin passed arg
        if self.get_option('maxhours'):
            maxhours = self.get_option('maxhours')

The first construction is more concise, the second more explicit. I like the first more but 2nd is fully OK for sure.

desc='Escapes archived files older (according to `mktime`) '
'than this many hours'
),
'all_logs': PluginOpt(
Copy link
Member

Choose a reason for hiding this comment

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

We recently standardized on using hyphens for plugin options, to match the "top level" options which are all hyphens. So this will need to be all-logs (though the internal dest naming will of course still be all_logs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm new to this, but I assumed looking at the kernel plugin with-timer definition and how it is accessed as with-timer and not with_timer that there is no translation on the PluginOpt.

I looked a bit into the get_option and PluginOpt and didn't find any translation mechanism so I went with the solution that required fewer code changes.

But it is true that it would be weird to call it --all-logs only to have to use all_logs in the plugins.

I'll see if I can use all-logs everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

sos/report/__init__.py Show resolved Hide resolved
@TurboTurtle
Copy link
Member

In a quick test, this change works for maxhours, but does not work for all_logs - the plugin only gets the global value, which is due to this in Plugin:

def get_option(self, optionname, default=0):
"""Retrieve the value of the requested option, searching in order:
parameters passed from the command line, set via `set_option()`, or the
global_plugin_options dict.
`optionname` may be iterable, in which case this function will return
the first match.
:param optionname: The name of the option to retrieve the value of
:type optionname: ``str``
:param default: Optionally provide a default value to return if no
option matching `optionname` is found. Default 0
:returns: The value of `optionname` if found, else `default`
"""
global_options = (
'all_logs', 'allow_system_changes', 'cmd_timeout', 'journal_size',
'log_size', 'plugin_timeout', 'since', 'verify'
)

@Akrog Akrog force-pushed the maxage-default-plugin-opt branch 2 times, most recently from 812a081 to 9d19e66 Compare June 26, 2024 10:51
Current `PluginOpt` code doesn't have the possibility of having a
different name for the parameter and the reference used in the code.

This would be the equivalent in arg parser to not having a `dest`
argument available to us.

This patch proposes a change to allow this using a new `PluginOpt` field
called `param_name`.

This new field will only be used when interfacing with users. In other
words, when showing the options to users (eg: `list_plugins`), when
parsing the command line arguments (eg: `_set_tunables`), and when
reading the config file (this doesn't require code changes because it
leverages the normal `_set_tunables` method).

Signed-off-by: Gorka Eguileor <[email protected]>
@Akrog Akrog force-pushed the maxage-default-plugin-opt branch from 9d19e66 to ab16bbf Compare June 26, 2024 14:45
This patch makes 2 options settable globally and per-plugin: `maxhours`
and `all-logs`.

The `maxhours` option maps to what the code used to call `maxage`, which
has also been renamed to `maxhours` to be consistent.

Examples:

```
sos report --all-logs --maxhours=1
sos report -k container_log.all-logs=on,container_log.maxhours=1
sos report --all-logs --maxhours=1 \
  -k container_log.all-logs=off,container_log.maxhours=2
```

This adds flexibility to what users want to retrieve.

Signed-off-by: Gorka Eguileor <[email protected]>
@Akrog Akrog force-pushed the maxage-default-plugin-opt branch from ab16bbf to 8bc2ccb Compare June 27, 2024 13:09
@Akrog
Copy link
Contributor Author

Akrog commented Jul 2, 2024

In a quick test, this change works for maxhours, but does not work for all_logs - the plugin only gets the global value, which is due to this in Plugin:

def get_option(self, optionname, default=0):
"""Retrieve the value of the requested option, searching in order:
parameters passed from the command line, set via `set_option()`, or the
global_plugin_options dict.
`optionname` may be iterable, in which case this function will return
the first match.
:param optionname: The name of the option to retrieve the value of
:type optionname: ``str``
:param default: Optionally provide a default value to return if no
option matching `optionname` is found. Default 0
:returns: The value of `optionname` if found, else `default`
"""
global_options = (
'all_logs', 'allow_system_changes', 'cmd_timeout', 'journal_size',
'log_size', 'plugin_timeout', 'since', 'verify'
)

Done, I implemented it in what I consider the safest way, and it also adds a missing feature: different variable and user facing parameter name for plugin options.

Alternatively the all-logs command line argument could be changed to save the parameter in all-logs instead of all_logs and all code changed to access it with getattr instead of using .all_logs.

@TurboTurtle
Copy link
Member

Sorry for the silence here, cycling around on it now.

The all-logs vs all_logs convention is due to python variable identifiers not allowing hyphen characters. We aligned to using hyphens in the user-facing CLI because that's typically what users expect, and it is the prevailing syntax for argparse and what it does automatically for name conversions.

Internally, developers just need to know that hyphens become underscores when accessing the associated variables, which is the case for any project using argparse and directly accessing the parsed options.

So, we're good with the original intent of the PR - expanding all-logs and maxage/maxhours to all plugins on a potentially individual basis, but we don't need to mess around with internal references to option names.

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.

3 participants