forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[receiver/k8s_cluster] Do not store unused data in the k8s API cache (o…
…pen-telemetry#23417) This change removes unused k8s informer data from the cache to reduce RAM utilization. Tried it on a cluster with 40 nodes and 1000 pods, and it gave up to 30% reduction in RAM usage.
- Loading branch information
Showing
13 changed files
with
589 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
# If your change doesn't affect end users, such as a test fix or a tooling change, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: 'enhancement' | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: receiver/k8s_cluster | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Do not store unused data in the k8s API cache to reduce RAM usage | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [23417] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package k8sclusterreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver" | ||
|
||
import ( | ||
appsv1 "k8s.io/api/apps/v1" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/jobs" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/node" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/pod" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/replicaset" | ||
) | ||
|
||
// transformObject transforms the k8s object by removing the data that is not utilized by the receiver. | ||
// Only highly utilized objects are transformed here while others are kept as is. | ||
func transformObject(object interface{}) (interface{}, error) { | ||
switch o := object.(type) { | ||
case *corev1.Pod: | ||
return pod.Transform(o), nil | ||
case *corev1.Node: | ||
return node.Transform(o), nil | ||
case *appsv1.ReplicaSet: | ||
return replicaset.Transform(o), nil | ||
case *batchv1.Job: | ||
return jobs.Transform(o), nil | ||
} | ||
return object, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package k8sclusterreceiver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/testutils" | ||
) | ||
|
||
func TestTransformObject(t *testing.T) { | ||
i := 1 | ||
intPtr := &i | ||
tests := []struct { | ||
name string | ||
object interface{} | ||
want interface{} | ||
same bool | ||
}{ | ||
{ | ||
name: "pod", | ||
object: testutils.NewPodWithContainer( | ||
"1", | ||
testutils.NewPodSpecWithContainer("container-name"), | ||
testutils.NewPodStatusWithContainer("container-name", "container-id"), | ||
), | ||
want: func() *corev1.Pod { | ||
pod := testutils.NewPodWithContainer( | ||
"1", | ||
testutils.NewPodSpecWithContainer("container-name"), | ||
testutils.NewPodStatusWithContainer("container-name", "container-id"), | ||
) | ||
pod.Spec.Containers[0].Image = "" | ||
pod.Status.ContainerStatuses[0].State = corev1.ContainerState{} | ||
return pod | ||
}(), | ||
same: false, | ||
}, | ||
{ | ||
name: "node", | ||
object: testutils.NewNode("1"), | ||
want: testutils.NewNode("1"), | ||
same: false, | ||
}, | ||
{ | ||
name: "replicaset", | ||
object: testutils.NewReplicaSet("1"), | ||
want: testutils.NewReplicaSet("1"), | ||
same: false, | ||
}, | ||
{ | ||
name: "job", | ||
object: testutils.NewJob("1"), | ||
want: testutils.NewJob("1"), | ||
same: false, | ||
}, | ||
{ | ||
// This is a case where we don't transform the object. | ||
name: "hpa", | ||
object: testutils.NewHPA("1"), | ||
want: testutils.NewHPA("1"), | ||
same: true, | ||
}, | ||
{ | ||
name: "invalid_type", | ||
object: intPtr, | ||
want: intPtr, | ||
same: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := transformObject(tt.object) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.want, got) | ||
if tt.same { | ||
assert.Same(t, tt.object, got) | ||
} else { | ||
assert.NotSame(t, tt.object, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.