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

[grafana] conf and logs from snap added #3289

Closed
wants to merge 2 commits into from

Conversation

GairePravesh
Copy link
Contributor

@GairePravesh GairePravesh commented Jun 27, 2023

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

  • 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?

@packit-as-a-service
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-3289
  • And now you can install the packages.

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

Comment on lines 70 to 83
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*********"
)
Copy link
Contributor

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*********"
)

Comment on lines -42 to +62
"admin_password", "secret_key"
"admin_password",
"secret_key",
"password",
"client_secret"
Copy link
Contributor

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.

Copy link
Member

@arif-ali arif-ali left a 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 the grafana-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,
])

@pmoravec
Copy link
Contributor

Generally ACK, just a though: since the "snap instance or not" call flows differ a lot, it would maybe make more sense to have SnapPlugin class likewise we have RedHatPlugin or DebianPlugin? Though the Plugin hierarchy is likely distribution-based, not package-manager-based. But maybe if some other plugins might benefit from this in future, it should be easy to add SnapPlugin (likewise https://github.com/sosreport/sos/blob/main/sos/policies/distros/ubuntu.py#L49)?

@arif-ali
Copy link
Member

Generally ACK, just a though: since the "snap instance or not" call flows differ a lot, it would maybe make more sense to have SnapPlugin class likewise we have RedHatPlugin or DebianPlugin? Though the Plugin hierarchy is likely distribution-based, not package-manager-based. But maybe if some other plugins might benefit from this in future, it should be easy to add SnapPlugin (likewise https://github.com/sosreport/sos/blob/main/sos/policies/distros/ubuntu.py#L49)?

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 maas and lxd

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.

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?

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)
Copy link
Member

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

Comment on lines +44 to +45
f'{grafana_cli} -v' if not self._is_snap else None,
'grafana-server -v' if not self._is_snap else None
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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.

@arif-ali
Copy link
Member

arif-ali commented Nov 9, 2023

This is being closed in favour of #3410, Pravesh will not longer be contributing

@arif-ali arif-ali closed this Nov 9, 2023
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.

[grafana] Collect data for snap installation
4 participants