-
Notifications
You must be signed in to change notification settings - Fork 543
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
[grafana] conf and logs from snap added #3289
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. |
sos/report/plugins/grafana.py
Outdated
if self._is_snap: | ||
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys) | ||
self.do_path_regex_sub( | ||
"/var/snap/grafana/current/conf/grafana.ini", | ||
regexp, | ||
r"\1*********" | ||
) | ||
else: | ||
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys) | ||
self.do_path_regex_sub( | ||
"/etc/grafana/grafana.ini", | ||
regexp, | ||
r"\1*********" | ||
) |
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.
If the only change is in filename, maybe it is easier to have:
inifile = `"/var/snap/grafana/current/conf/grafana.ini"` if self_is_snap else "/etc/grafana/grafana.ini"
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
self.do_path_regex_sub(
inifile,
regexp,
r"\1*********"
)
"admin_password", "secret_key" | ||
"admin_password", | ||
"secret_key", | ||
"password", | ||
"client_secret" |
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.
+1, that helps also to non-snap instances.
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.
@GairePravesh Thanks for your contribution
probably nits more than anything
- What about creating a variable called
grafana_cli
, and based if it is snap or standard, and then use that variable to do thegrafana-cli
commands. This way, if more commands are needed we add 1 line rather than duplication - We could probably do the same with both the log path and config path, as they would be similar
i.e.
if self._is_snap:
grafana_cli = "grafana.grafana-cli"
else:
grafana_cli = "grafana-cli"
self.add_cmd_output([
"%s plugin ls" % grafana_cli,
"%s plugin list remote" % grafana_cli,
"%s -v" % grafana_cli,
])
Generally ACK, just a though: since the "snap instance or not" call flows differ a lot, it would maybe make more sense to have |
I do like the idea, I will have a look at this in the background, and see how that looks with refactoring a few of the other plugins that has this already, like |
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.
if self._is_snap: grafana_cli = "grafana.grafana-cli" else: grafana_cli = "grafana-cli" self.add_cmd_output([ "%s plugin ls" % grafana_cli, "%s plugin list remote" % grafana_cli, "%s -v" % grafana_cli, ])
This, but please note that f-strings are preferred per the contributions guidelines.
The intent of the changes looks good, just simplifying the flow as suggested above would be my 2 cents.
As far as a SnapPlugin
goes, I'm not sure how well we'd be able to have that in tandem with distro-based enablement without things getting real fragile.
Perhaps instead we could add a helper method like self.is_pkg_snap('$pkg')
(and accompanying is_pkg_rpm()
, is_pkg_deb()
etc...) to better support these checks within the current scope of enablement desgns?
eca3de6
to
ceb702f
Compare
files added: /var/snap/grafana/common/data/log/grafana.log* /var/snap/grafana/current/conf/grafana.ini cmds added: snap info grafana grafana.grafana-cli plugins ls grafana.grafana-cli plugins list-remote Closes: sosreport#3278 Signed-off-by: Pravesh Gaire <[email protected]>
regexp = r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys) | ||
self.do_path_regex_sub("/etc/grafana/grafana.ini", | ||
regexp, r"\1*********") | ||
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys) |
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.
can you remove the (?m)
as that is now implied by default in the self.do_path_regex_sub()
based on issue #3301 and not going to be allowed in this manner in py311, thanks
f'{grafana_cli} -v' if not self._is_snap else None, | ||
'grafana-server -v' if not self._is_snap else None |
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.
Do these commands not work with a snap installation? Or are they not present. Non-present commands are handled gracefully by Plugin
, so we don't need to set these to None
and filter later.
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.
Likewise we don't need to gate the snap info
command, we can just tuck an add_cmd_output()
under the conditional on line 30.
"/etc/sysconfig/grafana-server", | ||
log_path + log_file_pattern, | ||
config_path, | ||
"/etc/sysconfig/grafana-server" if not self._is_snap else None |
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.
add_copy_spec()
also handles non-existing paths gracefully, so we can just have it listed here and it will be ignored for snap installations.
This is being closed in favour of #3410, Pravesh will not longer be contributing |
files added:
/var/snap/grafana/common/data/log/grafana.log*
/var/snap/grafana/current/conf/grafana.ini
cmds added:
snap info grafana
grafana.grafana-cli plugins ls
grafana.grafana-cli plugins list-remote
Closes: #3278
Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines