Skip to content
Merged
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
5 changes: 5 additions & 0 deletions internal/containers/graph/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type ContainerInfo struct {
ImageName string
ImageTag string
Labels map[string]string

// Human-readable identifiers (container-specific only, not K8s Pod data)
ContainerName string // Container name (not pod name)
WorkloadName string // Derived: workload name with hash stripped

// Resource limits
CPUShares *int32
CPUQuotaUs *int32
Expand Down
7 changes: 7 additions & 0 deletions internal/containers/graph/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func (b *Builder) createContainerNode(container *ContainerInfo) (*resourcev1.Res
// Timestamps would be set if we had them
// CreatedAt: container.CreatedAt,
// StartedAt: container.StartedAt,

// Human-readable identifiers (container-specific only)
// Pod-level fields available via Pod resources and Container→Pod relationships
ContainerName: container.ContainerName,
WorkloadName: container.WorkloadName,

// Resource limits
CpuShares: container.CPUShares,
CpuQuotaUs: container.CPUQuotaUs,
CpuPeriodUs: container.CPUPeriodUs,
Expand Down
49 changes: 48 additions & 1 deletion internal/containers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,37 @@ var _ containergraph.RuntimeSnapshot = (*RuntimeSnapshot)(nil)
func (s *RuntimeSnapshot) GetContainers() []containergraph.ContainerInfo {
containerInfos := make([]containergraph.ContainerInfo, len(s.Containers))

for i, container := range s.Containers {
for i := range s.Containers {
container := &s.Containers[i]
// Note: Metadata extraction errors are silently ignored to allow
// container discovery to succeed even if metadata files are unavailable
_ = pkgcontainers.ExtractMetadata(container, "")

containerInfo := containergraph.ContainerInfo{
// Discovery fields
ID: container.ID,
Runtime: container.Runtime,
CgroupVersion: container.CgroupVersion,
CgroupPath: container.CgroupPath,

// Image information
ImageName: container.ImageName,
ImageTag: container.ImageTag,

// Human-readable identifiers
ContainerName: container.ContainerName,
WorkloadName: container.WorkloadName,

// Labels
Labels: container.Labels,

// Resource limits
CPUShares: container.CPUShares,
CPUQuotaUs: container.CPUQuotaUs,
CPUPeriodUs: container.CPUPeriodUs,
MemoryLimitBytes: container.MemoryLimitBytes,
CpusetCpus: container.CpusetCpus,
CpusetMems: container.CpusetMems,
}

containerInfos[i] = containerInfo
Expand Down Expand Up @@ -229,6 +254,28 @@ func (m *Manager) collectRuntimeSnapshot(ctx context.Context) (*RuntimeSnapshot,

m.logger.V(1).Info("Discovered containers", "count", len(allContainers))

// Log extracted metadata for demonstration (first 3 containers)
for i := range allContainers {
if i >= 3 {
break
}
container := &allContainers[i]
if err := pkgcontainers.ExtractMetadata(container, ""); err == nil {
m.logger.Info("Container metadata sample",
"id", container.ID[:min(12, len(container.ID))],
"runtime", container.Runtime,
// Container-specific human names
"container_name", container.ContainerName,
"workload_name", container.WorkloadName,
// Image info
"image", container.ImageName,
"tag", container.ImageTag,
// Resource limits
"has_cpu_limit", container.CPUQuotaUs != nil,
"has_memory_limit", container.MemoryLimitBytes != nil)
}
}

// For now, we'll use an empty process snapshot
// TODO: Integrate with performance manager when process collection is available
processSnapshot := &performance.ProcessSnapshot{
Expand Down
30 changes: 27 additions & 3 deletions pkg/api/antimetal/runtime/v1/linux.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 28 additions & 11 deletions pkg/containers/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,35 @@ func ParseContainerRuntime(runtime string) runtimev1.ContainerRuntime {
}
}

// Container represents a discovered container with its cgroup location and runtime information.
// This structure provides the necessary information to collect resource metrics for a container.
// Container represents a discovered container with its cgroup location, runtime information,
// and extracted metadata. This structure provides all necessary information for container
// resource metrics collection and graph building.
type Container struct {
// ID is the container identifier (may be truncated for some runtimes)
ID string
// Runtime is the detected container runtime (docker, containerd, crio, etc.)
Runtime runtimev1.ContainerRuntime
// CgroupPath is the full path to the container's cgroup directory
CgroupPath string
// CgroupVersion indicates whether this container uses cgroup v1 or v2
// Note: Different runtimes on the same host may use different cgroup versions
CgroupVersion int
// Discovery fields - populated during cgroup scanning
ID string // Container identifier (may be truncated for some runtimes)
Runtime runtimev1.ContainerRuntime // Detected container runtime
CgroupPath string // Full path to the container's cgroup directory
CgroupVersion int // Cgroup version (1 or 2)

// Image information - extracted from runtime metadata files
ImageName string
ImageTag string

// Human-readable identifiers (container-specific only)
// Note: Pod-level fields (pod name, namespace, app) are available in K8s Pod resources
ContainerName string // "nginx", "web", "sidecar"
WorkloadName string // "web-server" (deployment name, hash stripped)

// Labels - full map containing all K8s/Docker metadata
Labels map[string]string

// Resource limits - extracted from cgroup files
CPUShares *int32
CPUQuotaUs *int32
CPUPeriodUs *int32
MemoryLimitBytes *uint64
CpusetCpus string
CpusetMems string
}

// Discovery provides methods to discover containers in cgroup hierarchies.
Expand Down
Loading
Loading