Skip to content

Commit

Permalink
[receiver/vcenter] Fix multi cluster deployment resource attributes (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#31113)

**Description:** First pass at better contextualizing VMs in a
multicluster deployment.

## The Problem

For multicluster deployments the original scraper code incorrectly
interpreted assumptions on VM ownership belonging to multiple clusters.

## The Solution

The VM folder in a datacenter is completely separated from a cluster.
Because of this we have to determine the VM's host system or resource
polo in order to appropriate set the `vcenter.cluster.name`
appropriately.

## Things that have changed 
- ClusterComputes are now retrieved as a superset Computes
- For the resource attribute `vcenter.cluster.name` to show up, the
inventory type must match the string "ClusterComputeResource"
- The receiver now maintains a dynamic map of vm Managed Object
Reference Value to compute name

## Customer impacts
- VM metrics will more appropriately set the `vcenter.cluster.name`
resource attribute in multi-cluster environments. This resource
attribute will not be emitted for VMs on a runtime hosts outside of a
cluster.
- VM metrics will now emit with `vcenter.resource_pool.name` and
`vcenter.resource_pool.inventory_path` when the VM is a member of one.


**Link to tracking Issue:** Resolves open-telemetry#30879

**Testing:**

**Documentation:** <Describe the documentation added.>
  • Loading branch information
schmikei authored and DougManton committed Mar 13, 2024
1 parent 5678708 commit 3692c24
Show file tree
Hide file tree
Showing 9 changed files with 508 additions and 270 deletions.
29 changes: 29 additions & 0 deletions .chloggen/vcenter-cluster-duplication.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

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

# 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: Fixed the resource attribute model to more accurately support multi-cluster deployments

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

# (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: |
For more information on impacts please refer https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/31113. The main impacts are that
the `vcenter.resource_pool.name`, `vcenter.resource_pool.inventory_path`, and `vcenter.cluster.name` are reported with more accuracy on VM metrics.
# 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: []
9 changes: 4 additions & 5 deletions receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ func (vc *vcenterClient) Datacenters(ctx context.Context) ([]*object.Datacenter,
return datacenters, nil
}

// Clusters returns the clusterComputeResources of the vSphere SDK
func (vc *vcenterClient) Clusters(ctx context.Context, datacenter *object.Datacenter) ([]*object.ClusterComputeResource, error) {
func (vc *vcenterClient) Computes(ctx context.Context, datacenter *object.Datacenter) ([]*object.ComputeResource, error) {
vc.finder = vc.finder.SetDatacenter(datacenter)
clusters, err := vc.finder.ClusterComputeResourceList(ctx, "*")
computes, err := vc.finder.ComputeResourceList(ctx, "*")
if err != nil {
return []*object.ClusterComputeResource{}, fmt.Errorf("unable to get cluster lists: %w", err)
return []*object.ComputeResource{}, fmt.Errorf("unable to get compute lists: %w", err)
}
return clusters, nil
return computes, nil
}

// ResourcePools returns the resourcePools in the vSphere SDK
Expand Down
6 changes: 3 additions & 3 deletions receiver/vcenterreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
)

func TestGetClusters(t *testing.T) {
func TestGetComputes(t *testing.T) {
simulator.Test(func(ctx context.Context, c *vim25.Client) {
finder := find.NewFinder(c)
client := vcenterClient{
Expand All @@ -27,9 +27,9 @@ func TestGetClusters(t *testing.T) {
}
dc, err := finder.DefaultDatacenter(ctx)
require.NoError(t, err)
clusters, err := client.Clusters(ctx, dc)
computes, err := client.Computes(ctx, dc)
require.NoError(t, err)
require.NotEmpty(t, clusters, 0)
require.NotEmpty(t, computes, 0)
})
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/vcenterreceiver/internal/mockserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ And then running the receiver against the proxy.
```yaml
receivers:
vcenter:
endpoint: https://localhost:56626
endpoint: http://localhost:55626
username: "otelu"
password: "otelp"
tls:
Expand Down
6 changes: 6 additions & 0 deletions receiver/vcenterreceiver/internal/mockserver/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ func routeRetreiveProperties(t *testing.T, body map[string]any) ([]byte, error)
}
}

if ps, ok := propSet["pathSet"].(string); ok {
if ps == "owner" {
return loadResponse("resource-pool-single.xml")
}
}

if ss, ok := objectSet["selectSet"].(map[string]any); ok && ss["path"] == "resourcePool" {
return loadResponse("resource-pool-group.xml")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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="ResourcePool">resgroup-9</obj>
<propSet>
<name>owner</name>
<val type="ClusterComputeResource" xsi:type="ManagedObjectReference">domain-c8</val>
</propSet>
</returnval>
</RetrievePropertiesResponse>
</soapenv:Body>
</soapenv:Envelope>
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?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: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>
Expand Down Expand Up @@ -93,6 +96,15 @@
<compressedMemory>0</compressedMemory>
</val>
</propSet>
<propSet>
<name>vm</name>
<val xsi:type="ArrayOfManagedObjectReference">
<ManagedObjectReference type="VirtualMachine"
xsi:type="ManagedObjectReference">vm-1040</ManagedObjectReference>
<ManagedObjectReference type="VirtualMachine"
xsi:type="ManagedObjectReference">vm-6005</ManagedObjectReference>
</val>
</propSet>
</returnval>
</RetrievePropertiesResponse>
</soapenv:Body>
Expand Down

0 comments on commit 3692c24

Please sign in to comment.