Files
team/server/channels/app/platform/container_limits_other.go
2381664c84 [MM-67975] Add container CPU and memory limits to support packet diagnostics (#35835)
* MM-67975: Add container CPU and memory limits to support packet diagnostics

Add two new optional fields to SupportPacketDiagnostics.Server:
- container_cpu_limit (float64): effective CPU limit in CPUs (e.g. 0.5, 2.0)
- container_memory_limit_mb (uint64): memory limit in MB

Both fields are populated from cgroups v2 (/sys/fs/cgroup/memory.max and
/sys/fs/cgroup/cpu.max) on Linux. Fields use omitempty so they are absent
from the output on bare metal or when no container limits are configured,
preserving backwards compatibility.

Non-Linux builds compile and produce no output for these fields via a
container_limits_other.go stub, following the existing memory_linux.go /
memory_other.go pattern.

* Fix golangci-lint errors: govet shadow and gofmt formatting

- Fix govet shadow: use var memBytes uint64 + err = instead of memBytes, err :=
  to avoid shadowing the outer err variable (which is reused after this block)
- Fix gofmt: add extra space before // 512 MB comment to align with
  the longer v2CPUMax line in the same assignment block

* fix(platform): ceil memory MB conversion and return zero-values for missing cgroup files

- Use ceiling division for MemoryLimitMB so sub-1MB limits map to 1 instead
  of 0 (which omitempty would silently drop)
- Absorb os.ErrNotExist in getContainerLimits so non-v2/bare-metal hosts
  return ContainerLimits{}, nil as the function comment promises
- Update test: missing cgroup file now asserts zero-values, not an error

* test(platform): add subtest locking ceil-to-MB behavior for sub-MB memory limits

* test(platform): add subtest for missing cpu.max returning zero values

Locks in the os.ErrNotExist branch for cpu.max (lines 57-60 in
container_limits_linux.go), which was previously unreachable via the
existing missing-memory test since that test returns early before
reading cpu.max.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-04-23 13:25:34 +00:00

20 lines
616 B
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//go:build !linux
package platform
// ContainerLimits holds effective CPU and memory limits for the current container.
// Zero values indicate no limit is set (fields will be omitted from YAML output).
type ContainerLimits struct {
CPULimit float64
MemoryLimitMB uint64
}
// getContainerLimits returns zero values on non-Linux platforms.
// Container limit detection via cgroups is only supported on Linux.
func getContainerLimits() (ContainerLimits, error) {
return ContainerLimits{}, nil
}