Skip to content
27 changes: 27 additions & 0 deletions .chloggen/fix_PerfMetricsQueryFollowUp.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. receiver/filelog)
component: receiver/vcenter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: added logic so that if a query fails due to a bad object it does not fail the entire scrape

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

# (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: []
19 changes: 17 additions & 2 deletions receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ func (vc *vcenterClient) PerfMetricsQuery(
return &perfMetricsQueryResult{}, nil
}
vc.pm.Sort = true

batchSize := vc.batchSizeForMetrics(len(names))
if batchSize <= 0 || batchSize >= len(objs) {
batchSize = max(len(objs), 1)
Expand All @@ -337,7 +336,22 @@ func (vc *vcenterClient) PerfMetricsQuery(
for batch := range slices.Chunk(objs, batchSize) {
sample, err := vc.pm.SampleByName(ctx, spec, names, batch)
if err != nil {
return nil, err
for _, obj := range batch {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than exploding the number of queries can we read the error, remove the failing metric(s), and try again as a batch?

singleSample, singleErr := vc.pm.SampleByName(ctx, spec, names, []vt.ManagedObjectReference{obj})
if singleErr != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than discarding these errors, we should aggregate and log them (at a debug level?) to support fixing issues with the receiver moving forward.

continue
}

singleResult, singleErr := vc.pm.ToMetricSeries(ctx, singleSample)
if singleErr != nil {
continue
}

for i := range singleResult {
resultsByRef[singleResult[i].Entity.Value] = &singleResult[i]
}
}
continue
}
result, err := vc.pm.ToMetricSeries(ctx, sample)
if err != nil {
Expand All @@ -348,6 +362,7 @@ func (vc *vcenterClient) PerfMetricsQuery(
resultsByRef[result[i].Entity.Value] = &result[i]
}
}

return &perfMetricsQueryResult{
resultsByRef: resultsByRef,
}, nil
Expand Down
24 changes: 24 additions & 0 deletions receiver/vcenterreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,30 @@ func TestPerfMetricsQuery(t *testing.T) {
}, esx)
}

func TestPerfMetricsQuery_FallbackOnBatchError(t *testing.T) {
esx := simulator.ESX()
simulator.Test(func(ctx context.Context, c *vim25.Client) {
pm := performance.NewManager(c)
m := view.NewManager(c)
finder := find.NewFinder(c)
client := vcenterClient{
vimDriver: c,
vm: m,
pm: pm,
finder: finder,
}
hs, err := finder.DefaultHostSystem(ctx)
require.NoError(t, err)

spec := types.PerfQuerySpec{Format: string(types.PerfFormatNormal), IntervalId: int32(20)}

metrics, err := client.PerfMetricsQuery(ctx, spec, []string{"invalid.metric.name"}, []types.ManagedObjectReference{hs.Reference()})
require.NoError(t, err)
require.NotNil(t, metrics)
require.Empty(t, metrics.resultsByRef)
}, esx)
}

func TestPerfMetricsQueryBatching(t *testing.T) {
vpx := simulator.VPX()
vpx.Host = 10
Expand Down
Loading