Skip to content

Commit

Permalink
vcenterreceiver: Adds vcenter.datacenter.name attributes to all resou…
Browse files Browse the repository at this point in the history
…rce types (#32528)

**Description:** <Describe what has changed.>
Adds `vcenter.datacenter.name` attribute for every resource type. This
ensures uniqueness in cases where more than one datacenter exists.

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

**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.>
Documentation regenerated.

---------

Co-authored-by: Daniel Jaglowski <[email protected]>
  • Loading branch information
StefanKurek and djaglowski authored Apr 24, 2024
1 parent 6cefabc commit 3c64cea
Show file tree
Hide file tree
Showing 15 changed files with 6,683 additions and 16 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix_vcenter-datacenter-attributes.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 `vcenter.datacenter.name` attributes to all resource types to help with resource identification"

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

# (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]
2 changes: 1 addition & 1 deletion receiver/vcenterreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| Stability | [alpha]: metrics |
| Distributions | [contrib] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fvcenter%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fvcenter) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fvcenter%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fvcenter) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@djaglowski](https://www.github.com/djaglowski), [@schmikei](https://www.github.com/schmikei) \| Seeking more code owners! |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@djaglowski](https://www.github.com/djaglowski), [@schmikei](https://www.github.com/schmikei), [@StefanKurek](https://www.github.com/StefanKurek) \| Seeking more code owners! |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
1 change: 1 addition & 0 deletions receiver/vcenterreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ The memory utilization of the VM.
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| vcenter.cluster.name | The name of the vCenter Cluster. | Any Str | true |
| vcenter.datacenter.name | The name of the vCenter datacenter. | Any Str | false |
| vcenter.datastore.name | The name of the vCenter datastore. | Any Str | true |
| 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 |
Expand Down

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.

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.

12 changes: 12 additions & 0 deletions receiver/vcenterreceiver/internal/metadata/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ all_set:
resource_attributes:
vcenter.cluster.name:
enabled: true
vcenter.datacenter.name:
enabled: true
vcenter.datastore.name:
enabled: true
vcenter.host.name:
Expand Down Expand Up @@ -177,6 +179,8 @@ none_set:
resource_attributes:
vcenter.cluster.name:
enabled: false
vcenter.datacenter.name:
enabled: false
vcenter.datastore.name:
enabled: false
vcenter.host.name:
Expand All @@ -195,6 +199,10 @@ filter_set_include:
enabled: true
metrics_include:
- regexp: ".*"
vcenter.datacenter.name:
enabled: true
metrics_include:
- regexp: ".*"
vcenter.datastore.name:
enabled: true
metrics_include:
Expand Down Expand Up @@ -225,6 +233,10 @@ filter_set_exclude:
enabled: true
metrics_exclude:
- strict: "vcenter.cluster.name-val"
vcenter.datacenter.name:
enabled: true
metrics_exclude:
- strict: "vcenter.datacenter.name-val"
vcenter.datastore.name:
enabled: true
metrics_exclude:
Expand Down
10 changes: 8 additions & 2 deletions receiver/vcenterreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ status:
alpha: [metrics]
distributions: [contrib]
codeowners:
active: [djaglowski, schmikei]
active: [djaglowski, schmikei, StefanKurek]
seeking_new: true

resource_attributes:
resource_attributes:
vcenter.datacenter.name:
description: The name of the vCenter datacenter.
enabled: false
type: string
warnings:
if_enabled_not_set: "this attribute will be enabled by default starting in release v0.101.0"
vcenter.cluster.name:
description: The name of the vCenter Cluster.
enabled: true
Expand Down
2 changes: 2 additions & 0 deletions receiver/vcenterreceiver/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
)

