From cec4dd3ae872cecfaf9b2dd43008e24d77237549 Mon Sep 17 00:00:00 2001 From: theteacat Date: Fri, 16 May 2025 10:50:13 +0100 Subject: [PATCH 1/4] Implement shutdown timeout --- src/main.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.go b/src/main.go index c77dab4..0bdd052 100644 --- a/src/main.go +++ b/src/main.go @@ -15,6 +15,28 @@ import ( ) func main() { + maxLifetimeMinutes, err := strconv.Atoi(os.Getenv("FIRETAIL_KUBERNETES_SENSOR_LIFETIME_MINUTES")) + if err != nil { + slog.Warn( + "FIRETAIL_KUBERNETES_SENSOR_LIFETIME_MINUTES environment variable not set. " + + "This sensor will shutdown in 15 minutes.", + ) + maxLifetimeMinutes = 15 + } else { + if maxLifetimeMinutes > 0 { + slog.Warn("This sensor will shutdown in " + strconv.Itoa(maxLifetimeMinutes) + " minute(s).") + } else { + slog.Warn("Shutdown timeout disabled. This sensor will run indefinitely.") + } + } + if maxLifetimeMinutes > 0 { + go func() { + time.Sleep(time.Minute * time.Duration(maxLifetimeMinutes)) + slog.Warn("Timeout reached. Shutting down the sensor...") + os.Exit(0) + }() + } + logsApiToken, logsApiTokenSet := os.LookupEnv("FIRETAIL_API_TOKEN") if !logsApiTokenSet { log.Fatal("FIRETAIL_API_TOKEN environment variable not set") From c8bfe46123034d7ef15def096136a8a1dcf0cc64 Mon Sep 17 00:00:00 2001 From: theteacat Date: Fri, 16 May 2025 10:50:23 +0100 Subject: [PATCH 2/4] update makefile dev target to disable shutdown timeout --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index cd232dd..354b166 100644 --- a/Makefile +++ b/Makefile @@ -24,4 +24,5 @@ dev: build-dev -e FIRETAIL_KUBERNETES_SENSOR_DEV_SERVER_ENABLED=true \ -e DISABLE_SERVICE_IP_FILTERING=true \ -e ENABLE_ONLY_LOG_JSON=true \ + -e FIRETAIL_KUBERNETES_SENSOR_LIFETIME_MINUTES=0 \ firetail/kubernetes-sensor-dev From 7a0a2fbf901076b81c5c3ca9da4c8588699d260e Mon Sep 17 00:00:00 2001 From: theteacat Date: Fri, 16 May 2025 10:50:32 +0100 Subject: [PATCH 3/4] add FIRETAIL_KUBERNETES_SENSOR_LIFETIME_MINUTES to docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f7566be..b68638a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ POC for a FireTail Kubernetes Sensor. | `ENABLE_ONLY_LOG_JSON` | ❌ | `true` | Enables only logging requests where the content-type implies the payload should be JSON, or the payload is valid JSON regardless of the content-type. | | `DISABLE_SERVICE_IP_FILTERING` | ❌ | `true` | Disables polling Kubernetes for the IP addresses of services & subsequently ignoring all requests captured that aren't made to one of those IPs. | | `FIRETAIL_API_URL` | ❌ | `https://api.logging.eu-west-1.prod.firetail.app/logs/bulk` | The API url the sensor will send logs to. Defaults to the EU region production environment. | +| `FIRETAIL_KUBERNETES_SENSOR_LIFETIME_MINUTES` | ❌ | `15` | The maximum lifetime of the FireTail kubernetes sensor in minutes. Must be an integer. Values <=0 will disable the shutdown timer. | | `FIRETAIL_KUBERNETES_SENSOR_DEV_MODE` | ❌ | `true` | Enables debug logging when set to `true`, and reduces the max age of a log in a batch to be sent to FireTail. | | `FIRETAIL_KUBERNETES_SENSOR_DEV_SERVER_ENABLED` | ❌ | `true` | Enables a demo web server when set to `true`; useful for sending test requests to. | From 202713b8efb0f2ba96d5ac14f4d634c7aea6e884 Mon Sep 17 00:00:00 2001 From: theteacat Date: Fri, 16 May 2025 10:53:08 +0100 Subject: [PATCH 4/4] tidy doc --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 213fb0d..ad9183c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Firetail Kubernetes Sensor + + ## Deployment - Create an API & API Key on the FireTail Platform @@ -8,6 +10,8 @@ - ```git clone https://github.com/FireTail-io/firetail-kubernetes-sensor.git``` - deploy helm chart ```cd helm && helm install firetail-sensor firetail-sensor/ --set apiKey="PS-02-XXXXXXXX"``` + + ## Environment Variables | Variable Name | Required? | Example | Description |