-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[WIP] Collect domain memory stat from KVM #6265
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@@ -0,0 +1,129 @@ | |||
package domain_memory |
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 use an underscore in package name
@amandahla Do you know what happens in the background / lib? Does it talk to an API or executes a binary? |
I understand that the go-libvirt make a local ("unix", "/var/run/libvirt/libvirt-sock") or RPC ("tcp", "192.168.1.12:16509") connection to the libvirt daemon. Then we can make the same thing that the virsh command does. |
I would prefer if we don't execute any binaries if possible so I'm tempted to go the RPC direction for now. @andrewkroh Thouhgs? |
Sorry @ruflin but I understand that the library connects to the libvirt daemon without executing any binaries. I used the virsh command only as a reference. |
👍 Good. At some point in the near future we will likely add a seccomp filter that prohibits execs (#5213). |
@amandahla I wonder what the next steps are you had in mind here? Seems like the PR is pretty close to be complete? |
@ruflin I think that I only need to write the tests. Is there anything else? |
Thinking about it...Should I use "Fetch(report mb.ReporterV2)"? I didn't find something like "mbtest.NewEventFetcher" for this to write the test. |
Sorry, the missing test utility was an oversight on my part. Similar to NewReportingMetricSet there should be a |
metricbeat/mb/testing/modules.go
Outdated
r.events = append(r.events, event) | ||
return true | ||
} | ||
func ReportingFetchV2(metricSet mb.ReportingMetricSetV2) []mb.Event { |
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 ReportingFetchV2 should have comment or be unexported
@andrewkroh I'm not sure if I did right but here it is :) |
I ended up needing this too for testing the perfmon metricset and added |
@andrewkroh Great, thanks! I didn't saw that. Now I removed what I did. |
@amandahla Is this PR ready for review? |
jenkins, test it |
@ruflin Yes, is ready. |
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.
I have added some comments. Please add also an entry to the changelog, and if possible a data.json
. Thanks for this new module!
NOTICE.txt
Outdated
-------------------------------------------------------------------- | ||
Dependency: github.com/digitalocean/go-libvirt | ||
Revision: 59d541f19311883ad82708651353009fb207d8a9 | ||
License type (autodetected): UNKNOWN |
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.
@ruflin @andrewkroh can this be manually corrected?
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.
@jsoriano No. Do you know the license type? We should update our script to detect the right one.
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.
It seems to be Apache
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.
The file that checks all the licenses is here: https://github.com/elastic/beats/blob/master/dev-tools/generate_notice.py Probably need some regexp / contains adjustements.
@tsg @monicasarbu FYI
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.
These markdown formatted licenses seem to come from here: https://github.com/IQAndreas/markdown-licenses in the README it says: licenses are read by humans, not computers
:)
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.
I have created a PR to add this license #6632
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.
So much about assumption who is going to be your user :-) #6632 got merged.
metricbeat/docs/modules/kvm.asciidoc
Outdated
---- | ||
metricbeat.modules: | ||
- module: kvm | ||
metricsets: ["memory"] |
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.
Metricset name is memory
or dommemstat
? Maybe memory
is a good name, out of implementation details :) but for the rest of the PR it seems to be dommemstat
.
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.
I changed from "memory" to "dommemstat" to be consistent with the virsh command parameters to domain monitoring. It seems that I forgot to change this file :|
cfgwarn.Experimental("The kvm dommemstat metricset is experimental.") | ||
|
||
config := struct{}{} | ||
if err := base.Module().UnpackConfig(&config); err != nil { |
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.
No needed if there is no custom configuration.
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.
@amandahla could you also remove this?
// when running tests, a mock Libvirt server is used | ||
c = libvirttest.New() | ||
} else { | ||
c, err = net.DialTimeout(m.separatedURI[0], m.separatedURI[1], 2*time.Second) |
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.
Timeout could be obtained from configuration as in https://github.com/elastic/beats/blob/master/metricbeat/module/munin/node/node.go#L45
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.
Done
|
||
return &MetricSet{ | ||
BaseMetricSet: base, | ||
separatedURI: strings.Split(base.HostData().URI, "://"), |
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.
Could we have here a safer parsing? Maybe using url.Parse
. If protocol is not present in the host configuration, m.separatedURI[1]
will panic on Fetch
.
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.
Done
// when running tests, a mock Libvirt server is used | ||
c = libvirttest.New() | ||
} else { | ||
c, err = net.DialTimeout(m.separatedURI[0], m.separatedURI[1], 2*time.Second) |
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.
@andrewkroh @ruflin we might want to offer some kind of high-level "Dialer" that handles connections using info in BaseMetricSet
. I guess lots of modules support unix/tcp and/or have to parse urls, handle with tls, timeouts configs... wdyt? do we already have something similar?
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.
We have a http helper which contains the base metricset: https://github.com/elastic/beats/blob/master/metricbeat/helper/http.go#L19 Perhaps we can do in the future something similar?
c, err = net.DialTimeout(m.separatedURI[0], m.separatedURI[1], 2*time.Second) | ||
if err != nil { | ||
report.Error(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.
defer c.Close()
?
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.
Done.
} | ||
|
||
for _, d := range domains { | ||
l.DomainMemoryStats(d, 8, 0) |
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.
Is it needed?
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.
Actually no, my mistake. :|
for _, d := range domains { | ||
l.DomainMemoryStats(d, 8, 0) | ||
|
||
gotDomainMemoryStats, err := l.DomainMemoryStats(d, 8, 0) |
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.
What are these 8 an 0? Would it make sense to set them from constants?
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.
8 -> Maximum stats that you want
0 -> Flags that you can pass
Actually it would be better to change to 11 since we have 11 possible stats and to set constants.
@@ -0,0 +1,9 @@ | |||
- name: dommemstat |
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.
We should complete the fields.yml here and have a system tests that validates that all fields are documented.
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.
@amandahla could you complete this fields file?
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.
It is fine to refer the issue in the commit message, but could you add additional information there about the change? Thanks!
metricbeat/metricbeat.reference.yml
Outdated
@@ -317,6 +317,14 @@ metricbeat.modules: | |||
metricsets: | |||
- event | |||
|
|||
#--------------------------------- kvm Module -------------------------------- | |||
- module: kvm | |||
metricsets: ["memory"] |
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.
memory
still here, you may need to run make update
again.
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.
Done :)
|
||
u, err := url.Parse(m.Host()) | ||
if err != nil { | ||
report.Error(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.
This parsing could be done in New
so it is done only once. If it's kept here add a return
after reporting the Error so it doesn't continue.
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.
Moved to New, thanks!
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.
Thanks for your changes. It mostly LGTM, there are a couple of comments that I think should be addressed before merging (deleting the empty custom config and filling the fields file), others can probably be done in future PRs as the module is going to be merged as experimental.
cfgwarn.Experimental("The kvm dommemstat metricset is experimental.") | ||
|
||
config := struct{}{} | ||
if err := base.Module().UnpackConfig(&config); err != nil { |
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.
@amandahla could you also remove this?
hosts: ["localhost"] | ||
|
||
# Timeout to connect to Libvirt server | ||
#timeout: 1s |
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.
@ruflin we will have to add a reference config and default metricsets, as this module is experimental I think this can be left for a future PR
@@ -0,0 +1,9 @@ | |||
- name: dommemstat |
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.
@amandahla could you complete this fields file?
@amandahla Any chance you find some time to push this forward in the near future? Would be nice to have the code in. Let us know if we can help somehow. |
Sorry for the delay! Finally the commit with the changes asked. |
jenkins, test this please |
@@ -0,0 +1,8 @@ | |||
- module: kvm | |||
metricsets: ["dommemstat"] | |||
enabled: false |
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.
@exekias If this module is going to be enabled, will the enabled
config be overwritten?
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.
nope, I think we should remove the enabled
setting here
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.
@jsoriano I suggest we merge the PR and to a follow up PR to adjust the config and config reference file to our most recent logic.
Merged, thanks @amandahla ! |
Just to start discussion about the implementation.
It collects the same output from the command "virsh dommemstat ".
Reference: #4402