Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Use a different package to extract system information during host discovery #428

Merged
merged 2 commits into from
Nov 8, 2021

Conversation

nelsonkopliku
Copy link
Member

On demo we are projecting the HostTelemetry, but the current package is not able to properly extract CPU count.

This PR replaces it with https://github.com/shirou/gopsutil.

I have doubts on the physical/logical cpu stuff. Please let know if that would work

Comment on lines +94 to +99
infoStat, err := host.Info()
if err != nil {
log.Errorf("Error while getting host info: %s", err)
}
return infoStat.PlatformVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we get an error from host.Info()? We'll still have PlatformVersion inside infoStat?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will get its null value, in this case an empty string. I guess 😅

Comment on lines +102 to +107
v, err := mem.VirtualMemory()
if err != nil {
log.Errorf("Error while getting memory info: %s", err)
}
return int(v.Total) / 1024 / 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we got an empty struct if err != nil? I really don't know what we get

Copy link
Member Author

Choose a reason for hiding this comment

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

It will get the int zero value 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's risky, because we would be reporting 0 as metric, which is false.
We should handle the error cases and set the this discovery with a failed state, so the server knows that something wrong happened.

Copy link
Contributor

@dottorblaster dottorblaster left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

I think we should handle the error on these commands, to set the discovery in a failed/warning state.
We shouldn't report at least a 0 value. Maybe -1?
Or not report the value is it failed.

return infoStat.PlatformVersion
}

func getTotalMemoryMB() int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why this function is private? (starts with small letter)

Copy link
Member Author

Choose a reason for hiding this comment

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

No particular reason. No one is using it, except for this discovery.

When neede It could very well be public, or even an Interface to a service.
I kept it really simple.

Is that good enough for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just surprised because the other Get... function are using capital letter. I just noticed the difference and lack of consistency. Nothing else hehe

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, my bad, now I spotted.

They were supposed to be all private actually. Now I see I have all public except for one.
A leftover. Gonna make all private.

Thanks 🙏

Comment on lines +102 to +107
v, err := mem.VirtualMemory()
if err != nil {
log.Errorf("Error while getting memory info: %s", err)
}
return int(v.Total) / 1024 / 1024
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's risky, because we would be reporting 0 as metric, which is false.
We should handle the error cases and set the this discovery with a failed state, so the server knows that something wrong happened.

@nelsonkopliku
Copy link
Member Author

nelsonkopliku commented Nov 5, 2021

I think we should handle the error on these commands, to set the discovery in a failed/warning state. We shouldn't report at least a 0 value. Maybe -1? Or not report the value is it failed.

Thanks @arbulu89. I'd agree with you. Yet I am not confident on the way to go in that regard.
Since this telemetry thing is still super alpha, is that okay to postpone that? I'll track the thing.

agent/discovery/host.go Outdated Show resolved Hide resolved
@rtorrero
Copy link
Contributor

rtorrero commented Nov 7, 2021

After a bit of thought, I think this was the right decision. Tracking core counts of VMs also makes sense, and in the future we could add checks to report if the agent is running behind a hypervisor.

Good job! (just left a comment at some small detail I think we should change before merging)

@rtorrero
Copy link
Contributor

rtorrero commented Nov 8, 2021

It looks good to me now, thanks :-)!

@nelsonkopliku nelsonkopliku merged commit bb9eb66 into trento-project:main Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants