BREAKING: (Feature) maximum pod log size limit

introduces a new option to limit the size of a pod log when added to the bundle. This will make sure the support bundle will not grow to an unacceptable size and thus might contain information that is too old.

The maximum size of a pod log in a bundle is set by default to 5MB, and can be changed if we decide upon the need.

BREAKING CHANGE: any logs that are collected by the logs collector are now limited by default to 5MB unless a different size limit is specified.  Folks expecting log files larger than that to be collected without truncation will need to adjust their support bundle specs.

Fixes: #878
This commit is contained in:
Edgar Lanting
2023-01-05 04:23:43 +01:00
committed by GitHub
parent a31e2ff1b9
commit a442ac8fc4
12 changed files with 54 additions and 6 deletions

View File

@@ -326,6 +326,9 @@ spec:
properties:
maxAge:
type: string
maxBytes:
format: int64
type: integer
maxLines:
format: int64
type: integer

View File

@@ -1718,6 +1718,9 @@ spec:
properties:
maxAge:
type: string
maxBytes:
format: int64
type: integer
maxLines:
format: int64
type: integer

View File

@@ -1749,6 +1749,9 @@ spec:
properties:
maxAge:
type: string
maxBytes:
format: int64
type: integer
maxLines:
format: int64
type: integer

View File

@@ -12,6 +12,7 @@ spec:
limits:
maxAge: 720h # 30*24
maxLines: 10000
maxBytes: 5000000
- logs:
collectorName: all-logs
name: all-logs

View File

@@ -50,6 +50,7 @@ type LogLimits struct {
MaxAge string `json:"maxAge,omitempty" yaml:"maxAge,omitempty"`
MaxLines int64 `json:"maxLines,omitempty" yaml:"maxLines,omitempty"`
SinceTime metav1.Time `json:"sinceTime,omitempty" yaml:"sinceTime,omitempty"`
MaxBytes int64 `json:"maxBytes,omitempty" yaml:"maxBytes,omitempty"`
}
type Logs struct {

View File

@@ -169,6 +169,7 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
for _, container := range allContainers {
limits := &troubleshootv1beta2.LogLimits{
MaxLines: 500,
MaxBytes: 5000000,
}
podLogs, err := savePodLogs(ctx, c.BundlePath, client, &pod, "", container.Name, limits, false, false)
if err != nil {

View File

@@ -288,6 +288,13 @@ func setLogLimits(podLogOpts *corev1.PodLogOptions, limits *troubleshootv1beta2.
} else {
podLogOpts.TailLines = &limits.MaxLines
}
defaultMaxBytes := int64(5000000)
if limits.MaxBytes == 0 {
podLogOpts.LimitBytes = &defaultMaxBytes
} else {
podLogOpts.LimitBytes = &limits.MaxBytes
}
}
func getLogsErrorsFileName(logsCollector *troubleshootv1beta2.Logs) string {

View File

@@ -7,13 +7,13 @@ import (
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"
)
func Test_setLogLimits(t *testing.T) {
maxBytes := int64(5000000)
defaultMaxLines := int64(10000)
customLines := int64(20)
maxAge := "10h"
@@ -29,6 +29,17 @@ func Test_setLogLimits(t *testing.T) {
expected corev1.PodLogOptions
validate func(t *testing.T, podLogOpts *corev1.PodLogOptions)
}{
{
name: "max bytes",
limits: &troubleshootv1beta2.LogLimits{
MaxBytes: maxBytes,
},
expected: corev1.PodLogOptions{
LimitBytes: &maxBytes,
TailLines: &defaultMaxLines,
},
},
{
name: "default limits",
limits: nil,
@@ -58,23 +69,27 @@ func Test_setLogLimits(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
req := require.New(t)
actual := corev1.PodLogOptions{}
setLogLimits(&actual, test.limits, convertMaxAgeToTime)
if test.expected.LimitBytes != nil {
assert.NotNil(t, actual.LimitBytes)
assert.Equal(t, *test.expected.LimitBytes, *actual.LimitBytes)
}
if test.expected.TailLines != nil {
req.NotNil(actual.TailLines)
assert.NotNil(t, actual.TailLines)
assert.Equal(t, *test.expected.TailLines, *actual.TailLines)
} else {
req.Nil(actual.TailLines)
assert.Nil(t, actual.TailLines)
}
if test.expected.SinceTime != nil {
req.NotNil(actual.SinceTime)
assert.NotNil(t, actual.SinceTime)
assert.Equal(t, *test.expected.SinceTime, *actual.SinceTime)
} else {
req.Nil(actual.SinceTime)
assert.Nil(t, actual.SinceTime)
}
})
}
@@ -141,6 +156,7 @@ func Test_savePodLogs(t *testing.T) {
client := testclient.NewSimpleClientset()
limits := &troubleshootv1beta2.LogLimits{
MaxLines: 500,
MaxBytes: 10000000,
}
pod, err := client.CoreV1().Pods("my-namespace").Create(ctx, &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{

View File

@@ -178,6 +178,7 @@ func runWithoutTimeout(ctx context.Context, bundlePath string, clientConfig *res
limits := troubleshootv1beta2.LogLimits{
MaxLines: 10000,
MaxBytes: 5000000,
}
podLogs, err := savePodLogs(ctx, bundlePath, client, pod, collectorName, "", &limits, true, true)
if err != nil {

View File

@@ -459,6 +459,10 @@
"maxAge": {
"type": "string"
},
"maxBytes": {
"type": "integer",
"format": "int64"
},
"maxLines": {
"type": "integer",
"format": "int64"

View File

@@ -2603,6 +2603,10 @@
"maxAge": {
"type": "string"
},
"maxBytes": {
"type": "integer",
"format": "int64"
},
"maxLines": {
"type": "integer",
"format": "int64"

View File

@@ -2649,6 +2649,10 @@
"maxAge": {
"type": "string"
},
"maxBytes": {
"type": "integer",
"format": "int64"
},
"maxLines": {
"type": "integer",
"format": "int64"