Skip to content

Commit 7a8afdf

Browse files
committed
nrt: log: enhance logging in container scope
before #710 and #725, we logged the container being processed alongside the pod (identified by namespace/name pair). It was dropped by mistake and not deliberately. This is useful information when troubleshooting, so let's add it back. Signed-off-by: Francesco Romani <[email protected]>
1 parent 004e0d9 commit 7a8afdf

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

pkg/noderesourcetopology/filter.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,34 @@ func singleNUMAContainerLevelHandler(lh logr.Logger, pod *v1.Pod, zones topology
5555
// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#understanding-init-containers
5656
// therefore, we don't need to accumulate their resources together
5757
for _, initContainer := range pod.Spec.InitContainers {
58-
lh.V(6).Info("init container desired resources", stringify.ResourceListToLoggable(initContainer.Resources.Requests)...)
58+
// TODO: handle sidecar explicitely (new kind)
59+
clh := lh.WithValues(logging.KeyContainer, initContainer.Name, logging.KeyContainerKind, logging.KindContainerInit)
60+
clh.V(6).Info("desired resources", stringify.ResourceListToLoggable(initContainer.Resources.Requests)...)
5961

60-
_, match := resourcesAvailableInAnyNUMANodes(lh, nodes, initContainer.Resources.Requests, qos, nodeInfo)
62+
_, match := resourcesAvailableInAnyNUMANodes(clh, nodes, initContainer.Resources.Requests, qos, nodeInfo)
6163
if !match {
6264
// we can't align init container, so definitely we can't align a pod
63-
lh.V(2).Info("cannot align container", "name", initContainer.Name, "kind", "init")
65+
clh.V(2).Info("cannot align container")
6466
return framework.NewStatus(framework.Unschedulable, "cannot align init container")
6567
}
6668
}
6769

6870
for _, container := range pod.Spec.Containers {
69-
// TODO: add containerName
70-
lh.V(6).Info("app container resources", stringify.ResourceListToLoggable(container.Resources.Requests)...)
71+
clh := lh.WithValues(logging.KeyContainer, container.Name, logging.KeyContainerKind, logging.KindContainerApp)
72+
clh.V(6).Info("app container resources", stringify.ResourceListToLoggable(container.Resources.Requests)...)
7173

72-
numaID, match := resourcesAvailableInAnyNUMANodes(lh, nodes, container.Resources.Requests, qos, nodeInfo)
74+
numaID, match := resourcesAvailableInAnyNUMANodes(clh, nodes, container.Resources.Requests, qos, nodeInfo)
7375
if !match {
7476
// we can't align container, so definitely we can't align a pod
75-
lh.V(2).Info("cannot align container", "name", container.Name, "kind", "app")
77+
clh.V(2).Info("cannot align container")
7678
return framework.NewStatus(framework.Unschedulable, "cannot align container")
7779
}
7880

7981
// subtract the resources requested by the container from the given NUMA.
8082
// this is necessary, so we won't allocate the same resources for the upcoming containers
81-
subtractFromNUMA(lh, nodes, numaID, container)
83+
subtractFromNUMA(clh, nodes, numaID, container)
84+
clh.V(4).Info("app container placed", "numaCell", numaID)
8285
}
83-
lh.V(2).Info("can align all containers")
8486
return nil
8587
}
8688

@@ -150,7 +152,7 @@ func resourcesAvailableInAnyNUMANodes(lh logr.Logger, numaNodes NUMANodeList, re
150152

151153
// at least one NUMA node is available
152154
ret := !bitmask.IsEmpty()
153-
lh.V(2).Info("final verdict", "suitable", ret)
155+
lh.V(2).Info("final verdict", "suitable", ret, "numaCell", numaID)
154156
return numaID, ret
155157
}
156158

@@ -172,11 +174,12 @@ func singleNUMAPodLevelHandler(lh logr.Logger, pod *v1.Pod, zones topologyv1alph
172174
logNumaNodes(lh, "pod handler NUMA resources", nodeInfo.Node().Name, nodes)
173175
lh.V(6).Info("pod desired resources", stringify.ResourceListToLoggable(resources)...)
174176

175-
if _, match := resourcesAvailableInAnyNUMANodes(lh, createNUMANodeList(lh, zones), resources, v1qos.GetPodQOS(pod), nodeInfo); !match {
177+
numaID, match := resourcesAvailableInAnyNUMANodes(lh, createNUMANodeList(lh, zones), resources, v1qos.GetPodQOS(pod), nodeInfo)
178+
if !match {
176179
lh.V(2).Info("cannot align pod", "name", pod.Name)
177180
return framework.NewStatus(framework.Unschedulable, "cannot align pod")
178181
}
179-
lh.V(2).Info("can align pod")
182+
lh.V(4).Info("all container placed", "numaCell", numaID)
180183
return nil
181184
}
182185

pkg/noderesourcetopology/logging/logging.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import (
2626

2727
// well-known structured log keys
2828
const (
29-
KeyLogID string = "logID"
30-
KeyPod string = "pod"
31-
KeyPodUID string = "podUID"
32-
KeyNode string = "node"
33-
KeyFlow string = "flow"
29+
KeyLogID string = "logID"
30+
KeyPod string = "pod"
31+
KeyPodUID string = "podUID"
32+
KeyNode string = "node"
33+
KeyFlow string = "flow"
34+
KeyContainer string = "container"
35+
KeyContainerKind string = "kind"
3436
)
3537

3638
const (
@@ -42,6 +44,11 @@ const (
4244
FlowCacheSync string = "resync"
4345
)
4446

47+
const (
48+
KindContainerInit string = "init"
49+
KindContainerApp string = "app"
50+
)
51+
4552
const (
4653
SubsystemForeignPods string = "foreignpods"
4754
SubsystemNRTCache string = "nrtcache"

pkg/noderesourcetopology/stringify/stringify.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ func nrtResourceInfo(resInfo topologyv1alpha2.ResourceInfo) string {
106106
return resInfo.Name + "=" + humanize.IBytes(uint64(capVal)) + "/" + humanize.IBytes(uint64(allocVal)) + "/" + humanize.IBytes(uint64(availVal))
107107
}
108108

109-
func needsHumanization(resName string) bool {
109+
func needsHumanization(rn string) bool {
110+
resName := corev1.ResourceName(rn)
110111
// memory-related resources may be expressed in KiB/Bytes, which makes
111112
// for long numbers, harder to read and compare. To make it easier for
112113
// the reader, we express them in a more compact form using go-humanize.
113-
return resName == string(corev1.ResourceMemory) || v1helper.IsHugePageResourceName(corev1.ResourceName(resName))
114+
if resName == corev1.ResourceMemory {
115+
return true
116+
}
117+
if resName == corev1.ResourceStorage || resName == corev1.ResourceEphemeralStorage {
118+
return true
119+
}
120+
return v1helper.IsHugePageResourceName(resName)
114121
}

pkg/noderesourcetopology/stringify/stringify_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ func TestResourceListToLoggable(t *testing.T) {
111111
},
112112
expected: ` logID="TEST4" awesome.net/gpu="4" cpu="24" example.com/netdevice="16" hugepages-2Mi="1.0 GiB" memory="16 GiB"`,
113113
},
114+
{
115+
name: "CPUs, Memory, EphemeralStorage",
116+
logID: "TEST5",
117+
resources: corev1.ResourceList{
118+
corev1.ResourceCPU: resource.MustParse("24"),
119+
corev1.ResourceMemory: resource.MustParse("16Gi"),
120+
corev1.ResourceEphemeralStorage: resource.MustParse("4Gi"),
121+
},
122+
expected: ` logID="TEST5" cpu="24" ephemeral-storage="4.0 GiB" memory="16 GiB"`,
123+
},
124+
{
125+
name: "CPUs, Memory, EphemeralStorage, hugepages-1Gi",
126+
logID: "TEST6",
127+
resources: corev1.ResourceList{
128+
corev1.ResourceCPU: resource.MustParse("24"),
129+
corev1.ResourceMemory: resource.MustParse("16Gi"),
130+
corev1.ResourceName("hugepages-1Gi"): resource.MustParse("4Gi"),
131+
corev1.ResourceEphemeralStorage: resource.MustParse("6Gi"),
132+
},
133+
expected: ` logID="TEST6" cpu="24" ephemeral-storage="6.0 GiB" hugepages-1Gi="4.0 GiB" memory="16 GiB"`,
134+
},
114135
}
115136

116137
for _, tt := range tests {

0 commit comments

Comments
 (0)