From c988876a9d4cc22b4bf0d093e32932e41b2245aa Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:10:07 +0200 Subject: [PATCH] refactor: Unify task runner env vars - Rename `N8N_TASK_BROKER_URI` to `N8N_RUNNERS_TASK_BROKER_URI` - Rename `N8N_RUNNERS_SERVER_ENABLED` to `N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED` --- docs/setup.md | 4 ++-- internal/config/config.go | 4 ++-- internal/config/config_test.go | 24 ++++++++++++------------ internal/env/env.go | 2 +- internal/env/env_test.go | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/setup.md b/docs/setup.md index 6be31cf..73cb162 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -20,7 +20,7 @@ This launcher is intended for deployment as a sidecar container alongside one or "PATH", "GENERIC_TIMEZONE", "N8N_RUNNERS_GRANT_TOKEN", - "N8N_RUNNERS_N8N_URI", + "N8N_RUNNERS_TASK_BROKER_URI", "N8N_RUNNERS_MAX_PAYLOAD", "N8N_RUNNERS_MAX_CONCURRENCY", "NODE_FUNCTION_ALLOW_BUILTIN", @@ -48,7 +48,7 @@ Task runner config fields: - Optionally, specify the launcher's auto-shutdown timeout by setting `N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT` to a number of seconds, or set it to `0` to disable. Default is `15`. The runner will exit after this timeout if it is idle for the specified duration, and will be re-launched on demand when the next task comes in. -- Optionally, specify the task broker's URI (i.e. n8n instance's URI) by setting `N8N_TASK_BROKER_URI`. Default is `http://127.0.0.1:5679`. +- Optionally, specify the task broker's URI (i.e. n8n instance's URI) by setting `N8N_RUNNERS_TASK_BROKER_URI`. Default is `http://127.0.0.1:5679`. - Optionally, specify the port for the launcher's health check server by setting `N8N_LAUNCHER_HEALTH_CHECK_PORT`. Default is `5680`. When overriding this port, be mindful of port conflicts - by default, the n8n instance uses `5678` for its regular server and `5679` for its task broker server, and the runner uses `5681` for its healthcheck server. diff --git a/internal/config/config.go b/internal/config/config.go index 067a8e0..5abf382 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -36,7 +36,7 @@ type Config struct { AutoShutdownTimeout string `env:"N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT, default=15"` // TaskBrokerURI is the URI of the task broker server. - TaskBrokerURI string `env:"N8N_TASK_BROKER_URI, default=http://127.0.0.1:5679"` + TaskBrokerURI string `env:"N8N_RUNNERS_TASK_BROKER_URI, default=http://127.0.0.1:5679"` // HealthCheckServerPort is the port for the launcher's health check server. HealthCheckServerPort string `env:"N8N_LAUNCHER_HEALTH_CHECK_PORT, default=5680"` @@ -89,7 +89,7 @@ func LoadConfig(runnerType string, lookuper envconfig.Lookuper) (*Config, error) // launcher - if err := validateURL(cfg.TaskBrokerURI, "N8N_TASK_BROKER_URI"); err != nil { + if err := validateURL(cfg.TaskBrokerURI, "N8N_RUNNERS_TASK_BROKER_URI"); err != nil { cfgErrs = append(cfgErrs, err) } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index ec4461f..092def1 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -35,9 +35,9 @@ func TestLoadConfig(t *testing.T) { name: "valid configuration", configContent: validConfigContent, envVars: map[string]string{ - "N8N_RUNNERS_AUTH_TOKEN": "test-token", - "N8N_TASK_BROKER_URI": "http://localhost:5679", - "SENTRY_DSN": "https://test@sentry.io/123", + "N8N_RUNNERS_AUTH_TOKEN": "test-token", + "N8N_RUNNERS_TASK_BROKER_URI": "http://localhost:5679", + "SENTRY_DSN": "https://test@sentry.io/123", }, runnerType: "javascript", expectedError: false, @@ -46,9 +46,9 @@ func TestLoadConfig(t *testing.T) { name: "valid configuration", configContent: validConfigContent, envVars: map[string]string{ - "N8N_RUNNERS_AUTH_TOKEN": "test-token", - "N8N_TASK_BROKER_URI": "http://127.0.0.1:5679", - "SENTRY_DSN": "https://test@sentry.io/123", + "N8N_RUNNERS_AUTH_TOKEN": "test-token", + "N8N_RUNNERS_TASK_BROKER_URI": "http://127.0.0.1:5679", + "SENTRY_DSN": "https://test@sentry.io/123", }, runnerType: "javascript", expectedError: false, @@ -92,8 +92,8 @@ func TestConfigFileErrors(t *testing.T) { configContent: "invalid json", expectedError: "failed to parse config file", envVars: map[string]string{ - "N8N_RUNNERS_AUTH_TOKEN": "test-token", - "N8N_TASK_BROKER_URI": "http://localhost:5679", + "N8N_RUNNERS_AUTH_TOKEN": "test-token", + "N8N_RUNNERS_TASK_BROKER_URI": "http://localhost:5679", }, }, { @@ -103,8 +103,8 @@ func TestConfigFileErrors(t *testing.T) { }`, expectedError: "found no task runner configs", envVars: map[string]string{ - "N8N_RUNNERS_AUTH_TOKEN": "test-token", - "N8N_TASK_BROKER_URI": "http://localhost:5679", + "N8N_RUNNERS_AUTH_TOKEN": "test-token", + "N8N_RUNNERS_TASK_BROKER_URI": "http://localhost:5679", }, }, { @@ -120,8 +120,8 @@ func TestConfigFileErrors(t *testing.T) { }`, expectedError: "does not contain requested runner type: javascript", envVars: map[string]string{ - "N8N_RUNNERS_AUTH_TOKEN": "test-token", - "N8N_TASK_BROKER_URI": "http://localhost:5679", + "N8N_RUNNERS_AUTH_TOKEN": "test-token", + "N8N_RUNNERS_TASK_BROKER_URI": "http://localhost:5679", }, }, } diff --git a/internal/env/env.go b/internal/env/env.go index a8ad19c..20c980a 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -78,7 +78,7 @@ func PrepareRunnerEnv(cfg *config.Config) []string { allowedEnvs := append(defaultEnvs, cfg.Runner.AllowedEnv...) runnerEnv := allowedOnly(allowedEnvs) - runnerEnv = append(runnerEnv, "N8N_RUNNERS_SERVER_ENABLED=true") + runnerEnv = append(runnerEnv, "N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED=true") runnerEnv = append(runnerEnv, fmt.Sprintf("%s=%s", EnvVarAutoShutdownTimeout, cfg.AutoShutdownTimeout)) return runnerEnv diff --git a/internal/env/env_test.go b/internal/env/env_test.go index 66fab2f..e57bc76 100644 --- a/internal/env/env_test.go +++ b/internal/env/env_test.go @@ -176,7 +176,7 @@ func TestPrepareRunnerEnv(t *testing.T) { "CUSTOM_VAR2=value2", "LANG=en_US.UTF-8", "N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT=15", - "N8N_RUNNERS_SERVER_ENABLED=true", + "N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED=true", "PATH=/usr/bin", "TERM=xterm", "TZ=UTC", @@ -198,7 +198,7 @@ func TestPrepareRunnerEnv(t *testing.T) { expected: []string{ "LANG=en_US.UTF-8", "N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT=15", - "N8N_RUNNERS_SERVER_ENABLED=true", + "N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED=true", "PATH=/usr/bin", }, }, @@ -216,7 +216,7 @@ func TestPrepareRunnerEnv(t *testing.T) { }, expected: []string{ "N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT=30", - "N8N_RUNNERS_SERVER_ENABLED=true", + "N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED=true", "PATH=/usr/bin", }, },