diff --git a/.chloggen/fix_vcenter-client-errors-on-empty-vapps.yaml b/.chloggen/fix_vcenter-client-errors-on-empty-vapps.yaml new file mode 100644 index 000000000000..3d71d2fcbc7f --- /dev/null +++ b/.chloggen/fix_vcenter-client-errors-on-empty-vapps.yaml @@ -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: "vcenterreceiver client no longer returns error if no Virtual Apps are found." + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [33073] + +# (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] diff --git a/.chloggen/fix_vcenter-datastore-attributes.yaml b/.chloggen/fix_vcenter-datastore-attributes.yaml index d6d3dcfc4a34..78d289a463fa 100644 --- a/.chloggen/fix_vcenter-datastore-attributes.yaml +++ b/.chloggen/fix_vcenter-datastore-attributes.yaml @@ -19,7 +19,7 @@ subtext: | If there were multiple Clusters, Datastore metrics were being repeated under Resources differentiated with a `vcenter.cluster.name` resource attribute. In the same vein, if there were standalone Hosts, in addition to clusters the metrics would be repeated under a Resource without the `vcenter.cluster.name` attribute. Now there - will only be a single set of metrics for one Datastore (as there should be, as Datastores don't be long to + will only be a single set of metrics for one Datastore (as there should be, as Datastores don't belong to Clusters). # If your change doesn't affect end users or the exported elements of any package, diff --git a/receiver/vcenterreceiver/client.go b/receiver/vcenterreceiver/client.go index a68156d7ea86..6bf61883dd9b 100644 --- a/receiver/vcenterreceiver/client.go +++ b/receiver/vcenterreceiver/client.go @@ -5,6 +5,7 @@ package vcenterreceiver // import "github.com/open-telemetry/opentelemetry-colle import ( "context" + "errors" "fmt" "net/url" @@ -236,11 +237,16 @@ func (vc *vcenterClient) ResourcePoolInventoryListObjects(ctx context.Context) ( // VAppInventoryListObjects returns the vApps (with populated InventoryLists) of the vSphere SDK func (vc *vcenterClient) VAppInventoryListObjects(ctx context.Context) ([]*object.VirtualApp, error) { vApps, err := vc.finder.VirtualAppList(ctx, "*") - if err != nil { - return nil, fmt.Errorf("unable to retrieve vApps with InventoryLists: %w", err) + if err == nil { + return vApps, nil + } + + var notFoundErr *find.NotFoundError + if errors.As(err, ¬FoundErr) { + return []*object.VirtualApp{}, nil } - return vApps, nil + return nil, fmt.Errorf("unable to retrieve vApps with InventoryLists: %w", err) } // PerfMetricsQueryResult contains performance metric related data diff --git a/receiver/vcenterreceiver/client_test.go b/receiver/vcenterreceiver/client_test.go index 4048cd780ba3..1576b4f2da3a 100644 --- a/receiver/vcenterreceiver/client_test.go +++ b/receiver/vcenterreceiver/client_test.go @@ -51,6 +51,26 @@ func TestDatastores(t *testing.T) { }) } +func TestEmptyDatastores(t *testing.T) { + vpx := simulator.VPX() + vpx.Datastore = 0 + vpx.Machine = 0 + simulator.Test(func(ctx context.Context, c *vim25.Client) { + finder := find.NewFinder(c) + vm := view.NewManager(c) + client := vcenterClient{ + vimDriver: c, + finder: finder, + vm: vm, + } + dc, err := finder.DefaultDatacenter(ctx) + require.NoError(t, err) + dss, err := client.Datastores(ctx, dc.Reference()) + require.NoError(t, err) + require.Empty(t, dss, 0) + }, vpx) +} + func TestComputeResources(t *testing.T) { simulator.Test(func(ctx context.Context, c *vim25.Client) { finder := find.NewFinder(c) @@ -68,6 +88,24 @@ func TestComputeResources(t *testing.T) { }) } +func TestComputeResourcesWithStandalone(t *testing.T) { + esx := simulator.ESX() + simulator.Test(func(ctx context.Context, c *vim25.Client) { + finder := find.NewFinder(c) + vm := view.NewManager(c) + client := vcenterClient{ + vimDriver: c, + finder: finder, + vm: vm, + } + dc, err := finder.DefaultDatacenter(ctx) + require.NoError(t, err) + crs, err := client.ComputeResources(ctx, dc.Reference()) + require.NoError(t, err) + require.NotEmpty(t, crs, 0) + }, esx) +} + func TestHostSystems(t *testing.T) { simulator.Test(func(ctx context.Context, c *vim25.Client) { finder := find.NewFinder(c) @@ -85,6 +123,27 @@ func TestHostSystems(t *testing.T) { }) } +func TestEmptyHostSystems(t *testing.T) { + vpx := simulator.VPX() + vpx.Host = 0 + vpx.ClusterHost = 0 + vpx.Machine = 0 + simulator.Test(func(ctx context.Context, c *vim25.Client) { + finder := find.NewFinder(c) + vm := view.NewManager(c) + client := vcenterClient{ + vimDriver: c, + finder: finder, + vm: vm, + } + dc, err := finder.DefaultDatacenter(ctx) + require.NoError(t, err) + hss, err := client.HostSystems(ctx, dc.Reference()) + require.NoError(t, err) + require.Empty(t, hss, 0) + }, vpx) +} + func TestResourcePools(t *testing.T) { simulator.Test(func(ctx context.Context, c *vim25.Client) { finder := find.NewFinder(c) @@ -119,6 +178,25 @@ func TestVMs(t *testing.T) { }) } +func TestEmptyVMs(t *testing.T) { + vpx := simulator.VPX() + vpx.Machine = 0 + simulator.Test(func(ctx context.Context, c *vim25.Client) { + finder := find.NewFinder(c) + vm := view.NewManager(c) + client := vcenterClient{ + vimDriver: c, + finder: finder, + vm: vm, + } + dc, err := finder.DefaultDatacenter(ctx) + require.NoError(t, err) + vms, err := client.VMs(ctx, dc.Reference()) + require.NoError(t, err) + require.Empty(t, vms, 0) + }, vpx) +} + func TestPerfMetricsQuery(t *testing.T) { esx := simulator.ESX() simulator.Test(func(ctx context.Context, c *vim25.Client) { @@ -172,6 +250,19 @@ func TestVAppInventoryListObjects(t *testing.T) { }, vpx) } +func TestEmptyVAppInventoryListObjects(t *testing.T) { + simulator.Test(func(ctx context.Context, c *vim25.Client) { + finder := find.NewFinder(c) + client := vcenterClient{ + vimDriver: c, + finder: finder, + } + vApps, err := client.VAppInventoryListObjects(ctx) + require.NoError(t, err) + require.Empty(t, vApps, 0) + }) +} + func TestSessionReestablish(t *testing.T) { simulator.Test(func(ctx context.Context, c *vim25.Client) { sm := session.NewManager(c)