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

[container_log] Get rotated logs #3678

Merged
merged 1 commit into from
Jul 4, 2024
Merged

Conversation

Akrog
Copy link
Contributor

@Akrog Akrog commented Jun 17, 2024

In Kubernetes/OpenShift rotated logs have no symbolic link in /var/log/containers and they cannot be retrieved using oc logs either, so there is no way to get these rotated logs in a SOS report.

This patch proposes a new functionality for the container_log plugin to retrieve rotated logs for the containers.

Since there may be lots of rotated logs we also add the maxage option.

The plugin will not only download the /var/log/pods files but also the /var/log/container symlinks.

Closes #3677
Signed-off-by: Gorka Eguileor [email protected]


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?

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-3678
  • And now you can install the packages.

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

Copy link

@gibizer gibizer left a comment

Choose a reason for hiding this comment

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

Thanks @Akrog

@fmount
Copy link

fmount commented Jun 17, 2024

+1 on this change, thank you @Akrog

Copy link
Member

@TurboTurtle TurboTurtle left a comment

Choose a reason for hiding this comment

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

I don't like the idea of adding yet another "get logs for containers" plugin from the start. On top of that though, this should be an addition to the openshift and kubernetes plugins as a simple add_copy_spec() using the existing maxage parameter.

If the rotated logs are written to disk, there's no reason the openshift plugin can't just collect those outside of the oc logs command.

@Akrog
Copy link
Contributor Author

Akrog commented Jun 17, 2024

I don't like the idea of adding yet another "get logs for containers" plugin from the start. On top of that though, this should be an addition to the openshift and kubernetes plugins as a simple add_copy_spec() using the existing maxage parameter.

If the rotated logs are written to disk, there's no reason the openshift plugin can't just collect those outside of the oc logs command.

Makes sense not adding yet another plugin.

Would it be ok to add it as an option to the container_log plugin instead?

I'm saying it because that plugin is already getting /var/log/containers which in many cases are just symlinks to /var/log/pods.

@bogdando
Copy link
Contributor

well done, thanks a lot!

@TurboTurtle
Copy link
Member

I don't like the idea of adding yet another "get logs for containers" plugin from the start. On top of that though, this should be an addition to the openshift and kubernetes plugins as a simple add_copy_spec() using the existing maxage parameter.
If the rotated logs are written to disk, there's no reason the openshift plugin can't just collect those outside of the oc logs command.

Would it be ok to add it as an option to the container_log plugin instead?

I'm saying it because that plugin is already getting /var/log/containers which in many cases are just symlinks to /var/log/pods.

Yeah, that makes sense.

@Akrog Akrog changed the title Add new pod_log plugin [container_log] Get rotated logs Jun 20, 2024
@jcastill
Copy link
Member

@Akrog can you squash these two commits into one please?

@Akrog
Copy link
Contributor Author

Akrog commented Jun 20, 2024

@jcastill Done. I usually try to do 1 thing on each patch, but each project is different. :-)

Comment on lines 35 to 36
# Remove size limit from containers logs when getting rotated, since
# they are just symlinks to the pods logs
Copy link
Member

@TurboTurtle TurboTurtle Jun 20, 2024

Choose a reason for hiding this comment

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

Our sizelimiting takes the link's destination into account when checking sizes for collections, so I'm not sure what the desire is here? We definitely do not want to have a wide open "collect all logs regardless of sizes" default posture here. We've had that bite us in the rear in the past several times - no one likes several GB sos reports.

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 tried, and failed, to explain it in the PR description.

The idea is that if you set the rotated option but you don't change the limits at all you are going to either get the exact same content as without the option (because like you said getting the symlinks checks the actual destination files) or we are going to get logs from the pods that don't have a symlink (not necessarily rotated logs), in both cases it seems wrong.

Another option is for the rotated option to ignore all the .log files from the pods directory and only get rotated logs instead.

This later options sounds reasonable to me and in line with the option name. I'll update the PR.

Comment on lines 51 to 56
def collect_subdirs(self, root=logdir, sizelimit=None, maxage=None):
"""Collect *.log files from subdirs of passed root path
"""
for dir_name, _, _ in os.walk(root):
self.add_copy_spec(self.path_join(dir_name, '*.log'))
self.add_copy_spec(self.path_join(dir_name, '*.log'),
sizelimit=sizelimit,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, not ignoring sizelimit entirely as a default behavior.

Comment on lines 27 to 29
PluginOpt('maxage', default=None, val_type=int,
desc='gather only logs with `mtime` not older than this many'
' hours')
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 if we do anything here, we should add a maxage (or since) -esque options to all plugins by default, like we do for timeout and postproc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding that global feature in this PR doesn't feel right, so I'll submit another PR for that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this PR look reasonable? #3681

Comment on lines +24 to +27
option_list = [
PluginOpt('rotated', default=False, val_type=bool,
desc='also get rotated logs from /var/log/pods'),
]
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed this on a second pass, but I'm assuming this should be dropped with the intent being that the rotated logs are collected by -k container_log.all-logs=true once #3681 is merged?

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 stupid, you are right.
This PR is changing existing behavior and it's adding a plugin option that is not being used.
I'll make the rotated log gathering conditional to the rotated plugin option.

In Kubernetes/OpenShift rotated logs have no symbolic link in
/var/log/containers and they cannot be retrieved using `oc logs` either,
so there is no way to get these rotated logs in a SOS report.

This patch proposes extending the `container_log` plugin to make it also
capable of retrieving rotated logs from `var/log/pods` using a plugin
boolean option called `rotated`.

Closes sosreport#3677
Signed-off-by: Gorka Eguileor <[email protected]>
@TurboTurtle TurboTurtle merged commit a79b866 into sosreport:main Jul 4, 2024
32 checks passed
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.

There are no plugin to gater K8s/OCP rotated logs
7 participants