Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crio: only collect required metrics for infra container #3592

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 16 additions & 7 deletions container/crio/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,22 @@ func newCrioContainerHandler(
Namespace: CrioNamespace,
}

// Find out if we need network metrics reported for this container.
// Containers that don't have their own network -- this includes
// containers running in Kubernetes pods that use the network of the
// infrastructure container -- does not need their stats to be
// reported. This stops metrics being reported multiple times for each
// container in a pod.
metrics := common.RemoveNetMetrics(includedMetrics, cInfo.Labels["io.kubernetes.container.name"] != "POD")
nonNetworkMetrics := common.RemoveNetMetrics(includedMetrics, true)
haircommander marked this conversation as resolved.
Show resolved Hide resolved
// If it's a non-infra container, then we can exclude network metrics,
// because in kubernetes a container always shares the network namespace
// with the infra container.
metrics := nonNetworkMetrics
// If this is the infra container cgroup, then we only need to collect network metrics
// as the rest will be discarded.
if cInfo.Labels["io.kubernetes.container.name"] == "POD" {
// Only include the non-non-network metrics. This way, we can tell if there are no network metrics
metrics = includedMetrics.Difference(nonNetworkMetrics)
Copy link

@bitoku bitoku Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding something like Intersect function in MetricsSet make more sense?

}

// No metrics are being collected, no need to create a handler.
if len(metrics) == 0 {
return nil, nil
}

libcontainerHandler := containerlibcontainer.NewHandler(cgroupManager, rootFs, cInfo.Pid, metrics)

Expand Down
6 changes: 3 additions & 3 deletions container/crio/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestHandler(t *testing.T) {
nil,
false,
nil,
nil,
container.AllMetrics,

true,
"no client returned",
Expand All @@ -70,7 +70,7 @@ func TestHandler(t *testing.T) {
nil,
false,
nil,
nil,
container.AllMetrics,

true,
"no container with id 81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f",
Expand All @@ -90,7 +90,7 @@ func TestHandler(t *testing.T) {
nil,
false,
nil,
nil,
container.AllMetrics,

false,
"",
Expand Down
Loading