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

[receiver/vcenter] Adds vApp Resource Attributes to Relevant VM Resources #32673

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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