Skip to content

Commit

Permalink
fix: ensure containerDecorator is nil (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercoll authored Jun 1, 2023
1 parent 07ab68f commit c6a9b8e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/metrics/containerd_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type containerdDecorator struct {
// compile-time assertion.
var _ ProcessDecorator = &containerdDecorator{} //nolint:exhaustruct

func newContainerdDecorator(containerdClient helpers.ContainerdInterface, pidsCache *pidsCache) (*containerdDecorator, error) { //nolint:ireturn
func newContainerdDecorator(containerdClient helpers.ContainerdInterface, pidsCache *pidsCache) (ProcessDecorator, error) { //nolint:ireturn
dec := &containerdDecorator{ //nolint:exhaustruct
containerdClient: containerdClient,
cache: pidsCache,
Expand Down
2 changes: 2 additions & 0 deletions pkg/metrics/process/sampler_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func (ps *processSampler) Sample() (results sample.EventBatch, err error) {
if ps.containerSampler.Enabled() {
containerDecorator, err = ps.containerSampler.NewDecorator()
if err != nil {
// ensure containerDecorator is set to nil if error
containerDecorator = nil
if id := containerIDFromNotRunningErr(err); id != "" {
if _, ok := containerNotRunningErrs[id]; !ok {
containerNotRunningErrs[id] = struct{}{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/metrics/process/sampler_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (ps *processSampler) Sample() (results sample.EventBatch, err error) {
if ps.containerSampler.Enabled() {
containerDecorator, err = ps.containerSampler.NewDecorator()
if err != nil {
// ensure containerDecorator is set to nil if error
containerDecorator = nil
if id := containerIDFromNotRunningErr(err); id != "" {
if _, ok := containerNotRunningErrs[id]; !ok {
containerNotRunningErrs[id] = struct{}{}
Expand Down
11 changes: 6 additions & 5 deletions pkg/metrics/procs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import (
"unsafe"

"github.com/StackExchange/wmi"
"github.com/newrelic/infrastructure-agent/pkg/metrics/types"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/process"
"github.com/sirupsen/logrus"

"github.com/newrelic/infrastructure-agent/internal/agent"
"github.com/newrelic/infrastructure-agent/pkg/config"
"github.com/newrelic/infrastructure-agent/pkg/helpers"
"github.com/newrelic/infrastructure-agent/pkg/metrics/acquire"
"github.com/newrelic/infrastructure-agent/pkg/metrics/types"
"github.com/newrelic/infrastructure-agent/pkg/sample"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/process"
"github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -662,6 +661,8 @@ func (self *ProcsMonitor) Sample() (results sample.EventBatch, err error) {
if self.containerSampler.Enabled() {
containerDecorator, err = self.containerSampler.NewDecorator()
if err != nil {
// ensure containerDecorator is set to nil if error
containerDecorator = nil
if id := containerIDFromNotRunningErr(err); id != "" {
if _, ok := containerNotRunningErrs[id]; !ok {
containerNotRunningErrs[id] = struct{}{}
Expand Down

0 comments on commit c6a9b8e

Please sign in to comment.