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

Feature: Distribution Packages #97

Merged
merged 25 commits into from
Sep 10, 2024

Conversation

drewstinnett
Copy link
Contributor

@drewstinnett drewstinnett commented Aug 28, 2024

This PR adds RPM and Deb packaging from goreleaser, as well as a little systemd file to start and stop the service.

resolves #96

@drewstinnett drewstinnett marked this pull request as draft August 28, 2024 12:04
@drewstinnett
Copy link
Contributor Author

Oops, need to fix reuse workflow..

@drewstinnett drewstinnett marked this pull request as ready for review August 28, 2024 12:18
@NucciTheBoss
Copy link

Hah, looks like we had the same idea this week (#96) - this is great! 😆

I published a PPA for Noble and Jammy on Launchpad for the exporter. I've reached out to the Debian Go team about getting the exporter uploaded to Debian. It would be great to have latest builds published to GitHub and a git buildpackage version on Salsa for inclusion into Debian 😄

@drewstinnett
Copy link
Contributor Author

Hah, looks like we had the same idea this week (#96) - this is great! 😆

I published a PPA for Noble and Jammy on Launchpad for the exporter. I've reached out to the Debian Go team about getting the exporter uploaded to Debian. It would be great to have latest builds published to GitHub and a git buildpackage version on Salsa for inclusion into Debian 😄

Oh I totally missed that...good timing!!

@abhinavDhulipala
Copy link
Collaborator

Howdy! First of all thanks a ton for your contributions. Give me a day or 2 wrap my mind around this MR and get back to you. In the meanwhile, I don't think tracing functionality is supported the way it is packaged right now. Please checkout my latest MR #95 for how to package and resolve the html files to support tracing. In short, we need to package the ./exporter/templates/* html files. In the systemd file and pkgs, we need to support pointing to the proper templated directory using the TRACE_ROOT_PATH env var.

@drewstinnett
Copy link
Contributor Author

Ah yes that makes sense I'll add that in shortly... Thank you!

@drewstinnett
Copy link
Contributor Author

Ok @abhinavDhulipala, I think the packaging is correct now if you'd like to take a look when you can (No rush here btw, and thank you so much for this awesome project! 🙏)

Just a thought, but how would you feel if I changed the TRACE_ROOT_PATH logic in the code to look in the order:

  1. $TRACE_ROOT_PATH path
  2. . (cwd)
  3. /usr/share/prometheus-slurm-exporter/templates/

I don't think that would break any current workflows, but it would allow users of the distro packages to use tracing without having to specify an additional env variable. If that is something you would be interested in, I'd be happy to make that change as well as part of this PR. No worries if you'd like to keep it the same though too.

Thank you again!

@abhinavDhulipala
Copy link
Collaborator

abhinavDhulipala commented Sep 2, 2024

Howdy @drewstinnett that trace path feature looks like a great feature, but we could also configure the environment variable of the systemd file to fill in the $TRACE_PATH to /usr/share/prometheus-slurm-exporter/templates. If we were to implement the scheme above, I think we should implement it in the following way:

  1. If TRACE_ROOT_PATH is specified, search that directory. If we don't find a templates dir, let's panic and crash the program.
  2. If TRACE_ROOT_PATH isn't specified, we can search cwd and /usr/share/prometheus-slurm-exporter.

Now, I tried to install debian found on your forks release page. I did the following in case you want to repro:

docker run -ti --rm --platform linux/amd64 ubuntu:22.04 bash
$ apt update -y && apt-get install wget -y && mkdir /workspace
$ cd /workspace
$ wget https://github.com/drewstinnett/prometheus-slurm-exporter/releases/download/v0.0.3/prometheus-slurm-exporter_0.0.3_linux_amd64.deb
$  apt-get install -f prometheus-slurm-exporter_0.0.3_linux_amd64.deb
# unfortunately got the following
$  stat /usr/share/prometheus-slurm-exporter/         
stat: cannot statx '/usr/share/prometheus-slurm-exporter/': No such file or directory

It doesn't look like the templates were packaged. Is this stale perhaps?

Thanks again for all your hard work!

@drewstinnett
Copy link
Contributor Author

Thank you @abhinavDhulipala, I will work on these fixes/changes!

* archive static templates with binary

* update docs
…metheus-slurm-exporter into feature-distro-packages
Adding packaging pieces

Testing goreleaser and re-adding license

Fixing whitespace

Adding in trace path detection logic

Testing goreleaser

Adding license bits

Oops forgot conflict

Adding trace templates to distro package

Fixing spacing
…metheus-slurm-exporter into feature-distro-packages
@drewstinnett
Copy link
Contributor Author

Working on the trace logic...quick question for you @abhinavDhulipala, should the app do a 'deep' search of the TRACE_ROOT_PATH for the 'templates' directory, or do we always expect it to be right under the top path? For example:

if TRACE_ROOT_PATH is set to "/srv", should "/srv/subdir/templates" be considered valid, or would we only want to look at "/srv/templates"? Either is fine with me, just wanted to check the intended behavior. Thank you!

@abhinavDhulipala
Copy link
Collaborator

I have it now as a recursive search, but I think that could be a potential bottleneck if configured wrong. Let's modify it to simply checking for the existence of the one html file we have now.

@drewstinnett
Copy link
Contributor Author

Ok, whenever you get a chance, can you give it another review? I think I was mis-using the github-release command, which appears to have generated the packages based off of an older tag. I think this is fixed now. I verified with:

$ goreleaser release --clean --snapshot
...
$ dpkg-deb -c dist/prometheus-slurm-exporter_1.6.5-SNAPSHOT-0969bb7_linux_amd64.deb
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/bin/
-rwxr-xr-x root/root  10014872 2024-09-03 10:02 ./usr/bin/prometheus-slurm-exporter
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/lib/
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/lib/systemd/
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/lib/systemd/system/
-rw-r--r-- root/root       250 2024-09-03 09:35 ./usr/lib/systemd/system/prometheus-slurm-exporter.service
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/share/
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/share/prometheus-slurm-exporter/
drwxr-xr-x root/root         0 2024-09-03 10:02 ./usr/share/prometheus-slurm-exporter/templates/
-rw-r--r-- root/root       927 2024-08-27 10:47 ./usr/share/prometheus-slurm-exporter/templates/proc_traces.html

The logic for the detection is also in place now

$ LOGLEVEL=debug prometheus-slurm-exporter -trace.enabled=true
time=2024-09-03T12:22:40.135-04:00 level=INFO msg="trace path enabled at path: :9092/trace"
time=2024-09-03T12:22:40.136-04:00 level=DEBUG msg="using trace template path: /usr/share/prometheus-slurm-exporter/templates"
time=2024-09-03T12:22:40.136-04:00 level=INFO msg="serving metrics at :9092/metrics"
…
$ LOGLEVEL=debug TRACE_ROOT_PATH=/tmp/empty-dir prometheus-slurm-exporter -trace.enabled=true
time=2024-09-03T12:23:46.371-04:00 level=INFO msg="trace path enabled at path: :9092/trace"
panic: TRACE_ROOT_PATH must include a directory called: templates
…

Happy to make whatever tweaks/changes you suggest in addition to these as well. Thank you!

Copy link
Collaborator

@abhinavDhulipala abhinavDhulipala left a comment

Choose a reason for hiding this comment

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

The biggest takeaway here is that I've found it cumbersome to install this in containers which I often use for deployment. Let me know what you think!

EDIT: I've also validated this within a docker container to ensure that your branch works :).

.goreleaser.yaml Outdated Show resolved Hide resolved
Comment on lines 6 to 7
systemctl daemon-reload
systemctl enable --now prometheus-slurm-exporter.service
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm conflicted on whether we should install a systemctl function by default. I personally won't be using this method of deployment and when I try to develop and test out of containers this gets in the way quite a bit. I'd suggest remove this entirely. We could guard with the following: [[ -d /run/systemd/system ]] && ..., but I still would prefer to drop this and just put this as documentation. Perhaps a curlable snippet of some kind.

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 understand what you mean...I'll make this update removing the systemd components from the packaging and include a snippet in the documentation that can be copy/pasted. Thank you for that feedback!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, systemd bits have been removed from the packaging, and I added a little copy/pastable snippet to the README for folks that would like to enable it as a systemd service. Look ok? Thank you!

Comment on lines +209 to +219
func TestDetectTraceRootPath_Env(t *testing.T) {
os.Clearenv()
testDir := t.TempDir()
t.Setenv("TRACE_ROOT_PATH", testDir)
// Ensure that the function panics if given a TRACE_ROOT_PATh with no 'templates' subdirectory
assert.PanicsWithValue(t, "TRACE_ROOT_PATH must include a directory called: templates", func() { detectTraceTemplatePath() })
require.NoError(t, os.Mkdir(filepath.Join(testDir, templateDirName), 0o700))

// Now that we have a 'templates' subdir, it should no longer panic
assert.Equal(t, filepath.Join(testDir, templateDirName), detectTraceTemplatePath())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an awesome test! Great work.

drewstinnett and others added 5 commits September 6, 2024 11:33
Fixing bad copy/paste, oops!

Co-authored-by: abhinavDhulipala <[email protected]>
…metheus-slurm-exporter into feature-distro-packages
Fixing bad copy/paste, oops!

Co-authored-by: abhinavDhulipala <[email protected]>

make systemctl edit copy/pastable
…metheus-slurm-exporter into feature-distro-packages
Copy link
Collaborator

@abhinavDhulipala abhinavDhulipala left a comment

Choose a reason for hiding this comment

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

This looks awesome, thanks a ton for all your hard work once again. I'll cut a release on main shortly

@abhinavDhulipala abhinavDhulipala merged commit e285f3e into rivosinc:main Sep 10, 2024
1 check 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.

Debian packaging for Slurm exporter
3 participants