Skip to content

Conversation

brett060102
Copy link
Collaborator

@brett060102 brett060102 commented Jul 17, 2025

Add collection of lsmod and PCI data to the hwdata infor block

This done by adding a collector that will invoke
lspci -s .0 and lsmod

Requires adding pciutils to required package for suseconnect

The size of the additional payload in the heartbeat depends on how many pci devices are on the system and
number of modules loaded into the kernel. See:
https://confluence.suse.com/display/publiccloud/Design+-+PCI+Data+Collection
For more information.

Copy link
Contributor

@mssola mssola left a comment

Choose a reason for hiding this comment

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

In a more general comment, please use goimports/gofmt. As in, your Go environment does not align at all with Go's coding conventions. This is something that should've been detected via our CI, but we never bothered to do so 😅 Hence, take a look at that, and run make check-format to ensure that your code is up to Go's coding conventions.

@brett060102
Copy link
Collaborator Author

Thank you for "gofmt" reference. I did not know about it. Does make things easier.

@brett060102 brett060102 changed the base branch from main to next August 11, 2025 20:38
@mssola
Copy link
Contributor

mssola commented Aug 12, 2025

By the way, does the WIP label still apply for this PR?

@brett060102
Copy link
Collaborator Author

yes, this should stay WIP for now. We don't want this to land until we know how it would effect RMT's and SCC.

@mssola
Copy link
Contributor

mssola commented Aug 13, 2025

Ok, then I will not review this further. Ping me again when you need another review.

@brett060102
Copy link
Collaborator Author

@mssola Thank you very much for all of your comments and inputs on this. It has helped a lot.

@brett060102 brett060102 force-pushed the pci-collector branch 2 times, most recently from b8e8271 to 06e5d40 Compare August 13, 2025 16:49
@mssola mssola force-pushed the next branch 2 times, most recently from ba2362b to 3b96875 Compare August 19, 2025 10:58
@brett060102 brett060102 force-pushed the pci-collector branch 2 times, most recently from 677ec83 to a82952b Compare August 27, 2025 06:19
Base automatically changed from next to main September 2, 2025 10:15
@brett060102 brett060102 force-pushed the pci-collector branch 7 times, most recently from 3cc85cd to ff353d9 Compare September 9, 2025 19:23
@brett060102 brett060102 force-pushed the pci-collector branch 9 times, most recently from 16cf9bc to 4dcd889 Compare September 16, 2025 15:56
@brett060102 brett060102 force-pushed the pci-collector branch 4 times, most recently from ce9ae58 to 92c1d95 Compare October 1, 2025 17:23
@brett060102 brett060102 force-pushed the pci-collector branch 2 times, most recently from e213f15 to 8e70bb4 Compare October 16, 2025 18:33
os.Exit(0)
} else if deRegister {
// Need to clear ProfileCache on deregister
// even if dereg does not succeed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: didn't this comment fit into a single line?

exitOnError(errors.New("cannot use the json option with the 'cleanup' command"), api, opts)
}
// Need to clear ProfileCache on cleanup
// even if cleanup does not succeed.
Copy link
Contributor

Choose a reason for hiding this comment

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

idem


err := connect.Register(api, opts)
if err != nil {
// clear profile cache on registration errors
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: capitalize first word.

}

func exitOnError(err error, api connect.WrappedAPI, opts *connect.Options) {
util.Debug.Println("exitOnError err: ", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this handled on each if block so it's more specific?

)

type Result = map[string]interface{}
type Result = util.Result
Copy link
Contributor

Choose a reason for hiding this comment

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

This Result could probably go into pkg/, as it's used in different places. But also bear in mind my comments on profiles 😉

@@ -0,0 +1,124 @@
package util
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this probably belongs to pkg/, as users of this library might be interested on this very topic as well. Note that for some time we also wanted to export the collectors into this public library, but we ended up too busy with other stuff 😄

As for SUSEConnect-specific things, maybe they can be brought in as parameters? Note that you are already passing arguments such us cacheFile.

ProfileData any `json:"profileData"` // Data associated with ProfileI
}

func UpdateCache(updateCache bool, tag string, cacheFile string, dataBlock any) (Result, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Exported function needs documentation. Other than that:

  • To me it feels weird to have a function called UpdateCache which has as a first parameter a boolean on whether you want to update the cache or not. This feels off.
  • Maybe instead of tag, identifier, or profileName?
  • In the documentation, please specify whether cacheFile is just the name, the full path, etc.

//
// ProfileData: can be any data such array of strings, a single large string
type Profile struct {
ProfileID string `json:"profileId"` // Sha256 of ProfileData
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't document members inline. But other than that, the naming feels redundant. As in, if the struct is named Profile, there's no need to include Profile* in the member's names. Moreover, this is not a profile "id", but a checksum, as you clearly document. Hence, why not simply:

type Profile struct {
	Checksum string `json:"checksum"`
	Data     string `json:"data"`
}

This way documentation is not even needed as it pretty clear what each thing refers to, and anyways the documentation of the type you have provided is more than enough.

Also note that I turned Data into a string, as that's good enough. Users of the Profile struct should do the marshaling themselves, but looking at the code, everything is a string anyways, so there's no need for marshaling nor to be cryptic about the type.

func UpdateCache(updateCache bool, tag string, cacheFile string, dataBlock any) (Result, error) {

var hashInput = ""
switch v := dataBlock.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As detailed before, let it be a string and avoid type casting shenanigans.

func SetProfileFilePath(newPath string) {
profileFilePath = newPath
if profileFilePath[len(profileFilePath)-1] != '/' {
profileFilePath = profileFilePath + "/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use filepath.Join instead.

@brett060102 brett060102 force-pushed the pci-collector branch 3 times, most recently from 9c801a3 to bb90fb7 Compare October 17, 2025 20:22
  and some debug to wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants