Skip to content

Commit

Permalink
NSOF-8274 receiver/hostmetricsreceiver:processscraper: Workaround pro…
Browse files Browse the repository at this point in the history
…cess createTime bogus value

Process createTime collected using gopsutils/process module and uses as
startTime of metric sequence.
When running inside lxc, function that calculates create time mixes host
and guest stats.
See shirou/gopsutil#1562 for more details
This leads to two issues:
1. Calculated createTime has future value eventually causing scrapper to
skip process collection.
2. dp series startTime is set to future in time value, the consequences
   are unknown.
In order to overcome this issue, we will set createTime to system boot time.
In case of lxc, container boot time
  • Loading branch information
drubinMeta committed Dec 17, 2023
1 parent 299e6e3 commit c0abf5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ type scraper struct {
// newProcessScraper creates a Process Scraper
func newProcessScraper(settings receiver.CreateSettings, cfg *Config) (*scraper, error) {
scraper := &scraper{
settings: settings,
config: cfg,
getProcessCreateTime: processHandle.CreateTimeWithContext,
getProcessHandles: getProcessHandlesInternal,
scrapeProcessDelay: cfg.ScrapeProcessDelay,
ucals: make(map[int32]*ucal.CPUUtilizationCalculator),
handleCountManager: handlecount.NewManager(),
settings: settings,
config: cfg,
getProcessCreateTime: func(p processHandle, ctx context.Context) (int64, error) {
return getProcessCreateTimeInternal(ctx, p)
},
getProcessHandles: getProcessHandlesInternal,
scrapeProcessDelay: cfg.ScrapeProcessDelay,
ucals: make(map[int32]*ucal.CPUUtilizationCalculator),
handleCountManager: handlecount.NewManager(),
}

var err error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ func getProcessCommand(ctx context.Context, proc processHandle) (*commandMetadat
return command, nil

}

func getProcessCreateTimeInternal(ctx context.Context, proc processHandle) (int64, error) {
return proc.CreateTimeWithContext(ctx)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"

"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/host"
"go.opentelemetry.io/collector/pdata/pcommon"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata"
Expand Down Expand Up @@ -60,3 +61,18 @@ func getProcessCommand(ctx context.Context, proc processHandle) (*commandMetadat
command := &commandMetadata{command: cmd, commandLineSlice: cmdline}
return command, nil
}

func getProcessCreateTimeInternal(ctx context.Context, proc processHandle) (int64, error) {
vsystem, vrole, err := host.VirtualizationWithContext(ctx)
if err != nil {
return 0, err
}
if vsystem == "lxc" && vrole == "guest" {
bootTime, err := host.BootTimeWithContext(ctx)
if err != nil {
return 0, err
}
return int64(bootTime) * 1000, nil
}
return proc.CreateTimeWithContext(ctx)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ func getProcessExecutable(context.Context, processHandle) (string, error) {
func getProcessCommand(context.Context, processHandle) (*commandMetadata, error) {
return nil, nil
}

func getProcessCreateTimeInternal(ctx context.Context, proc processHandle) (int64, error) {
return 0, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ func getProcessCommand(ctx context.Context, proc processHandle) (*commandMetadat
command := &commandMetadata{command: cmd, commandLine: cmdline}
return command, nil
}

func getProcessCreateTimeInternal(ctx context.Context, proc processHandle) (int64, error) {
return proc.CreateTimeWithContext(ctx)
}

0 comments on commit c0abf5d

Please sign in to comment.