Skip to content

Commit

Permalink
Fix stats overflow (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao authored Jan 24, 2025
1 parent 35d43b8 commit ae324e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/agent/daemon/state/stats_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package state

import (
"context"
"errors"
"log/slog"
"time"

castaipb "github.com/castai/kvisor/api/v1/runtime"
"github.com/castai/kvisor/cmd/agent/daemon/metrics"
"github.com/castai/kvisor/pkg/cgroup"
"github.com/castai/kvisor/pkg/containers"
)

Expand Down Expand Up @@ -63,6 +65,9 @@ func (c *Controller) scrapeContainersResourceStats(batch *castaipb.StatsBatch) {
func (c *Controller) scrapeContainerResourcesStats(cont *containers.Container, batch *castaipb.StatsBatch) {
cgStats, err := c.containersClient.GetCgroupStats(cont)
if err != nil {
if errors.Is(err, cgroup.ErrStatsNotFound) {
return
}
if c.log.IsEnabled(slog.LevelDebug) {
c.log.Errorf("getting cgroup stats for container %q: %v", cont.Name, err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/cgroup/cgroup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cgroup

import (
"errors"
"os"
"path"
"strings"
Expand All @@ -10,6 +11,8 @@ import (

const UnifiedMountpoint = "/sys/fs/cgroup"

var ErrStatsNotFound = errors.New("stats not found")

type Stats struct {
CpuStats *castaipb.CpuStats
MemoryStats *castaipb.MemoryStats
Expand All @@ -34,7 +37,8 @@ func (cg *Cgroup) GetStats() (Stats, error) {
}
if err := cg.statsGetterFunc(&res); err != nil {
if os.IsNotExist(err) {
return res, nil
// Most likely container was deleted.
return res, ErrStatsNotFound
}
return res, err
}
Expand Down

0 comments on commit ae324e4

Please sign in to comment.