diff --git a/config/crds/troubleshoot.sh_collectors.yaml b/config/crds/troubleshoot.sh_collectors.yaml index 146dd71b..d42309fc 100644 --- a/config/crds/troubleshoot.sh_collectors.yaml +++ b/config/crds/troubleshoot.sh_collectors.yaml @@ -326,6 +326,9 @@ spec: properties: maxAge: type: string + maxBytes: + format: int64 + type: integer maxLines: format: int64 type: integer diff --git a/config/crds/troubleshoot.sh_preflights.yaml b/config/crds/troubleshoot.sh_preflights.yaml index 7cfa5c19..d3e96507 100644 --- a/config/crds/troubleshoot.sh_preflights.yaml +++ b/config/crds/troubleshoot.sh_preflights.yaml @@ -1718,6 +1718,9 @@ spec: properties: maxAge: type: string + maxBytes: + format: int64 + type: integer maxLines: format: int64 type: integer diff --git a/config/crds/troubleshoot.sh_supportbundles.yaml b/config/crds/troubleshoot.sh_supportbundles.yaml index db862805..9384a4f7 100644 --- a/config/crds/troubleshoot.sh_supportbundles.yaml +++ b/config/crds/troubleshoot.sh_supportbundles.yaml @@ -1749,6 +1749,9 @@ spec: properties: maxAge: type: string + maxBytes: + format: int64 + type: integer maxLines: format: int64 type: integer diff --git a/examples/support-bundle/sample-supportbundle.yaml b/examples/support-bundle/sample-supportbundle.yaml index 42ecbf9a..3baf560c 100644 --- a/examples/support-bundle/sample-supportbundle.yaml +++ b/examples/support-bundle/sample-supportbundle.yaml @@ -12,6 +12,7 @@ spec: limits: maxAge: 720h # 30*24 maxLines: 10000 + maxBytes: 5000000 - logs: collectorName: all-logs name: all-logs diff --git a/pkg/apis/troubleshoot/v1beta2/collector_shared.go b/pkg/apis/troubleshoot/v1beta2/collector_shared.go index a21a0851..70e63bd8 100644 --- a/pkg/apis/troubleshoot/v1beta2/collector_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/collector_shared.go @@ -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 { diff --git a/pkg/collect/cluster_resources.go b/pkg/collect/cluster_resources.go index 03f91d50..25faf625 100644 --- a/pkg/collect/cluster_resources.go +++ b/pkg/collect/cluster_resources.go @@ -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 { diff --git a/pkg/collect/logs.go b/pkg/collect/logs.go index 30441654..c0d0595c 100644 --- a/pkg/collect/logs.go +++ b/pkg/collect/logs.go @@ -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 { diff --git a/pkg/collect/logs_test.go b/pkg/collect/logs_test.go index a9132ef4..510b630a 100644 --- a/pkg/collect/logs_test.go +++ b/pkg/collect/logs_test.go @@ -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{ diff --git a/pkg/collect/run_pod.go b/pkg/collect/run_pod.go index 9d270911..37c3308d 100644 --- a/pkg/collect/run_pod.go +++ b/pkg/collect/run_pod.go @@ -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 { diff --git a/schemas/collector-troubleshoot-v1beta2.json b/schemas/collector-troubleshoot-v1beta2.json index 444ffdef..4c33fe76 100644 --- a/schemas/collector-troubleshoot-v1beta2.json +++ b/schemas/collector-troubleshoot-v1beta2.json @@ -459,6 +459,10 @@ "maxAge": { "type": "string" }, + "maxBytes": { + "type": "integer", + "format": "int64" + }, "maxLines": { "type": "integer", "format": "int64" diff --git a/schemas/preflight-troubleshoot-v1beta2.json b/schemas/preflight-troubleshoot-v1beta2.json index b0637f2c..a58213b3 100644 --- a/schemas/preflight-troubleshoot-v1beta2.json +++ b/schemas/preflight-troubleshoot-v1beta2.json @@ -2603,6 +2603,10 @@ "maxAge": { "type": "string" }, + "maxBytes": { + "type": "integer", + "format": "int64" + }, "maxLines": { "type": "integer", "format": "int64" diff --git a/schemas/supportbundle-troubleshoot-v1beta2.json b/schemas/supportbundle-troubleshoot-v1beta2.json index c8718dc8..3fd69d3b 100644 --- a/schemas/supportbundle-troubleshoot-v1beta2.json +++ b/schemas/supportbundle-troubleshoot-v1beta2.json @@ -2649,6 +2649,10 @@ "maxAge": { "type": "string" }, + "maxBytes": { + "type": "integer", + "format": "int64" + }, "maxLines": { "type": "integer", "format": "int64"