Skip to content

Commit 2dbdca3

Browse files
authored
[receiver/vcenter] Adds vApp Resource Attributes to Relevant VM Resources (open-telemetry#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> open-telemetry#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.
1 parent dc68260 commit 2dbdca3

19 files changed

+266
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: vcenterreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Adds new `vcenter.virtual_app.name` and `vcenter.virtual_app.inventory_path` resource attributes to appropriate VM Resources"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [32557]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/vcenterreceiver/client.go

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package vcenterreceiver // import "github.com/open-telemetry/opentelemetry-colle
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"net/url"
1011

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

116+
// VirtualApps returns the VirtualApps in the vSphere SDK
117+
func (vc *vcenterClient) VirtualApps(ctx context.Context) ([]*object.VirtualApp, error) {
118+
vApps, err := vc.finder.VirtualAppList(ctx, "*")
119+
if err != nil {
120+
var notFoundErr *find.NotFoundError
121+
if errors.As(err, &notFoundErr) {
122+
return []*object.VirtualApp{}, nil
123+
}
124+
125+
return nil, fmt.Errorf("unable to retrieve vApps: %w", err)
126+
}
127+
return vApps, err
128+
}
129+
115130
func (vc *vcenterClient) VMs(ctx context.Context) ([]mo.VirtualMachine, error) {
116131
v, err := vc.vm.CreateContainerView(ctx, vc.vimDriver.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
117132
if err != nil {
@@ -135,6 +150,7 @@ func (vc *vcenterClient) VMs(ctx context.Context) ([]mo.VirtualMachine, error) {
135150
"summary.storage.uncommitted",
136151
"summary.runtime.host",
137152
"resourcePool",
153+
"parentVApp",
138154
}, &vms)
139155
if err != nil {
140156
return nil, fmt.Errorf("unable to retrieve VMs: %w", err)

receiver/vcenterreceiver/client_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ func TestGetResourcePools(t *testing.T) {
4747
})
4848
}
4949

50+
func TestGetVirtualApps(t *testing.T) {
51+
// Currently some issue with how the simulator creates vApps.
52+
// It is created (VMs show up with it in the inventory path)
53+
// but it is not returned by the finder call in this tested method.
54+
t.Skip()
55+
model := simulator.VPX()
56+
model.App = 1
57+
simulator.Test(func(ctx context.Context, c *vim25.Client) {
58+
finder := find.NewFinder(c)
59+
client := vcenterClient{
60+
vimDriver: c,
61+
finder: finder,
62+
}
63+
vApps, err := client.VirtualApps(ctx)
64+
require.NoError(t, err)
65+
require.NotEmpty(t, vApps)
66+
}, model)
67+
}
68+
5069
func TestGetVMs(t *testing.T) {
5170
simulator.Test(func(ctx context.Context, c *vim25.Client) {
5271
viewManager := view.NewManager(c)

receiver/vcenterreceiver/documentation.md

+2
Original file line numberDiff line numberDiff line change
@@ -471,5 +471,7 @@ The memory utilization of the VM.
471471
| vcenter.host.name | The hostname of the vCenter ESXi host. | Any Str | true |
472472
| vcenter.resource_pool.inventory_path | The inventory path of the resource pool. | Any Str | true |
473473
| vcenter.resource_pool.name | The name of the resource pool. | Any Str | true |
474+
| vcenter.virtual_app.inventory_path | The inventory path of the vApp. | Any Str | false |
475+
| vcenter.virtual_app.name | The name of the vApp. | Any Str | false |
474476
| vcenter.vm.id | The instance UUID of the virtual machine. | Any Str | true |
475477
| vcenter.vm.name | The name of the virtual machine. | Any Str | true |

receiver/vcenterreceiver/internal/metadata/generated_config.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/vcenterreceiver/internal/metadata/generated_config_test.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/vcenterreceiver/internal/metadata/generated_metrics.go

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/vcenterreceiver/internal/metadata/generated_metrics_test.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/vcenterreceiver/internal/metadata/generated_resource.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/vcenterreceiver/internal/metadata/generated_resource_test.go

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/vcenterreceiver/internal/metadata/testdata/config.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ all_set:
9292
enabled: true
9393
vcenter.resource_pool.name:
9494
enabled: true
95+
vcenter.virtual_app.inventory_path:
96+
enabled: true
97+
vcenter.virtual_app.name:
98+
enabled: true
9599
vcenter.vm.id:
96100
enabled: true
97101
vcenter.vm.name:
@@ -189,6 +193,10 @@ none_set:
189193
enabled: false
190194
vcenter.resource_pool.name:
191195
enabled: false
196+
vcenter.virtual_app.inventory_path:
197+
enabled: false
198+
vcenter.virtual_app.name:
199+
enabled: false
192200
vcenter.vm.id:
193201
enabled: false
194202
vcenter.vm.name:
@@ -219,6 +227,14 @@ filter_set_include:
219227
enabled: true
220228
metrics_include:
221229
- regexp: ".*"
230+
vcenter.virtual_app.inventory_path:
231+
enabled: true
232+
metrics_include:
233+
- regexp: ".*"
234+
vcenter.virtual_app.name:
235+
enabled: true
236+
metrics_include:
237+
- regexp: ".*"
222238
vcenter.vm.id:
223239
enabled: true
224240
metrics_include:
@@ -253,6 +269,14 @@ filter_set_exclude:
253269
enabled: true
254270
metrics_exclude:
255271
- strict: "vcenter.resource_pool.name-val"
272+
vcenter.virtual_app.inventory_path:
273+
enabled: true
274+
metrics_exclude:
275+
- strict: "vcenter.virtual_app.inventory_path-val"
276+
vcenter.virtual_app.name:
277+
enabled: true
278+
metrics_exclude:
279+
- strict: "vcenter.virtual_app.name-val"
256280
vcenter.vm.id:
257281
enabled: true
258282
metrics_exclude:

receiver/vcenterreceiver/internal/mockserver/client_mock.go

+10
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func routeRetreiveProperties(t *testing.T, body map[string]any) ([]byte, error)
114114

115115
switch {
116116
case content == "group-d1" && contentType == "Folder":
117+
for _, i := range propSetArray {
118+
m, ok := i.(map[string]any)
119+
require.True(t, ok)
120+
if m["pathSet"] == "parentVApp" && m["type"] == "VirtualMachine" {
121+
return loadResponse("datacenter-list.xml")
122+
}
123+
}
117124
return loadResponse("datacenter.xml")
118125

119126
case content == "datacenter-3" && contentType == "Datacenter":
@@ -199,6 +206,9 @@ func routeRetreiveProperties(t *testing.T, body map[string]any) ([]byte, error)
199206
return loadResponse("virtual-app-children.xml")
200207
}
201208
}
209+
if _, ok := propSet["pathSet"].([]any); ok {
210+
return loadResponse("virtual-app-properties.xml")
211+
}
202212
if ps, ok := propSet["pathSet"].(string); ok {
203213
if ps == "owner" {
204214
return loadResponse("virtual-app-owner.xml")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
3+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
<soapenv:Body>
7+
<RetrievePropertiesResponse xmlns="urn:vim25">
8+
<returnval>
9+
<obj type="VirtualApp">resgroup-v10</obj>
10+
<propSet>
11+
<name>name</name>
12+
<val xsi:type="xsd:string">v-app-1</val>
13+
</propSet>
14+
<propSet>
15+
<name>vm</name>
16+
<val xsi:type="ArrayOfManagedObjectReference">
17+
<ManagedObjectReference type="VirtualMachine"
18+
xsi:type="ManagedObjectReference">vm-6004</ManagedObjectReference>
19+
</val>
20+
</propSet>
21+
</returnval>
22+
</RetrievePropertiesResponse>
23+
</soapenv:Body>
24+
</soapenv:Envelope>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<soapenv:Body>
4+
<RetrievePropertiesResponse xmlns="urn:vim25">
5+
<returnval>
6+
<obj type="VirtualApp">resgroup-v10</obj>
7+
<propSet>
8+
<name>name</name>
9+
<val xsi:type="xsd:string">v-app-1</val>
10+
</propSet>
11+
</returnval>
12+
</RetrievePropertiesResponse>
13+
</soapenv:Body>
14+
</soapenv:Envelope>

0 commit comments

Comments
 (0)