Skip to content

Commit

Permalink
Do not report container stats for muted namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpichler committed Mar 12, 2024
1 parent 30bc53c commit 577fb7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 8 additions & 0 deletions cmd/agent/daemon/state/container_stats_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (c *Controller) scrapeContainersResourceStats(batch *castpb.ContainerStatsB
continue
}

if c.IsMutedNamespace(cont.PodNamespace) {
continue
}

now := time.Now().UTC()
cpu, err := cont.Cgroup.CpuStat()
if err != nil {
Expand Down Expand Up @@ -234,6 +238,10 @@ func (c *Controller) scrapeContainersSyscallStats(ctx context.Context, batch *ca
continue
}

if c.IsMutedNamespace(cont.PodNamespace) {
continue
}

// We need at least 2 scrapes to calculate diff count.
c.syscallScrapePointsMu.RLock()
prevScrape, found := c.syscallScrapePoints[cont.CgroupID]
Expand Down
14 changes: 9 additions & 5 deletions cmd/agent/daemon/state/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ func (c *Controller) Run(ctx context.Context) error {
}

func (c *Controller) onNewContainer(container *containers.Container) {
c.mutedNamespacesMu.RLock()
_, muted := c.mutedNamespaces[container.PodNamespace]
c.mutedNamespacesMu.RUnlock()

if !muted {
if !c.IsMutedNamespace(container.PodNamespace) {
return
}

Expand Down Expand Up @@ -202,3 +198,11 @@ func (c *Controller) UnmuteNamespace(namespace string) error {

return nil
}

func (c *Controller) IsMutedNamespace(namespace string) bool {
c.mutedNamespacesMu.RLock()
defer c.mutedNamespacesMu.RUnlock()
_, found := c.mutedNamespaces[namespace]

return found
}

0 comments on commit 577fb7a

Please sign in to comment.