Skip to content
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

Merged
merged 1 commit into from
Apr 19, 2018
Merged

[WIP] Collect domain memory stat from KVM #6265

merged 1 commit into from
Apr 19, 2018

Conversation

amandahla
Copy link

@amandahla amandahla commented Feb 2, 2018

Just to start discussion about the implementation.
It collects the same output from the command "virsh dommemstat ".

Reference: #4402

@elasticmachine
Copy link
Collaborator

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

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

@ruflin
Copy link
Contributor

ruflin commented Feb 5, 2018

@amandahla Do you know what happens in the background / lib? Does it talk to an API or executes a binary?

@amandahla
Copy link
Author

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.
But there is a warning about RPC connections here: "The libvirt project strongly recommends against talking to the RPC interface directly. They consider it to be a private implementation detail with the possibility of being entirely rearchitected in the future."

@ruflin
Copy link
Contributor

ruflin commented Feb 9, 2018

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?

@amandahla
Copy link
Author

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.
Did I get it wrong? :|

@andrewkroh
Copy link
Member

the library connects to the libvirt daemon without executing any binaries

👍 Good. At some point in the near future we will likely add a seccomp filter that prohibits execs (#5213).

@ruflin
Copy link
Contributor

ruflin commented Feb 27, 2018

@amandahla I wonder what the next steps are you had in mind here? Seems like the PR is pretty close to be complete?

@amandahla
Copy link
Author

@ruflin I think that I only need to write the tests. Is there anything else?

@amandahla
Copy link
Author

Thinking about it...Should I use "Fetch(report mb.ReporterV2)"? I didn't find something like "mbtest.NewEventFetcher" for this to write the test.

@andrewkroh
Copy link
Member

Sorry, the missing test utility was an oversight on my part.

Similar to NewReportingMetricSet there should be a NewReportingMetricSetV2 helper in mb/testing. Would you want to add the new test helper?

r.events = append(r.events, event)
return true
}
func ReportingFetchV2(metricSet mb.ReportingMetricSetV2) []mb.Event {

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

@amandahla
Copy link
Author

@andrewkroh I'm not sure if I did right but here it is :)

@andrewkroh
Copy link
Member

I ended up needing this too for testing the perfmon metricset and added NewReportingMetricSetV2 and ReportingFetchV2 in d4eac97. I was going to leave a note here after it merged and I totally forgot. Can you see if what I added works for your testing.

@amandahla
Copy link
Author

@andrewkroh Great, thanks! I didn't saw that. Now I removed what I did.

@ruflin
Copy link
Contributor

ruflin commented Mar 21, 2018

@amandahla Is this PR ready for review?

@ruflin
Copy link
Contributor

ruflin commented Mar 21, 2018

jenkins, test it

@amandahla
Copy link
Author

@ruflin Yes, is ready.

Copy link
Member

@jsoriano jsoriano left a 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
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Contributor

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

Copy link
Member

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 :)

Copy link
Member

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

Copy link
Contributor

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.modules:
- module: kvm
metricsets: ["memory"]
Copy link
Member

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.

Copy link
Author

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 {
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

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, "://"),
Copy link
Member

@jsoriano jsoriano Mar 21, 2018

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.

Copy link
Author

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)
Copy link
Member

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?

Copy link
Contributor

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)
}
Copy link
Member

Choose a reason for hiding this comment

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

defer c.Close()?

Copy link
Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

Is it needed?

Copy link
Author

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)
Copy link
Member

@jsoriano jsoriano Mar 21, 2018

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?

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Member

@jsoriano jsoriano left a 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!

@@ -317,6 +317,14 @@ metricbeat.modules:
metricsets:
- event

#--------------------------------- kvm Module --------------------------------
- module: kvm
metricsets: ["memory"]
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Moved to New, thanks!

Copy link
Member

@jsoriano jsoriano left a 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 {
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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?

@ruflin
Copy link
Contributor

ruflin commented Apr 18, 2018

@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.

@amandahla
Copy link
Author

Sorry for the delay! Finally the commit with the changes asked.

@jsoriano
Copy link
Member

jenkins, test this please

@@ -0,0 +1,8 @@
- module: kvm
metricsets: ["dommemstat"]
enabled: false
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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.

@jsoriano jsoriano merged commit ccd8a31 into elastic:master Apr 19, 2018
@jsoriano
Copy link
Member

Merged, thanks @amandahla !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants