Skip to content

Commit

Permalink
chore: Improve error logging for sub collectors
Browse files Browse the repository at this point in the history
Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Oct 24, 2024
1 parent 7d42ac9 commit ac27c05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/collector/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ func NewEbpfCollector(logger log.Logger, cgManager *cgroupManager) (*ebpfCollect
func (c *ebpfCollector) Update(ch chan<- prometheus.Metric, cgroupIDUUIDMap map[string]string) error {
// Fetch all active cgroups
if err := c.discoverCgroups(cgroupIDUUIDMap); err != nil {
return err
return fmt.Errorf("failed to discover cgroups: %w", err)
}

// Fetch metrics from maps
aggMetrics, err := c.readMaps()
if err != nil {
return err
return fmt.Errorf("failed to read bpf maps: %w", err)
}

// Start wait group
Expand Down Expand Up @@ -827,10 +827,12 @@ func (c *ebpfCollector) readMaps() (*aggMetrics, error) {
if securityCtx, ok := c.securityContexts[ebpfReadBPFMapsCtx]; ok {
if err := securityCtx.Exec(dataPtr); err == nil {
return dataPtr.aggMetrics, nil
} else {
return nil, err
}
}

return nil, ErrNoData
return nil, security.ErrNoSecurityCtx
}

// discoverCgroups walks through cgroup file system and discover all relevant cgroups based
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (c *perfCollector) Update(ch chan<- prometheus.Metric, cgroupIDUUIDMap map[
// Discover new processes
cgroups, err := c.discoverProcess()
if err != nil {
return fmt.Errorf("%w: %w", ErrNoData, err)
return fmt.Errorf("failed to discover processes: %w", err)
}

// Start new profilers for new processes
Expand All @@ -557,7 +557,7 @@ func (c *perfCollector) Update(ch chan<- prometheus.Metric, cgroupIDUUIDMap map[

// Ensure cgroups is non empty
if len(cgroups) == 0 {
return ErrNoData
return nil
}

// Start a wait group
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/slurm.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (c *slurmCollector) Update(ch chan<- prometheus.Metric) error {
// Discover all active cgroups
metrics, err := c.discoverCgroups()
if err != nil {
return fmt.Errorf("%w: %w", ErrNoData, err)
return fmt.Errorf("failed to discover cgroups: %w", err)
}

// Start a wait group
Expand Down

0 comments on commit ac27c05

Please sign in to comment.