Skip to content

Bug: Fix error formatting #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metric/cpu/metrics_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func parseCPULine(line string) (CPU, error) {
tryParseUint := func(name, field string) (v opt.Uint) {
u, err := touint(field)
if err != nil {
errs = append(errs, fmt.Errorf("failed to parse %v: %s", name, field))
errs = append(errs, fmt.Errorf("failed to parse %s: %s", name, field))
} else {
v = opt.UintWith(u)
}
Expand Down
2 changes: 1 addition & 1 deletion metric/memory/memory_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func get(_ resolve.Resolver) (Memory, error) {
meminfo := C.perfstat_memory_total_t{}
_, err := C.perfstat_memory_total(nil, &meminfo, C.sizeof_perfstat_memory_total_t, 1)
if err != nil {
return memData, fmt.Errorf("perfstat_memory_total: %s", err)
return memData, fmt.Errorf("perfstat_memory_total: %w", err)
}

totalMem := uint64(meminfo.real_total) * system.pagesize
Expand Down
2 changes: 1 addition & 1 deletion metric/system/cgroup/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestSupportedSubsystems(t *testing.T) {
func TestSupportedSubsystemsErrCgroupsMissing(t *testing.T) {
_, err := SupportedSubsystems(resolve.NewTestResolver("testdata/doesnotexist"))
if !errors.Is(err, ErrCgroupsMissing) {
t.Fatalf("expected ErrCgroupsMissing, but got %v", err)
t.Fatalf("expected ErrCgroupsMissing, but got %s", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion metric/system/diskio/diskstat_windows_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ioCounters(names ...string) (map[string]disk.IOCountersStat, error) {
var counter diskPerformance
err = ioCounter(drive.UNCPath, &counter)
if err != nil {
logp.Err("Could not return any performance counter values for %s .Error: %v", drive.UNCPath, err)
logp.Err("Could not return any performance counter values for %s .Error: %s", drive.UNCPath, err)
continue
}
ret[drive.Name] = disk.IOCountersStat{
Expand Down
2 changes: 1 addition & 1 deletion metric/system/filesystem/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestFileSystemList(t *testing.T) {

for _, fs := range fss {
err := fs.GetUsage()
assert.NoError(t, err, "filesystem=%#v: %v", fs, err)
assert.NoError(t, err, "filesystem=%#v: %s", fs, err)

}
}
Expand Down
6 changes: 3 additions & 3 deletions metric/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
failedPIDs := extractFailedPIDs(pidMap)
if err != nil && len(failedPIDs) > 0 {
init.logger.Debugf("error fetching process metrics: %v", err)
init.logger.Debugf("error fetching process metrics: %s", err)
return plist, NonFatalErr{Err: fmt.Errorf(errFetchingPIDs, len(failedPIDs))}
}
return plist, toNonFatal(err)
Expand Down Expand Up @@ -115,7 +115,7 @@
if procStats.host != nil {
memStats, err := procStats.host.Memory()
if err != nil {
procStats.logger.Warnf("Getting memory details: %v", err)
procStats.logger.Warnf("Getting memory details: %s", err)
} else {
totalPhyMem = memStats.Total
}
Expand All @@ -141,7 +141,7 @@
rootEvents = append(rootEvents, rootMap)
}
if wrappedErr != nil && len(failedPIDs) > 0 {
procStats.logger.Debugf("error fetching process metrics: %v", wrappedErr)
procStats.logger.Debugf("error fetching process metrics: %s", wrappedErr)
return procs, rootEvents, NonFatalErr{Err: fmt.Errorf(errFetchingPIDs, len(failedPIDs))}
}
return procs, rootEvents, toNonFatal(wrappedErr)
Expand Down Expand Up @@ -310,7 +310,7 @@

// network data
if procStats.EnableNetwork {
procHandle, err := sysinfo.Process(pid)

Check failure on line 313 in metric/system/process/process.go

View workflow job for this annotation

GitHub Actions / lint-darwin

undefined: sysinfo (typecheck)

Check failure on line 313 in metric/system/process/process.go

View workflow job for this annotation

GitHub Actions / lint (windows)

undefined: sysinfo (typecheck)

Check failure on line 313 in metric/system/process/process.go

View workflow job for this annotation

GitHub Actions / lint (linux)

undefined: sysinfo (typecheck)
// treat this as a soft error
if err != nil {
procStats.logger.Debugf("error initializing process handler for pid %d while trying to fetch network data: %w", pid, err)
Expand Down
4 changes: 2 additions & 2 deletions metric/system/process/process_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@
func (procStats *Stats) Init() error {
procStats.logger = logp.NewLogger("processes")
var err error
procStats.host, err = sysinfo.Host()

Check failure on line 162 in metric/system/process/process_common.go

View workflow job for this annotation

GitHub Actions / lint-darwin

undefined: sysinfo (typecheck)

Check failure on line 162 in metric/system/process/process_common.go

View workflow job for this annotation

GitHub Actions / lint (windows)

undefined: sysinfo (typecheck)

Check failure on line 162 in metric/system/process/process_common.go

View workflow job for this annotation

GitHub Actions / lint (linux)

undefined: sysinfo (typecheck)
if err != nil {
procStats.host = nil
procStats.logger.Warnf("Getting host details: %v", err)
procStats.logger.Warnf("Getting host details: %s", err)
}

// footcannon prevention
Expand Down Expand Up @@ -201,7 +201,7 @@
if procStats.EnableCgroups {
cgReader, err := cgroup.NewReaderOptions(procStats.CgroupOpts)
if errors.Is(err, cgroup.ErrCgroupsMissing) {
logp.Warn("cgroup data collection will be disabled: %v", err)
logp.Warn("cgroup data collection will be disabled: %s", err)
procStats.EnableCgroups = false
} else if err != nil {
return fmt.Errorf("error initializing cgroup reader: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion metric/system/process/process_linux_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGetInfoForPid_numThreads(t *testing.T) {
if !got.NumThreads.Exists() {
bs, err := json.Marshal(got)
if err != nil {
t.Logf("could not marshal ProcState: %v", err)
t.Logf("could not marshal ProcState: %s", err)
}
t.Fatalf("num_thread was not collected. Collected info: %s", bs)
}
Expand Down
2 changes: 1 addition & 1 deletion metric/system/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestGetState(t *testing.T) {

assert.Eventuallyf(t, test,
time.Second*5, 50*time.Millisecond,
"got process state %q. Last error: %v", got, err)
"got process state %q. Last error: %s", got, err)
}

func TestGetOneRoot(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion metric/system/process/process_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestGetInfoForPid_numThreads(t *testing.T) {
if !state.NumThreads.Exists() {
bs, err := json.Marshal(state)
if err != nil {
t.Logf("could not marshal ProcState: %v", err)
t.Logf("could not marshal ProcState: %s", err)
}
t.Fatalf("num_thread was not collected. Collected info: %s", bs)
}
Expand Down
2 changes: 1 addition & 1 deletion report/metrics_file_descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func FDUsageReporter(logger *logp.Logger, processStats *process.Stats) func(_ mo

open, hardLimit, softLimit, err := getFDUsage(processStats)
if err != nil {
logger.Error("Error while retrieving FD information: %v", err)
logger.Errorf("Error while retrieving FD information: %s", err)
return
}

Expand Down
6 changes: 3 additions & 3 deletions report/metrics_handles.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ var (
func SetupWindowsHandlesMetrics(logger *logp.Logger, reg *monitoring.Registry) {
beatProcessSysInfo, err := sysinfo.Self()
if err != nil {
logger.Error("Error while getting own process info: %v", err)
logger.Errorf("Error while getting own process info: %s", err)
logger.Error(fileHandlesNotReported)
return
}

var ok bool
handleCounter, ok = beatProcessSysInfo.(types.OpenHandleCounter)
if !ok {
logger.Error("Process does not implement types.OpenHandleCounter: %v", beatProcessSysInfo)
logger.Errorf("Process does not implement types.OpenHandleCounter: %s", beatProcessSysInfo)
logger.Error(fileHandlesNotReported)
return
}
Expand All @@ -61,7 +61,7 @@ func openHandlesReporter(logger *logp.Logger) func(_ monitoring.Mode, V monitori

n, err := handleCounter.OpenHandleCount()
if err != nil {
logger.Error("Error while retrieving the number of open file handles: %v", err)
logger.Errorf("Error while retrieving the number of open file handles: %s", err)
return
}
monitoring.ReportInt(V, "open", int64(n))
Expand Down
16 changes: 8 additions & 8 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func MemStatsReporter(logger *logp.Logger, processStats *process.Stats) func(mon

state, err := processStats.GetSelf()
if err != nil {
logger.Errorf("Error while getting memory usage: %v", err)
logger.Errorf("Error while getting memory usage: %s", err)
return
}

Expand All @@ -67,7 +67,7 @@ func InstanceCPUReporter(logger *logp.Logger, processStats *process.Stats) func(

state, err := processStats.GetSelf()
if err != nil {
logger.Errorf("Error retrieving CPU percentages: %v", err)
logger.Errorf("Error retrieving CPU percentages: %s", err)
return
}

Expand Down Expand Up @@ -99,7 +99,7 @@ func ReportSystemLoadAverage(_ monitoring.Mode, V monitoring.Visitor) {

load, err := cpu.Load()
if err != nil {
logp.Err("Error retrieving load average: %v", err)
logp.Err("Error retrieving load average: %s", err)
return
}
avgs := load.Averages()
Expand Down Expand Up @@ -145,16 +145,16 @@ func InstanceCroupsReporter(logger *logp.Logger, override string) func(monitorin
})
if err != nil {
if errors.Is(err, cgroup.ErrCgroupsMissing) {
logger.Warnf("cgroup data collection disabled in internal monitoring: %v", err)
logger.Warnf("cgroup data collection disabled in internal monitoring: %s", err)
} else {
logger.Errorf("cgroup data collection disabled in internal monitoring: %v", err)
logger.Errorf("cgroup data collection disabled in internal monitoring: %s", err)
}
return
}

cgv, err := cgroups.CgroupsVersion(pid)
if err != nil {
logger.Errorf("error determining cgroups version for internal monitoring: %v", err)
logger.Errorf("error determining cgroups version for internal monitoring: %s", err)
return
}

Expand All @@ -170,7 +170,7 @@ func InstanceCroupsReporter(logger *logp.Logger, override string) func(monitorin
func ReportMetricsCGV1(logger *logp.Logger, pid int, cgroups *cgroup.Reader, V monitoring.Visitor) {
selfStats, err := cgroups.GetV1StatsForProcess(pid)
if err != nil {
logger.Errorf("error getting cgroup stats for V1: %v", err)
logger.Errorf("error getting cgroup stats for V1: %s", err)
}
// GetStatsForProcess returns a nil selfStats and no error when there's no stats
if selfStats == nil {
Expand Down Expand Up @@ -231,7 +231,7 @@ func ReportMetricsCGV1(logger *logp.Logger, pid int, cgroups *cgroup.Reader, V m
func ReportMetricsCGV2(logger *logp.Logger, pid int, cgroups *cgroup.Reader, V monitoring.Visitor) {
selfStats, err := cgroups.GetV2StatsForProcess(pid)
if err != nil {
logger.Errorf("error getting cgroup stats for V2: %v", err)
logger.Errorf("error getting cgroup stats for V2: %s", err)
return
}

Expand Down
Loading