-
Notifications
You must be signed in to change notification settings - Fork 545
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
[maas] improve/refactor MAAS plugin #3687
Conversation
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
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.
some comments based on our discussions
a0d3c43
to
a52f4ec
Compare
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.
CI caught the following issue, which we ought to fix.
Also, we prefer commits to be squashed for final merge, so once this is ready, that should be done.
6b12d58
to
cffbe9c
Compare
sos/report/plugins/maas.py
Outdated
if not os.path.exists(dir): | ||
return [] | ||
|
||
# Machine messages are collected with syslog and are stored under: | ||
# $template "{{log_dir}}/rsyslog/%HOSTNAME%/%$YEAR%-%$MONTH%-%$DAY%" | ||
# Collect only the most recent "%$YEAR%-%$MONTH%-%$DAY%" | ||
# for each "%HOSTNAME%". | ||
recent = [] | ||
for host_dir in os.listdir(dir): | ||
host_path = os.path.join(dir, host_dir) | ||
if not os.path.isdir(host_path): | ||
continue | ||
|
||
subdirs = [ | ||
os.path.join(host_path, d) | ||
for d in os.listdir(host_path) | ||
if os.path.isdir(host_path) | ||
] | ||
|
||
if not subdirs: | ||
continue | ||
|
||
recent.append(sorted( | ||
subdirs, key=lambda f: os.stat(f).st_mtime, reverse=True)[0] | ||
) | ||
|
||
return recent |
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.
I think using glob.glob
can be shorter here but since you need to apply some logic (take most recent file from each subdir only), the code sounds good to me as well.
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.
Thanks for the review!
I was looking for some built-in functions that I can use together with glob.glob
but didn't find anything.
MAAS collects machine logs using rsyslog and stores them in the following way:
/var/snap/maas/common/log/rsyslog$ tree
.
├── 32toledo
│ └── 2021-01-21
│ └── messages
├── adm21
│ └── 2021-03-03
│ └── messages
├── amco
│ ├── 2020-05-26
│ │ └── messages
│ ├── 2020-05-28
│ │ └── messages
│ └── 2020-08-06
│ └── messages
└── witty-shrimp
└── 2021-10-05
└── messages
I thought it would be great to collect just the most recent machine log (e.g. for amco
that will be amco/2020-08-06
) as it will speed up sos report -o maas
in most of the cases.
If --all_logs
provided, we want to collect all the data for all the dates
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.
Hm, I think for a better UX I should also check self.get_option("since")
here and return matching directories
self._log_error( | ||
"Cannot login into MAAS remote API with provided creds.") | ||
def setup(self): | ||
for service in self._services: |
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.
@arif-ali I decided not to use services
because I don't want default behaviour as defined in
sos/sos/report/plugins/__init__.py
Lines 3334 to 3347 in ca7300e
def add_default_collections(self): | |
"""Based on the class attrs defined for plugin enablement, add a | |
standardized set of collections before we call the plugin's own setup() | |
method. | |
""" | |
# For any service used for enablement checks, collect its current | |
# status if it exists | |
for service in self.services: | |
if self.is_service(service): | |
self.add_service_status(service) | |
self.add_journal(service) | |
for kmod in self.kernel_mods: | |
if self.is_module_loaded(kmod): | |
self.add_cmd_output(f"modinfo {kmod}") |
I would like to call add_journal
with since -1days
by default
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.
yeah, I think that's what was here before from the MAAS plugin
I am going to try the new plugin on various MAAS deployments over the weekend and I will move PR into "Read for review" if there will be no issues. |
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
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.
Looks good overall, just noting that we should prefer the path wrappers in Plugin
so that we can account for sysroot
changes.
sos/report/plugins/maas.py
Outdated
for host_dir in os.listdir(dir): | ||
host_path = os.path.join(dir, host_dir) | ||
if not os.path.isdir(host_path): | ||
continue | ||
|
||
subdirs = [ | ||
os.path.join(host_path, d) | ||
for d in os.listdir(host_path) | ||
if os.path.isdir(host_path) | ||
] |
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.
Plugin
includes wrappers for these path methods, e.g. Plugin.path_join()
, that are preferred because they will account for any sysroot
handed to sos.
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.
Oh, TIL. Thanks!
2274805
to
6e9664a
Compare
- plugin_timeout = 1800 (because journal collection takes time) - collect journal for all MAAS related services (by default since yesterday) - mask passwords in (conf|yaml|yml|toml) files with `do_path_regex_sub` - collect only recent syslog data for machines (if `--all-logs` was not provided) snap: - collect all `.conf` and `.yaml` files - exclude files containing secrets and keys under `/var/snap/maas/**` deb: - add missing service `maas-temporal-worker` introduced in MAAS 3.5 - collect `/var/lib/maas/temporal` - use glob pattern to collect `.conf` files - exclude secrets and keys under `/var/lib/maas/**` and `/etc/maas/**` - remove `/var/log/upstart/maas-*` as it was removed in xenial - remove `maas-region dumpdata` as it can expose sensitive information Signed-off-by: Anton Troyanov <[email protected]>
Changes:
do_path_regex_sub
--all-logs
was not provided)snap:
.conf
and.yaml
files/var/snap/maas/**
deb:
maas-temporal-worker
introduced in MAAS 3.5/var/lib/maas/temporal
.conf
files/var/lib/maas/**
and/etc/maas/**
/var/log/upstart/maas-*
as it was removed in xenialmaas-region dumpdata
as it can expose sensitive informationPlease place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines