-
Notifications
You must be signed in to change notification settings - Fork 21
Add collector to get pci device data #320
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
base: main
Are you sure you want to change the base?
Conversation
292be7c
to
1ece975
Compare
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.
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.
Thank you for "gofmt" reference. I did not know about it. Does make things easier. |
1ece975
to
82b34b2
Compare
By the way, does the |
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. |
82b34b2
to
5585dd7
Compare
Ok, then I will not review this further. Ping me again when you need another review. |
@mssola Thank you very much for all of your comments and inputs on this. It has helped a lot. |
b8e8271
to
06e5d40
Compare
ba2362b
to
3b96875
Compare
677ec83
to
a82952b
Compare
3cc85cd
to
ff353d9
Compare
ff353d9
to
94faef2
Compare
16cf9bc
to
4dcd889
Compare
ce9ae58
to
92c1d95
Compare
92c1d95
to
0e16f52
Compare
e213f15
to
8e70bb4
Compare
os.Exit(0) | ||
} else if deRegister { | ||
// Need to clear ProfileCache on deregister | ||
// even if dereg does not succeed. |
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.
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. |
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.
idem
|
||
err := connect.Register(api, opts) | ||
if err != nil { | ||
// clear profile cache on registration errors |
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.
Nit: capitalize first word.
} | ||
|
||
func exitOnError(err error, api connect.WrappedAPI, opts *connect.Options) { | ||
util.Debug.Println("exitOnError err: ", err) |
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.
Isn't this handled on each if block so it's more specific?
) | ||
|
||
type Result = map[string]interface{} | ||
type Result = util.Result |
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.
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 |
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.
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) { |
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.
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
, orprofileName
? - 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 |
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.
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) { |
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.
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 + "/" |
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.
Use filepath.Join
instead.
9c801a3
to
bb90fb7
Compare
and some debug to wrapper
bb90fb7
to
45dc5e0
Compare
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.