Bug 2260538 - Review Request: Kepler - RPM package for Kepler
Summary: Review Request: Kepler - RPM package for Kepler
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: Package Review
Version: rawhide
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: ---
Assignee: Neal Gompa
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On: FE-NEEDSPONSOR
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-01-26 17:43 UTC by Matthew Yee
Modified: 2024-04-17 18:34 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2024-04-17 18:34:45 UTC
Type: ---
Embargoed:
ngompa13: fedora-review?


Attachments (Terms of Use)

Description Matthew Yee 2024-01-26 17:43:20 UTC
Spec URL: https://github.com/sustainable-computing-io/kepler/blob/main/packaging/rpm/kepler.spec
SRPM URL: N/A
Description: Kepler (Kubernetes-based Efficient Power Level Exporter) uses eBPF to probe performance counters and other system stats, use ML models to estimate workload energy consumption based on these stats, and exports them as Prometheus metrics
Fedora Account System Username: myee111

Comment 1 Matthew Yee 2024-01-26 20:41:16 UTC
We currently don't have a sponsor. This is our first package.

Comment 2 Neal Gompa 2024-01-27 14:10:49 UTC
Taking this review.

Comment 3 Neal Gompa 2024-01-27 14:12:12 UTC
(In reply to Matthew Yee from comment #0)
> Spec URL:
> https://github.com/sustainable-computing-io/kepler/blob/main/packaging/rpm/
> kepler.spec
> SRPM URL: N/A
> Description: Kepler (Kubernetes-based Efficient Power Level Exporter) uses
> eBPF to probe performance counters and other system stats, use ML models to
> estimate workload energy consumption based on these stats, and exports them
> as Prometheus metrics
> Fedora Account System Username: myee111

Please provide a spec file and an SRPM from URLs that can be curled so that fedora-review can fetch them.

Comment 4 Pau Garcia Quiles 2024-02-21 16:48:38 UTC
Hey Neal

This URL should work:
https://raw.githubusercontent.com/sustainable-computing-io/kepler/main/packaging/rpm/kepler.spec

Comment 5 hchen 2024-02-22 17:23:49 UTC
The RPM is available here https://github.com/sustainable-computing-io/kepler/releases/tag/v0.7.3

Comment 6 hchen 2024-02-22 17:24:28 UTC
@Neal, anything you need please let us know asap, thanks

Comment 7 Neal Gompa 2024-02-23 12:39:54 UTC
Spec review:

> %undefine _disable_source_fetch

This is not allowed. The Fedora build system does not provide internet access.

> Version:        %{getenv:_VERSION_}
> Release:        %{getenv:_RELEASE_}

This is not allowed. These values need to be static and managed from the spec file.

> BuildArch:      %{getenv:_ARCH_}

Ignoring the fact that this form is not allowed, this makes no sense and should be dropped. The build system will build for all architectures.

> License:        Apache License 2.0

This is not valid. This needs to be an SPDX license identifier tag.

Cf. https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/#_valid_license_short_names

> BuildRequires: systemd

I don't see a reason to require systemd when you only need the RPM macros. Instead, require "systemd-rpm-macros".

> BuildRequires: clang llvm llvm-devel zlib-devel make libbpf

Please format these such that each build dependency on its own line.

> Requires:       elfutils-libelf-devel

Are you sure you need the devel package at runtime?

> %ifarch x86_64
> GOARCH=amd64
> %endif

You're going to need aliases for all RPM arches in Fedora to map to Go arches.

> make genlibbpf _build_local GOOS=${GOOS} GOARCH=${GOARCH} ATTACHER_TAG=libbpf

The Go compilation build flags need to be passed in.

> install -d %{buildroot}/var/lib/kepler/data
> install -d %{buildroot}/var/lib/kepler/bpfassets
> install -d %{buildroot}/etc/kepler/kepler.config

"/var/lib" should be "%{_sharedstatedir}" and "/etc" should be "%{_sysconfdir}".

> install -p -m644 ./data/cpus.yaml %{buildroot}/var/lib/kepler/data/cpus.yaml
> install -p -m644 ./data/model_weight/acpi_AbsPowerModel.json %{buildroot}/var/lib/kepler/data/acpi_AbsPowerModel.json
> install -p -m644 ./data/model_weight/acpi_DynPowerModel.json %{buildroot}/var/lib/kepler/data/acpi_DynPowerModel.json
> install -p -m644 ./data/model_weight/intel_rapl_AbsPowerModel.json %{buildroot}/var/lib/kepler/data/intel_rapl_AbsPowerModel.json
> install -p -m644 ./data/model_weight/intel_rapl_DynPowerModel.json %{buildroot}/var/lib/kepler/data/intel_rapl_DynPowerModel.json

Are you sure this should be in "%{_sharedstatedir}"? It seems like these are static files and should be installed into "%{_datadir}".

> %post
>
> %systemd_post kepler.service

This is incomplete. 

Cf. https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd

> /var/lib/kepler/bpfassets/amd64_kepler.bpf.o

This should probably be installed into "%{_libexecdir}/kepler/bpfassets" instead.

Comment 8 Neal Gompa 2024-02-23 12:40:42 UTC
Also one more thing...

> Source0:        https://github.com/sustainable-computing-io/kepler/archive/refs/tags/%{version}.tar.gz

This should be "%{url}/archive/%{version}/%{name}-%{version}.tar.gz".

Comment 9 Nathan Scott 2024-02-26 03:42:54 UTC
> install -p -m644 ./bpfassets/libbpf/bpf.o/amd64_kepler.bpf.o %{buildroot}/var/lib/kepler/bpfassets/amd64_kepler.bpf.o

Is this amd64_kepler.bpf.o binary generated during the build or are we using the one from the git repo/tarball here?

For official Fedora builds, it will need to be built as part of the rpmbuild process (binary blobs are not allowed) and  that will result in a binary of the build system architecture (which is not necessarily x86_64).

Comment 10 Nathan Scott 2024-02-26 03:50:17 UTC
| The build system will build for all architectures.

What I suspect is actually needed here is the intersection of 'all support golang architectures' and 'all supported bpf architectures' (which is not all architectures, it turns out).  There's a similar situation in the Grafana build, where we need golang and nodejs architectures only, and this spec file snippet is used there:

%global grafana_arches %{lua: go_arches = {}
  for arch in rpm.expand("%{go_arches}"):gmatch("%S+") do
    go_arches[arch] = 1
  end
  for arch in rpm.expand("%{nodejs_arches}"):gmatch("%S+") do
    if go_arches[arch] then
      print(arch .. " ")
  end
end}

However, I'm not aware of a bpf_arches macro - for PCP we are using a local macro defined as: 'x86_64 %{power64} aarch64 s390x'.

Comment 11 hchen 2024-02-26 16:39:16 UTC
Thanks Neal! Will post a new spec for the Fedora requirements.

Comment 12 Neal Gompa 2024-02-26 17:10:57 UTC
(In reply to Nathan Scott from comment #9)
> > install -p -m644 ./bpfassets/libbpf/bpf.o/amd64_kepler.bpf.o %{buildroot}/var/lib/kepler/bpfassets/amd64_kepler.bpf.o
> 
> Is this amd64_kepler.bpf.o binary generated during the build or are we using
> the one from the git repo/tarball here?
> 
> For official Fedora builds, it will need to be built as part of the rpmbuild
> process (binary blobs are not allowed) and  that will result in a binary of
> the build system architecture (which is not necessarily x86_64).

eBPF binaries, regardless of arch, apparently look like x86_64 ELF blobs, which means the only way to distinguish them is by name...

Comment 13 Nathan Scott 2024-02-26 22:23:48 UTC
From the kepler git repo https://github.com/sustainable-computing-io/kepler.git ...

$ file ./bpfassets/libbpf/bpf.o/amd64_kepler.bpf.o 
./bpfassets/libbpf/bpf.o/amd64_kepler.bpf.o: ELF 64-bit LSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped

My question remains - is this built during the rpmbuild process or is it pulled from the tarball?  I believe it needs to be built locally as part of the Fedora build each time - 
https://docs.fedoraproject.org/en-US/packaging-guidelines/what-can-be-packaged/#prebuilt-binaries-or-libraries

New question :) - if this is platform-independent eBPF bytecode, why prefix the name with amd64?  For people on other arches this is going to be a source of confusion - looking at my aarch64 laptop and my confusion RN for example ;)

