Skip to content

Commit

Permalink
[receiver/vcenter]Fix nil pointer exception when vcenter receiver col…
Browse files Browse the repository at this point in the history
…lectVMs. (#16278)

Fix nil pointer exception when vcenter receiver collectVMs.
  • Loading branch information
wzy531a authored Nov 17, 2022
1 parent f36fd9d commit 47afa8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .chloggen/vcenter-nil-pointer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: collect VM may be panic nil pointer.

# One or more tracking issues related to the change
issues: [16277]

# (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:
8 changes: 6 additions & 2 deletions receiver/vcenterreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ func (v *vcenterMetricScraper) collectVMs(
continue
}

vmUUID := moVM.Config.InstanceUuid

if string(moVM.Runtime.PowerState) == "poweredOff" {
poweredOffVMs++
} else {
Expand All @@ -288,6 +286,12 @@ func (v *vcenterMetricScraper) collectVMs(
return
}

if moVM.Config == nil {
errs.AddPartial(1, fmt.Errorf("vm config empty for %s", hostname))
continue
}
vmUUID := moVM.Config.InstanceUuid

v.collectVM(ctx, colTime, moVM, errs)
v.mb.EmitForResource(
metadata.WithVcenterVMName(vm.Name()),
Expand Down

0 comments on commit 47afa8a

Please sign in to comment.