Skip to content

Commit

Permalink
[receiver/vcenter] Adds vApp Resource Attributes to Relevant VM Resou…
Browse files Browse the repository at this point in the history
…rces (#32673)

**Description:** <Describe what has changed.>
When VMs have a vApp parent rather than a Resource Pool parent, rather
than `vcenter.resource_pool.name` and
`vcenter.resource_pool.inventory_path` resource attributes getting added
to the VM resource, `vcenter.virtual_app.name` and
`vcenter.virtual_app.inventory_path` resource attributes will be added
for that VM instead. This way, VMs directly under vApps can still be
human identifiable (especially if multiple VMs share the same name).

These new attributes will be disabled by default and will have to be
manually enabled in the config.

**Link to tracking Issue:** <Issue number if applicable>
#32557 

**Testing:** <Describe what testing was performed and which tests were
added.>
Unit/integration tests updated and tested. Local environment tested.

**Documentation:** <Describe the documentation added.>
New documentation generated based on the metadata.
  • Loading branch information
StefanKurek authored Apr 25, 2024
1 parent dc68260 commit 2dbdca3
Show file tree
Hide file tree
Showing 19 changed files with 266 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix_vcenter-vapp-attrs-on-vms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: vcenterreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adds new `vcenter.virtual_app.name` and `vcenter.virtual_app.inventory_path` resource attributes to appropriate VM Resources"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32557]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
16 changes: 16 additions & 0 deletions receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vcenterreceiver // import "github.com/open-telemetry/opentelemetry-colle

import (
"context"
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -112,6 +113,20 @@ func (vc *vcenterClient) ResourcePools(ctx context.Context) ([]*object.ResourceP
return rps, err
}

// VirtualApps returns the VirtualApps in the vSphere SDK
func (vc *vcenterClient) VirtualApps(ctx context.Context) ([]*object.VirtualApp, error) {
vApps, err := vc.finder.VirtualAppList(ctx, "*")
if err != nil {
var notFoundErr *find.NotFoundError
if errors.As(err, &notFoundErr) {
return []*object.VirtualApp{}, nil
}

return nil, fmt.Errorf("unable to retrieve vApps: %w", err)
}
return vApps, err
}

func (vc *vcenterClient) VMs(ctx context.Context) ([]mo.VirtualMachine, error) {
v, err := vc.vm.CreateContainerView(ctx, vc.vimDriver.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
if err != nil {
Expand All @@ -135,6 +150,7 @@ func (vc *vcenterClient) VMs(ctx context.Context) ([]mo.VirtualMachine, error) {
"summary.storage.uncommitted",
"summary.runtime.host",
"resourcePool",
"parentVApp",
}, &vms)
if err != nil {
return nil, fmt.Errorf("unable to retrieve VMs: %w", err)
Expand Down
19 changes: 19 additions & 0 deletions receiver/vcenterreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ func TestGetResourcePools(t *testing.T) {
})
}

func TestGetVirtualApps(t *testing.T) {
// Currently some issue with how the simulator creates vApps.
// It is created (VMs show up with it in the inventory path)
// but it is not returned by the finder call in this tested method.
t.Skip()
model := simulator.VPX()
model.App = 1
simulator.Test(func(ctx context.Context, c *vim25.Client) {
finder := find.NewFinder(c)
client := vcenterClient{
vimDriver: c,
finder: finder,
}
vApps, err := client.VirtualApps(ctx)
require.NoError(t, err)
require.NotEmpty(t, vApps)
}, model)
}

func TestGetVMs(t *testing.T) {
simulator.Test(func(ctx context.Context, c *vim25.Client) {
viewManager := view.NewManager(c)
Expand Down
2 changes: 2 additions & 0 deletions receiver/vcenterreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,5 +471,7 @@ The memory utilization of the VM.
| vcenter.host.name | The hostname of the vCenter ESXi host. | Any Str | true |
| vcenter.resource_pool.inventory_path | The inventory path of the resource pool. | Any Str | true |
| vcenter.resource_pool.name | The name of the resource pool. | Any Str | true |
| vcenter.virtual_app.inventory_path | The inventory path of the vApp. | Any Str | false |
| vcenter.virtual_app.name | The name of the vApp. | Any Str | false |
| vcenter.vm.id | The instance UUID of the virtual machine. | Any Str | true |
| vcenter.vm.name | The name of the virtual machine. | Any Str | true |

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions receiver/vcenterreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions receiver/vcenterreceiver/internal/metadata/generated_resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions receiver/vcenterreceiver/internal/metadata/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ all_set:
enabled: true
vcenter.resource_pool.name:
enabled: true
vcenter.virtual_app.inventory_path:
enabled: true
vcenter.virtual_app.name:
enabled: true
vcenter.vm.id:
enabled: true
vcenter.vm.name:
Expand Down Expand Up @@ -189,6 +193,10 @@ none_set:
enabled: false
vcenter.resource_pool.name:
enabled: false
vcenter.virtual_app.inventory_path:
enabled: false
vcenter.virtual_app.name:
enabled: false
vcenter.vm.id:
enabled: false
vcenter.vm.name:
Expand Down Expand Up @@ -219,6 +227,14 @@ filter_set_include:
enabled: true
metrics_include:
- regexp: ".*"
vcenter.virtual_app.inventory_path:
enabled: true
metrics_include:
- regexp: ".*"
vcenter.virtual_app.name:
enabled: true
metrics_include:
- regexp: ".*"
vcenter.vm.id:
enabled: true
metrics_include:
Expand Down Expand Up @@ -253,6 +269,14 @@ filter_set_exclude:
enabled: true
metrics_exclude:
- strict: "vcenter.resource_pool.name-val"
vcenter.virtual_app.inventory_path:
enabled: true
metrics_exclude:
- strict: "vcenter.virtual_app.inventory_path-val"
vcenter.virtual_app.name:
enabled: true
metrics_exclude:
- strict: "vcenter.virtual_app.name-val"
vcenter.vm.id:
enabled: true
metrics_exclude:
Expand Down
10 changes: 10 additions & 0 deletions receiver/vcenterreceiver/internal/mockserver/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ func routeRetreiveProperties(t *testing.T, body map[string]any) ([]byte, error)

switch {
case content == "group-d1" && contentType == "Folder":
for _, i := range propSetArray {
m, ok := i.(map[string]any)
require.True(t, ok)
if m["pathSet"] == "parentVApp" && m["type"] == "VirtualMachine" {
return loadResponse("datacenter-list.xml")
}
}
return loadResponse("datacenter.xml")

case content == "datacenter-3" && contentType == "Datacenter":
Expand Down Expand Up @@ -199,6 +206,9 @@ func routeRetreiveProperties(t *testing.T, body map[string]any) ([]byte, error)
return loadResponse("virtual-app-children.xml")
}
}
if _, ok := propSet["pathSet"].([]any); ok {
return loadResponse("virtual-app-properties.xml")
}
if ps, ok := propSet["pathSet"].(string); ok {
if ps == "owner" {
return loadResponse("virtual-app-owner.xml")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<RetrievePropertiesResponse xmlns="urn:vim25">
<returnval>
<obj type="VirtualApp">resgroup-v10</obj>
<propSet>
<name>name</name>
<val xsi:type="xsd:string">v-app-1</val>
</propSet>
<propSet>
<name>vm</name>
<val xsi:type="ArrayOfManagedObjectReference">
<ManagedObjectReference type="VirtualMachine"
xsi:type="ManagedObjectReference">vm-6004</ManagedObjectReference>
</val>
</propSet>
</returnval>
</RetrievePropertiesResponse>
</soapenv:Body>
</soapenv:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<RetrievePropertiesResponse xmlns="urn:vim25">
<returnval>
<obj type="VirtualApp">resgroup-v10</obj>
<propSet>
<name>name</name>
<val xsi:type="xsd:string">v-app-1</val>
</propSet>
</returnval>
</RetrievePropertiesResponse>
</soapenv:Body>
</soapenv:Envelope>
Loading

0 comments on commit 2dbdca3

Please sign in to comment.