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 vCenter VM CPU readiness metric #33608

Merged
Merged
Show file tree
Hide file tree
Changes from 15 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/add_vcenter_vm_cpu_readiness_metric.yaml
BominRahmani marked this conversation as resolved.
Show resolved Hide resolved
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: enhancement

# 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 CPU readiness metric for VMs."

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

# (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]
4 changes: 4 additions & 0 deletions receiver/vcenterreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ The full list of settings exposed for this receiver are documented [here](./conf

Details about the metrics produced by this receiver can be found in [metadata.yaml](./metadata.yaml) with further documentation in [documentation.md](./documentation.md)

Additionally some metrics are only available to certain vSphere API versions.
### 7.0.0+
- [vcenter.vm.cpu.readiness](https://dp-downloads.broadcom.com/api-content/apis/API_VMA_001/8.0U2/html/vim.vm.Summary.QuickStats.html)
BominRahmani marked this conversation as resolved.
Show resolved Hide resolved

### Feature gates
35 changes: 28 additions & 7 deletions receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net/url"

"github.com/hashicorp/go-version"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
Expand All @@ -22,13 +23,14 @@ import (

// vcenterClient is a client that collects data from a vCenter endpoint.
type vcenterClient struct {
moClient *govmomi.Client
vimDriver *vim25.Client
finder *find.Finder
pc *property.Collector
pm *performance.Manager
vm *view.Manager
cfg *Config
moClient *govmomi.Client
vimDriver *vim25.Client
finder *find.Finder
pc *property.Collector
pm *performance.Manager
vm *view.Manager
cfg *Config
apiVersion string
}

var newVcenterClient = defaultNewVcenterClient
Expand Down Expand Up @@ -74,6 +76,7 @@ func (vc *vcenterClient) EnsureConnection(ctx context.Context) error {
vc.finder = find.NewFinder(vc.vimDriver)
vc.pm = performance.NewManager(vc.vimDriver)
vc.vm = view.NewManager(vc.vimDriver)
vc.apiVersion = vc.getVsphereAPIVersion()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we drop support for 6.7 we don't need this check. Perhaps there is a reasonable way to fail gracefully if the server does not support the new metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just drop support for 6.7 in this case. The problem with this metric is it doesn't really fail, rather it returns 0 if the server doesn't support the metric, but 0 in of itself is a valid value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As 6.7 is "End of General Support" since October 15, 2022 (https://core.vmware.com/blog/reminder-vsphere-6567-end-general-support), it would make sense to drop the support here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djaglowski To drop support for a version do we need to make a new pr / add warnings anywhere? or are we allowed to just remove it from the readme.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BominRahmani, a separate PR would be ideal but I think it's ok to do here as long as there's a separate changelog entry for it. You can just add a second changelog yaml file and note it there.

return nil
}

Expand Down Expand Up @@ -103,6 +106,24 @@ func (vc *vcenterClient) Datacenters(ctx context.Context) ([]mo.Datacenter, erro
return datacenters, nil
}

func (vc *vcenterClient) getVsphereAPIVersion() string {
return vc.vimDriver.ServiceContent.About.ApiVersion
}

func (vc *vcenterClient) VsphereAPIVersionMeetsMin(minVsphereAPIVersion string) bool {
apiVersion, err := version.NewVersion(vc.apiVersion)
if err != nil {
return false
}

minAPIVersion, err := version.NewVersion(minVsphereAPIVersion)
if err != nil {
return false
}

return apiVersion.GreaterThanOrEqual(minAPIVersion)
}

// Datastores returns the Datastores of the vSphere SDK
func (vc *vcenterClient) Datastores(ctx context.Context, containerMoRef vt.ManagedObjectReference) ([]mo.Datastore, error) {
v, err := vc.vm.CreateContainerView(ctx, containerMoRef, []string{"Datastore"}, true)
Expand Down
31 changes: 31 additions & 0 deletions receiver/vcenterreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,34 @@ func TestSessionReestablish(t *testing.T) {
require.True(t, connected)
})
}

func TestVsphereAPIVersionMeetsMin(t *testing.T) {
simulator.Test(func(_ context.Context, c *vim25.Client) {
finder := find.NewFinder(c)
vm := view.NewManager(c)
client := vcenterClient{
vimDriver: c,
finder: finder,
vm: vm,
apiVersion: c.ServiceContent.About.ApiVersion,
}
testCases := []struct {
name string
minVersion string
expectMeet bool
}{
{"Lower Version", "6.0.0", true},
{"Equal Version", client.apiVersion, true},
{"Higher Version", "7.0.8", false},
{"Empty Version", "", false},
{"Invalid Version", "invalid", false},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := client.VsphereAPIVersionMeetsMin(tc.minVersion)
require.Equal(t, tc.expectMeet, result, "Unexpected result for min version: %s", tc.minVersion)
})
}
})
}
18 changes: 18 additions & 0 deletions receiver/vcenterreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,24 @@ As measured over the most recent 20s interval.
| ---- | ----------- | ------ |
| object | The object on the virtual machine or host that is being reported on. | Any Str |

## Optional Metrics

The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration:

```yaml
metrics:
<metric_name>:
enabled: true
```

### vcenter.vm.cpu.readiness

Percentage of time that the virtual machine was ready, but could not get scheduled to run on the physical CPU.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| % | Gauge | Int |

## Resource Attributes

| Name | Description | Values | Enabled |
Expand Down
2 changes: 1 addition & 1 deletion receiver/vcenterreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21.0
require (
github.com/basgys/goxml2json v1.1.0
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-version v1.7.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.103.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.103.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.103.0
Expand Down Expand Up @@ -50,7 +51,6 @@ require (
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
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.

60 changes: 60 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.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ all_set:
enabled: true
vcenter.resource_pool.memory.usage:
enabled: true
vcenter.vm.cpu.readiness:
enabled: true
vcenter.vm.cpu.usage:
enabled: true
vcenter.vm.cpu.utilization:
Expand Down Expand Up @@ -156,6 +158,8 @@ none_set:
enabled: false
vcenter.resource_pool.memory.usage:
enabled: false
vcenter.vm.cpu.readiness:
enabled: false
vcenter.vm.cpu.usage:
enabled: false
vcenter.vm.cpu.utilization:
Expand Down
9 changes: 9 additions & 0 deletions receiver/vcenterreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ metrics:
value_type: int
aggregation_temporality: cumulative
attributes: []
vcenter.vm.cpu.readiness:
enabled: false
description: Percentage of time that the virtual machine was ready, but could not get scheduled to run on the physical CPU.
unit: "%"
gauge:
value_type: int
attributes: []
warnings:
if_enabled_not_set: "this metric will be enabled by default starting in release v0.105.0"
vcenter.vm.memory.utilization:
enabled: true
description: The memory utilization of the VM.
Expand Down
7 changes: 7 additions & 0 deletions receiver/vcenterreceiver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ func (v *vcenterMetricScraper) recordVMStats(
return
}
v.mb.RecordVcenterVMCPUUtilizationDataPoint(ts, 100*float64(cpuUsage)/float64(cpuLimit))

// OverallCpuReadiness is only available in vSphere API 7.0
// https://dp-downloads.broadcom.com/api-content/apis/API_VMA_001/8.0U2/html/vim.vm.Summary.QuickStats.html
if v.client.VsphereAPIVersionMeetsMin("7.0.0") {
cpuReadiness := vm.Summary.QuickStats.OverallCpuReadiness
v.mb.RecordVcenterVMCPUReadinessDataPoint(ts, int64(cpuReadiness))
}
}

var hostPerfMetricList = []string{
Expand Down
Loading