Comment 14 Nathan Scott 2024-02-26 22:49:08 UTC
Relevant excerpt from the packaging guidelines (link above):

| When you encounter prebuilt binaries in a package you MUST:
| 
|    Remove all pre-built program binaries and program libraries in %prep prior to the building of the package. Examples include, but are not limited to, *.class, *.dll, *.DS_Store, *.exe, *.jar, *.o, *.pyc, *.pyo, *.egg, *.so, *.swf files.
| 
|    Ask upstream to remove the binaries in their next release.

so kepler.spec needs a %prep section that removes ./bpfassets/libbpf/bpf.o/amd64_kepler.bpf.o prior to the build commencing.

Comment 15 Viktor Malik 2024-02-29 13:06:56 UTC
From specfile:

> BuildRequires: [...] libbpf

How does Kepler load the BPF program? I assume it uses libbpf so libbpf should be a runtime dependency (i.e. in "Requires"), unless you're linking against it statically.

On the contrary, I'd expect libbpf-devel in "BuildRequires".

> New question :) - if this is platform-independent eBPF bytecode, why prefix the name with amd64?  For people on other arches this is going to be a source of confusion - looking at my aarch64 laptop and my confusion RN for example ;)

Agreed with Nathan here. BPF binaries are arch-independent (they are ELFs with a special "BPF" architecture) so the prefix shouldn't be there.