func (v *vcenterMetricScraper) createVMResourceBuilder(
dcName string,
vm mo.VirtualMachine,
hs mo.HostSystem,
compute *object.ComputeResource,
rp *object.ResourcePool,
) *metadata.ResourceBuilder {
rb := v.mb.NewResourceBuilder()
rb.SetVcenterDatacenterName(dcName)
rb.SetVcenterVMName(vm.Summary.Config.Name)
rb.SetVcenterVMID(vm.Config.InstanceUuid)
if compute.Reference().Type == "ClusterComputeResource" {
Expand Down
28 changes: 20 additions & 8 deletions receiver/vcenterreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,22 @@ func (v *vcenterMetricScraper) collectClusters(ctx context.Context, datacenter *

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

v.collectResourcePools(ctx, now, computes, errs)
dcName := datacenter.Name()
v.collectResourcePools(ctx, now, dcName, computes, errs)
for _, c := range computes {
v.collectHosts(ctx, now, c, errs)
v.collectDatastores(ctx, now, c, errs)
poweredOnVMs, poweredOffVMs := v.collectVMs(ctx, now, c, errs)
v.collectHosts(ctx, now, dcName, c, errs)
v.collectDatastores(ctx, now, dcName, c, errs)
poweredOnVMs, poweredOffVMs := v.collectVMs(ctx, now, dcName, c, errs)
if c.Reference().Type == "ClusterComputeResource" {
v.collectCluster(ctx, now, c, poweredOnVMs, poweredOffVMs, errs)
v.collectCluster(ctx, now, dcName, c, poweredOnVMs, poweredOffVMs, errs)
}
}
}

func (v *vcenterMetricScraper) collectCluster(
ctx context.Context,
now pcommon.Timestamp,
dcName string,
c *object.ComputeResource,
poweredOnVMs, poweredOffVMs int64,
errs *scrapererror.ScrapeErrors,
Expand All @@ -149,13 +151,15 @@ func (v *vcenterMetricScraper) collectCluster(
v.mb.RecordVcenterClusterHostCountDataPoint(now, int64(s.NumHosts-s.NumEffectiveHosts), false)
v.mb.RecordVcenterClusterHostCountDataPoint(now, int64(s.NumEffectiveHosts), true)
rb := v.mb.NewResourceBuilder()
rb.SetVcenterDatacenterName(dcName)
rb.SetVcenterClusterName(c.Name())
v.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}

func (v *vcenterMetricScraper) collectDatastores(
ctx context.Context,
colTime pcommon.Timestamp,
dcName string,
compute *object.ComputeResource,
errs *scrapererror.ScrapeErrors,
) {
Expand All @@ -166,13 +170,14 @@ func (v *vcenterMetricScraper) collectDatastores(
}

for _, ds := range datastores {
v.collectDatastore(ctx, colTime, ds, compute, errs)
v.collectDatastore(ctx, colTime, dcName, ds, compute, errs)
}
}

func (v *vcenterMetricScraper) collectDatastore(
ctx context.Context,
now pcommon.Timestamp,
dcName string,
ds *object.Datastore,
compute *object.ComputeResource,
errs *scrapererror.ScrapeErrors,
Expand All @@ -186,6 +191,7 @@ func (v *vcenterMetricScraper) collectDatastore(

v.recordDatastoreProperties(now, moDS)
rb := v.mb.NewResourceBuilder()
rb.SetVcenterDatacenterName(dcName)
if compute.Reference().Type == "ClusterComputeResource" {
rb.SetVcenterClusterName(compute.Name())
}
Expand All @@ -196,6 +202,7 @@ func (v *vcenterMetricScraper) collectDatastore(
func (v *vcenterMetricScraper) collectHosts(
ctx context.Context,
colTime pcommon.Timestamp,
dcName string,
compute *object.ComputeResource,
errs *scrapererror.ScrapeErrors,
) {
Expand All @@ -206,13 +213,14 @@ func (v *vcenterMetricScraper) collectHosts(
}

for _, h := range hosts {
v.collectHost(ctx, colTime, h, compute, errs)
v.collectHost(ctx, colTime, dcName, h, compute, errs)
}
}

func (v *vcenterMetricScraper) collectHost(
ctx context.Context,
now pcommon.Timestamp,
dcName string,
host *object.HostSystem,
compute *object.ComputeResource,
errs *scrapererror.ScrapeErrors,
Expand Down Expand Up @@ -240,6 +248,7 @@ func (v *vcenterMetricScraper) collectHost(
v.recordHostSystemMemoryUsage(now, hwSum)
v.recordHostPerformanceMetrics(ctx, hwSum, errs)
rb := v.mb.NewResourceBuilder()
rb.SetVcenterDatacenterName(dcName)
rb.SetVcenterHostName(host.Name())
if compute.Reference().Type == "ClusterComputeResource" {
rb.SetVcenterClusterName(compute.Name())
Expand All @@ -250,6 +259,7 @@ func (v *vcenterMetricScraper) collectHost(
func (v *vcenterMetricScraper) collectResourcePools(
ctx context.Context,
ts pcommon.Timestamp,
dcName string,
computes []*object.ComputeResource,
errs *scrapererror.ScrapeErrors,
) {
Expand Down Expand Up @@ -292,6 +302,7 @@ func (v *vcenterMetricScraper) collectResourcePools(
rpName := rp.Name()
rb.SetVcenterResourcePoolName(rpName)
rb.SetVcenterResourcePoolInventoryPath(rp.InventoryPath)
rb.SetVcenterDatacenterName(dcName)

compute := computesByRef[computeRef.Reference().Value]
if compute == nil {
Expand Down Expand Up @@ -321,6 +332,7 @@ func (v *vcenterMetricScraper) collectResourcePools(
func (v *vcenterMetricScraper) collectVMs(
ctx context.Context,
colTime pcommon.Timestamp,
dcName string,
compute *object.ComputeResource,
errs *scrapererror.ScrapeErrors,
) (poweredOnVMs int64, poweredOffVMs int64) {
Expand Down Expand Up @@ -410,7 +422,7 @@ func (v *vcenterMetricScraper) collectVMs(

perfMetrics := vmPerfMetrics.resultsByMoRef[vm.Reference().Value]
v.buildVMMetrics(colTime, vm, hwSum, perfMetrics)
rb := v.createVMResourceBuilder(vm, hwSum, compute, rp)
rb := v.createVMResourceBuilder(dcName, vm, hwSum, compute, rp)
v.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}

Expand Down
Loading

0 comments on commit 3c64cea

Please sign in to comment.