-
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
Add support of snapshot in vSphere virtualmachine metricset #40683
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
/test |
@ishleenk17 please add entry in ascii.next file. |
Please update |
There is no way to test this, due to unavailability of snapshots. Hence its not updated. |
I understand, But the main prepose of data.json is to give idea about event that is going to be produced. I think we should add dummy fields because it would capture structure of our event. |
I think it is possible to write a mock (see example) but given the strict timeline we can take it up in future to properly generate the data.json. For now, we can go with dummy. |
diff --git a/metricbeat/module/vsphere/virtualmachine/data.go b/metricbeat/module/vsphere/virtualmachine/data.go
index 69d0bd1df5..bc29c1f8ef 100644
--- a/metricbeat/module/vsphere/virtualmachine/data.go
+++ b/metricbeat/module/vsphere/virtualmachine/data.go
@@ -72,9 +72,9 @@ func (m *MetricSet) mapEvent(data VMData) mapstr.M {
if len(data.DatastoreNames) > 0 {
event["datastore.names"] = data.DatastoreNames
}
- if len(data.Snapshots) > 0 {
+ if n := len(data.Snapshots); n > 0 {
event["snapshot.info"] = data.Snapshots
- event["snapshot.count"] = len(data.Snapshots)
+ event["snapshot.count"] = n
}
return event
diff --git a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go
index 81052e1eed..071c4f6cfb 100644
--- a/metricbeat/module/vsphere/virtualmachine/virtualmachine.go
+++ b/metricbeat/module/vsphere/virtualmachine/virtualmachine.go
@@ -61,6 +61,10 @@ type VMData struct {
}
type VMSnapshotData struct {
+ ID int32
+ State string
+ Quiesced bool
+ Age time.Duration
Name string
Description string
CreateTime time.Time
@@ -286,9 +290,12 @@ func getHostSystem(ctx context.Context, c *vim25.Client, ref types.ManagedObject
}
func fetchSnapshots(snapshotTree []types.VirtualMachineSnapshotTree) []VMSnapshotData {
- var snapshots []VMSnapshotData
+ snapshots := make([]VMSnapshotData, 0, len(snapshotTree))
for _, snapshot := range snapshotTree {
snapshots = append(snapshots, VMSnapshotData{
+ ID: snapshot.Id,
+ State: string(snapshot.State),
+ Quiesced: snapshot.Quiesced,
Name: snapshot.Name,
Description: snapshot.Description,
CreateTime: snapshot.CreateTime, Code added looks good. Just have a couple of things to suggest as you can see from the patch:
Quiesced definition:
|
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.
Left one comment to address. Everything else looks good. So, approving!
State and ID could be helpful, so adding those. Quiesced is not required IMO. |
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.
LGTM
@ishleenk17 I was working on alerts and i found that the way in which we define snapshot field, does not work. It will create field with name We have to change it. |
I agree with this point to make it small-case. But I'm curious; if field names are not in small-case, alerts don't work? |
* Add support of snapshot in virtualmachine * mage update and add fields.yml * Update data_test.go * address comments, mage update * Lint error * Add createtime * Update CHANGELOG.next.asciidoc * Add state and id for snapshot * update changelog * lint change * lint change (cherry picked from commit 7f29f60) # Conflicts: # metricbeat/docs/fields.asciidoc # metricbeat/module/vsphere/fields.go # metricbeat/module/vsphere/virtualmachine/_meta/data.json # metricbeat/module/vsphere/virtualmachine/_meta/fields.yml # metricbeat/module/vsphere/virtualmachine/data.go # metricbeat/module/vsphere/virtualmachine/data_test.go # metricbeat/module/vsphere/virtualmachine/virtualmachine.go
* Add support of snapshot in virtualmachine * mage update and add fields.yml * Update data_test.go * address comments, mage update * Lint error * Add createtime * Update CHANGELOG.next.asciidoc * Add state and id for snapshot * update changelog * lint change * lint change
…hine metricset (#40830) * Add support of snapshot in vSphere virtualmachine metricset (#40683) * Add support of snapshot in virtualmachine * mage update and add fields.yml * Update data_test.go * address comments, mage update * Lint error * Add createtime * Update CHANGELOG.next.asciidoc * Add state and id for snapshot * update changelog * lint change * lint change * Update CHANGELOG.next.asciidoc * Update CHANGELOG.next.asciidoc
Add support of adding snapshot details to the Virtualmachine object in Vsphere.
It caters to the snapshot and any childsnapshots as well.
Relates: https://github.com/elastic/obs-integration-team/issues/34