>  I believe it needs to be built locally as part of the Fedora build each time

Despite being arch-independent, I agree that the binary should be rebuilt as a part of the specfile, as per Fedora guidelines.
In fact, IIUC, that's exactly what

> make genlibbpf _build_local GOOS=${GOOS} GOARCH=${GOARCH} ATTACHER_TAG=libbpf

in the specfile does. So you just need to remove ./bpfassets/libbpf/bpf.o/amd64_kepler.bpf.o in the %prep phase, as mentioned above.

Comment 16 Toke Høiland-Jørgensen 2024-03-07 19:36:43 UTC
(In reply to Neal Gompa from comment #7)
> > /var/lib/kepler/bpfassets/amd64_kepler.bpf.o
> 
> This should probably be installed into "%{_libexecdir}/kepler/bpfassets"
> instead.

Actually, we've been trying to establish %{_libdir}/bpf/ as the place to put BPF object files, cf: https://src.fedoraproject.org/rpms/xdp-tools/blob/rawhide/f/xdp-tools.spec#_105

However, it looks like the loader code hard-codes the location of the object file: https://github.com/sustainable-computing-io/kepler/blob/main/pkg/bpfassets/attacher/libbpf_attacher.go#L41

This should probably be changed so the Makefile can override it.

(In reply to Viktor Malik from comment #15)
> From specfile:
> 
> > BuildRequires: [...] libbpf
> 
> How does Kepler load the BPF program? I assume it uses libbpf so libbpf
> should be a runtime dependency (i.e. in "Requires"), unless you're linking
> against it statically.
> 
> On the contrary, I'd expect libbpf-devel in "BuildRequires".

Looking at the top-level Makefile, it does appear that Kepler links statically against libbpf: https://github.com/sustainable-computing-io/kepler/blob/main/Makefile#L51

Not sure if we have a policy for this in Fedora, but at least in RHEL this won't be allowed. So at some point this needs to be changed to link dynamically against the system libbpf.

> > New question :) - if this is platform-independent eBPF bytecode, why prefix the name with amd64?  For people on other arches this is going to be a source of confusion - looking at my aarch64 laptop and my confusion RN for example ;)
> 
> Agreed with Nathan here. BPF binaries are arch-independent (they are ELFs
> with a special "BPF" architecture) so the prefix shouldn't be there.

AFAICT from the Kepler sources, it's arch-specific because the build includes different versions of vmlinux.h depending on the defined architecture: https://github.com/sustainable-computing-io/kepler/blob/main/bpfassets/libbpf/src/kepler.bpf.h

This should not be necessary for most accesses, CO-RE can be used instead. I am not sure if there are some arch-specific structs that Kepler needs to access, though, and whether CO-RE can handle those.

Comment 17 Viktor Malik 2024-03-08 05:58:32 UTC
(In reply to Toke Høiland-Jørgensen from comment #16)
> 
> Looking at the top-level Makefile, it does appear that Kepler links
> statically against libbpf:
> https://github.com/sustainable-computing-io/kepler/blob/main/Makefile#L51
> 
> Not sure if we have a policy for this in Fedora, but at least in RHEL this
> won't be allowed. So at some point this needs to be changed to link
> dynamically against the system libbpf.

In Fedora, it is very much discouraged:

https://docs.fedoraproject.org/en-US/packaging-guidelines/#bundling

Comment 18 Matthew Yee 2024-04-17 18:34:45 UTC
Won't do.


Note You need to log in before you can comment on or make changes to this bug.