Skip to content

Commit c71919f

Browse files
authored
[chore][receiver/vcenter] Reworked Integration test for vCenter (#34201)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> The following PR works to make the integration tests a bit more deterministic by taking advantage of the govmomi simulator. Previously the integration test had the following line when comparing ``` pmetrictest.IgnoreResourceAttributeValue("vcenter.host.name") ``` Which is a bit of a hacky fix that addressed an issue where the simulator had inconsistent VM to Host assignments between test runs. Although ignoring the resource attribute value currently works, it breaks once datacenter metrics are enabled by default This PR hopes to make the integration tests more consistent and accurate going forward. **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> - Regenerated the expected.yaml using `scraperinttest.WriteExpected()` - Passes Integration test **Documentation:** <Describe the documentation added.>
1 parent e32faef commit c71919f

File tree

2 files changed

+486
-440
lines changed

2 files changed

+486
-440
lines changed

receiver/vcenterreceiver/integration_test.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/vmware/govmomi/session"
1818
"github.com/vmware/govmomi/simulator"
1919
"github.com/vmware/govmomi/vim25"
20+
"github.com/vmware/govmomi/vim25/types"
2021
"go.opentelemetry.io/collector/component"
2122
"go.opentelemetry.io/collector/config/configopaque"
2223
"go.opentelemetry.io/collector/config/configtls"
@@ -26,7 +27,52 @@ import (
2627
)
2728

2829
func TestIntegration(t *testing.T) {
29-
simulator.Test(func(_ context.Context, c *vim25.Client) {
30+
model := simulator.VPX()
31+
32+
model.Host = 2
33+
model.Machine = 2
34+
35+
err := model.Create()
36+
require.NoError(t, err)
37+
38+
simulator.Test(func(ctx context.Context, c *vim25.Client) {
39+
finder := find.NewFinder(c)
40+
41+
hosts, err := finder.HostSystemList(ctx, "/DC0/host/*")
42+
require.NoError(t, err)
43+
for i, host := range hosts {
44+
newName := fmt.Sprintf("H%d", i)
45+
simulator.Map.Get(host.Reference()).(*simulator.HostSystem).Name = newName
46+
}
47+
48+
vms, err := finder.VirtualMachineList(ctx, "/DC0/vm/*")
49+
require.NoError(t, err)
50+
for i, vm := range vms {
51+
newName := fmt.Sprintf("VM%d", i)
52+
newUUID := fmt.Sprintf("vm-uuid-%d", i)
53+
simVM := simulator.Map.Get(vm.Reference()).(*simulator.VirtualMachine)
54+
simVM.Name = newName
55+
simVM.Config.Uuid = newUUID
56+
57+
// Explicitly assign VM to a specific host
58+
hostIndex := i % len(hosts) // This will alternate VMs between hosts
59+
host := hosts[hostIndex]
60+
hostRef := host.Reference()
61+
relocateSpec := types.VirtualMachineRelocateSpec{
62+
Host: &hostRef,
63+
}
64+
task, err := vm.Relocate(ctx, relocateSpec, types.VirtualMachineMovePriorityDefaultPriority)
65+
require.NoError(t, err)
66+
require.NoError(t, task.Wait(ctx))
67+
68+
// Reconfigure the VM to apply name and UUID changes
69+
task, err = vm.Reconfigure(ctx, types.VirtualMachineConfigSpec{
70+
Name: newName,
71+
Uuid: newUUID,
72+
})
73+
require.NoError(t, err)
74+
require.NoError(t, task.Wait(ctx))
75+
}
3076
pw, set := simulator.DefaultLogin.Password()
3177
require.True(t, set)
3278

@@ -51,7 +97,6 @@ func TestIntegration(t *testing.T) {
5197
defer func() {
5298
newVcenterClient = defaultNewVcenterClient
5399
}()
54-
55100
scraperinttest.NewIntegrationTest(
56101
NewFactory(),
57102
scraperinttest.WithCustomConfig(
@@ -66,9 +111,10 @@ func TestIntegration(t *testing.T) {
66111
}
67112
}),
68113
scraperinttest.WithCompareOptions(
69-
pmetrictest.IgnoreResourceAttributeValue("vcenter.host.name"),
70114
pmetrictest.IgnoreTimestamp(),
71115
pmetrictest.IgnoreResourceMetricsOrder(),
116+
pmetrictest.IgnoreDatapointAttributesOrder(),
117+
pmetrictest.IgnoreMetricDataPointsOrder(),
72118
pmetrictest.IgnoreMetricsOrder(),
73119
pmetrictest.IgnoreStartTimestamp(),
74120
pmetrictest.IgnoreMetricValues(),

0 commit comments

Comments
 (0)