Skip to content

Commit

Permalink
[receiver/vcenter] Adds extra resource attributes to relevant Resourc…
Browse files Browse the repository at this point in the history
…e Pools (open-telemetry#32538)

**Description:** <Describe what has changed.>
`vcenter.cluster.name` attribute is added to all Resource Pool resources
that belong to a Cluster. In addition, `vcenter.host.name` attribute is
added to all Resource Pool resources that belong to a standalone Host.

This helps to keep attributes consistent between all resource types.
Also, Cluster information can’t automatically be parsed from the
inventory path attribute, as we don’t have the context of nested
folders. So this allows for the ability to tell what Cluster a Resource
Pool belongs to (if any).

**Link to tracking Issue:** <Issue number if applicable>
open-telemetry#32535 

**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.>
N/A
  • Loading branch information
StefanKurek authored Apr 24, 2024
1 parent b76102f commit 9a5240e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix_vcenter-cluster-attr-on-rpools.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 the `vcenter.cluster.name` resource attribute to resource pool with a ClusterComputeResource parent"

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

# (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]
36 changes: 33 additions & 3 deletions receiver/vcenterreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (v *vcenterMetricScraper) collectClusters(ctx context.Context, datacenter *

now := pcommon.NewTimestampFromTime(time.Now())

v.collectResourcePools(ctx, now, errs)
v.collectResourcePools(ctx, now, computes, errs)
for _, c := range computes {
v.collectHosts(ctx, now, c, errs)
v.collectDatastores(ctx, now, c, errs)
Expand Down Expand Up @@ -250,13 +250,21 @@ func (v *vcenterMetricScraper) collectHost(
func (v *vcenterMetricScraper) collectResourcePools(
ctx context.Context,
ts pcommon.Timestamp,
computes []*object.ComputeResource,
errs *scrapererror.ScrapeErrors,
) {
rps, err := v.client.ResourcePools(ctx)
if err != nil {
errs.AddPartial(1, err)
return
}

// Make it easier to find matching Clusters
computesByRef := map[string]*object.ComputeResource{}
for _, cr := range computes {
computesByRef[cr.Reference().Value] = cr
}

for _, rp := range rps {
var moRP mo.ResourcePool
err = rp.Properties(ctx, rp.Reference(), []string{
Expand All @@ -280,10 +288,32 @@ func (v *vcenterMetricScraper) collectResourcePools(
v.vmToResourcePool[vmRef.Value] = rp
}

v.recordResourcePool(ts, moRP)
rb := v.mb.NewResourceBuilder()
rb.SetVcenterResourcePoolName(rp.Name())
rpName := rp.Name()
rb.SetVcenterResourcePoolName(rpName)
rb.SetVcenterResourcePoolInventoryPath(rp.InventoryPath)

compute := computesByRef[computeRef.Reference().Value]
if compute == nil {
errs.AddPartial(1, fmt.Errorf("no collected %s for Resource Pool [%s]'s owner ref: %s", computeRef.Reference().Type, rpName, computeRef.Reference().Value))
continue
}

if computeRef.Reference().Type == "ClusterComputeResource" {
rb.SetVcenterClusterName(compute.Name())
}
if computeRef.Reference().Type == "ComputeResource" {
hosts, err := compute.Hosts(ctx)
if err != nil || len(hosts) == 0 || hosts[0] == nil {
errs.AddPartial(1, fmt.Errorf("no hosts found for Resource Pool [%s]'s owner ref: %s", rpName, computeRef.Reference().Value))
continue
}

host := hosts[0]
rb.SetVcenterHostName(host.Name())
}

v.recordResourcePool(ts, moRP)
v.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}
}
Expand Down
6 changes: 6 additions & 0 deletions receiver/vcenterreceiver/testdata/integration/expected.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
resourceMetrics:
- resource:
attributes:
- key: vcenter.host.name
value:
stringValue: DC0_H0
- key: vcenter.resource_pool.name
value:
stringValue: Resources
Expand Down Expand Up @@ -32,6 +35,9 @@ resourceMetrics:
version: latest
- resource:
attributes:
- key: vcenter.cluster.name
value:
stringValue: DC0_C0
- key: vcenter.resource_pool.name
value:
stringValue: Resources
Expand Down
6 changes: 6 additions & 0 deletions receiver/vcenterreceiver/testdata/metrics/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5057,6 +5057,9 @@ resourceMetrics:
version: latest
- resource:
attributes:
- key: vcenter.cluster.name
value:
stringValue: Cluster
- key: vcenter.resource_pool.inventory_path
value:
stringValue: /Datacenter/host/Cluster/Resources
Expand Down Expand Up @@ -5106,6 +5109,9 @@ resourceMetrics:
version: latest
- resource:
attributes:
- key: vcenter.host.name
value:
stringValue: esxi-111.europe-southeast1.gve.goog
- key: vcenter.resource_pool.inventory_path
value:
stringValue: /Datacenter/host/StandaloneHost/Resources
Expand Down

0 comments on commit 9a5240e

Please sign in to comment.