From cd516533ae1322f9d7cb9c6c745f1b048e2be430 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 20 Aug 2024 15:32:17 +0200 Subject: [PATCH] Add watcher option logs_timestamps to store taskrun logs with timestamps --- cmd/api/README.md | 1 + cmd/watcher/main.go | 2 ++ config/base/env/config | 1 + pkg/api/server/config/config.go | 1 + pkg/watcher/reconciler/config.go | 3 +++ pkg/watcher/reconciler/dynamic/dynamic.go | 1 + 6 files changed, 9 insertions(+) diff --git a/cmd/api/README.md b/cmd/api/README.md index 621d4cd79..1f32029ba 100644 --- a/cmd/api/README.md +++ b/cmd/api/README.md @@ -29,6 +29,7 @@ | LOGS_TYPE | Determine Logs storage backend type | File (default) | | LOGS_BUFFER_SIZE | Buffer for streaming logs | 32768 (default) | | LOGS_PATH | Logs storage path | logs (default) | +| LOGS_TIMESTAMPS | Collect logs with timestamps | false (default) | | S3_BUCKET_NAME | S3 Bucket name | | | S3_ENDPOINT | S3 Endpoint | https://s3.ap-south-1.amazonaws.com | | S3_HOSTNAME_IMMUTABLE | S3 Hostname immutable | false (default) | diff --git a/cmd/watcher/main.go b/cmd/watcher/main.go index e5cab9151..879d49d4e 100644 --- a/cmd/watcher/main.go +++ b/cmd/watcher/main.go @@ -66,6 +66,7 @@ var ( qps = flag.Float64("qps", float64(rest.DefaultQPS), "Kubernetes client QPS setting") burst = flag.Int("burst", rest.DefaultBurst, "Kubernetes client Burst setting") logsAPI = flag.Bool("logs_api", false, "Disable sending logs. If not set, the logs will be sent only if server support API for it") + logsTimestamps = flag.Bool("logs_timestamps", false, "Collect logs with timestamps") labelSelector = flag.String("label_selector", "", "Selector (label query) to filter objects to be deleted. Matching objects must satisfy all labels requirements to be eligible for deletion") requeueInterval = flag.Duration("requeue_interval", 10*time.Minute, "How long the Watcher waits to reprocess keys on certain events (e.g. an object doesn't match the provided selectors)") namespace = flag.String("namespace", corev1.NamespaceAll, "Should the Watcher only watch a single namespace, then this value needs to be set to the namespace name otherwise leave it empty.") @@ -114,6 +115,7 @@ func main() { StoreEvent: *storeEvent, StoreDeadline: storeDeadline, ForwardBuffer: forwardBuffer, + LogsTimestamps: *logsTimestamps, } log.Printf("dynamic reconcile timeout %s and update log timeout is %s", cfg.DynamicReconcileTimeout.String(), cfg.UpdateLogTimeout.String()) diff --git a/config/base/env/config b/config/base/env/config index bebca8364..531e042c7 100644 --- a/config/base/env/config +++ b/config/base/env/config @@ -24,6 +24,7 @@ LOGS_API=false LOGS_TYPE=File LOGS_BUFFER_SIZE=32768 LOGS_PATH=/logs +LOGS_TIMESTAMPS=false S3_BUCKET_NAME= S3_ENDPOINT= S3_HOSTNAME_IMMUTABLE=false diff --git a/pkg/api/server/config/config.go b/pkg/api/server/config/config.go index c9bc4bf32..c8d0d95f5 100644 --- a/pkg/api/server/config/config.go +++ b/pkg/api/server/config/config.go @@ -34,6 +34,7 @@ type Config struct { LOGS_TYPE string `mapstructure:"LOGS_TYPE"` LOGS_BUFFER_SIZE int `mapstructure:"LOGS_BUFFER_SIZE"` LOGS_PATH string `mapstructure:"LOGS_PATH"` + LOGS_TIMESTAMPS bool `mapstructure:"LOGS_TIMESTAMPS"` PROFILING bool `mapstructure:"PROFILING"` PROFILING_PORT string `mapstructure:"PROFILING_PORT"` diff --git a/pkg/watcher/reconciler/config.go b/pkg/watcher/reconciler/config.go index 2558b3270..c908075ee 100644 --- a/pkg/watcher/reconciler/config.go +++ b/pkg/watcher/reconciler/config.go @@ -59,6 +59,9 @@ type Config struct { // by a forwarder. Since there's no way to check if log has been streamed, we // always wait for this much amount of duration ForwardBuffer *time.Duration + + // Collect logs with timestamps + LogsTimestamps bool } // GetDisableAnnotationUpdate returns whether annotation updates should be diff --git a/pkg/watcher/reconciler/dynamic/dynamic.go b/pkg/watcher/reconciler/dynamic/dynamic.go index e66187107..b093a217a 100644 --- a/pkg/watcher/reconciler/dynamic/dynamic.go +++ b/pkg/watcher/reconciler/dynamic/dynamic.go @@ -520,6 +520,7 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType, Params: tknParams, PipelineRunName: o.GetName(), TaskrunName: o.GetName(), + Timestamps: r.cfg.LogsTimestamps, Stream: &cli.Stream{ Out: inMemWriteBufferStdout, Err: inMemWriteBufferStderr,