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 diff --git a/README.md b/README.md index 86499da..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 | @@ -18,6 +22,7 @@ | `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. | 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")