Skip to content

Commit bc34ab4

Browse files
committed
Merge branch 'main' into manage-lifecycle-for-multiple-runner-types
2 parents ed1912d + 1847dcf commit bc34ab4

File tree

8 files changed

+44
-20
lines changed

8 files changed

+44
-20
lines changed

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
.PHONY: audit build lint lintfix fmt fmt-check run test test-verbose test-coverage
2-
3-
check: lint
4-
go fmt ./...
5-
go vet ./...
6-
71
build:
82
go build -o bin cmd/launcher/main.go
93
@echo "Binary built at: $(shell pwd)/bin/main"
104

11-
lint:
12-
golangci-lint run
5+
check: lint
6+
go fmt ./...
7+
go vet ./...
138

149
lintfix:
1510
golangci-lint run --fix
@@ -23,9 +18,15 @@ fmt-check:
2318
exit 1; \
2419
fi
2520

21+
lint:
22+
golangci-lint run
23+
2624
run: build
2725
./bin/main javascript
2826

27+
run-all: build
28+
./bin/main javascript python
29+
2930
test:
3031
go test -race ./...
3132

@@ -36,3 +37,5 @@ test-coverage:
3637
go test -race -coverprofile=coverage.out ./...
3738
go tool cover -html=coverage.out -o coverage.html
3839
open coverage.html
40+
41+
.PHONY: build check lint lintfix fmt fmt-check run run-all test test-verbose test-coverage

internal/commands/launch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (c *LaunchCommand) Execute(launcherConfig *config.LauncherConfig, runnerTyp
4545
// 2. prepare env vars to pass to runner
4646

4747
runnerEnv := env.PrepareRunnerEnv(baseConfig, runnerConfig, c.logger)
48+
runnerServerURI := fmt.Sprintf("http://%s:%s", baseConfig.RunnerHealthCheckServerHost, baseConfig.RunnerHealthCheckServerPort)
4849

4950
for {
5051
// 3. check until task broker is ready
@@ -110,7 +111,7 @@ func (c *LaunchCommand) Execute(launcherConfig *config.LauncherConfig, runnerTyp
110111
return fmt.Errorf("failed to start runner process: %w", err)
111112
}
112113

113-
go http.ManageRunnerHealth(ctx, cmd, env.RunnerServerURI, &wg, c.logger)
114+
go http.ManageRunnerHealth(ctx, cmd, runnerServerURI, &wg, c.logger)
114115

115116
err = cmd.Wait()
116117
if err != nil && err.Error() == "signal: killed" {

internal/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ type BaseConfig struct {
4949
// HealthCheckServerPort is the port for the launcher's health check server.
5050
HealthCheckServerPort string `env:"N8N_RUNNERS_LAUNCHER_HEALTH_CHECK_PORT, default=5680"`
5151

52+
// RunnerHealthCheckServerHost is the host for the runner's health check server.
53+
RunnerHealthCheckServerHost string `env:"N8N_RUNNERS_HEALTH_CHECK_SERVER_HOST, default=127.0.0.1"`
54+
55+
// RunnerHealthCheckServerPort is the port for the runner's health check server.
56+
RunnerHealthCheckServerPort string `env:"N8N_RUNNERS_HEALTH_CHECK_SERVER_PORT, default=5681"`
57+
5258
// Sentry is the Sentry config for the launcher, a subset of what is defined in:
5359
// https://docs.sentry.io/platforms/go/configuration/options/
5460
Sentry *SentryConfig

internal/env/env.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ const (
3131
EnvVarTaskTimeout = "N8N_RUNNERS_TASK_TIMEOUT"
3232
)
3333

34-
const (
35-
// URI of the runner. Used for monitoring the runner's health
36-
// BUG: Harcoded value makes N8N_RUNNERS_HEALTH_CHECK_SERVER_HOST and N8N_RUNNERS_HEALTH_CHECK_SERVER_PORT non-configurable.
37-
RunnerServerURI = "http://127.0.0.1:5681"
38-
)
39-
4034
// partitionByAllowlist divides the current env vars into those included in and
4135
// excluded from the allowlist.
4236
func partitionByAllowlist(allowlist []string) (included, excluded []string) {

internal/http/healthcheck_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const (
1919
// exposing `/healthz` at the given port, running in a goroutine.
2020
func InitHealthCheckServer(port string) {
2121
srv := newHealthCheckServer(port)
22+
logs.Infof("Starting launcher's health check server at port %s", port)
2223
go func() {
23-
logs.Infof("Starting launcher's health check server at port %s", port)
2424
if err := srv.ListenAndServe(); err != nil {
2525
errMsg := "Health check server failed to start"
2626
if opErr, ok := err.(*net.OpError); ok && opErr.Op == "listen" {

internal/logs/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (l *Logger) Infof(msg string, xs ...interface{}) {
116116

117117
func (l *Logger) Warn(msg string) {
118118
if l.level <= WarnLevel {
119-
l.warn.Printf("%sWARN %s%s%s", ColorYellow, l.prefix, msg, ColorReset)
119+
l.warn.Printf("%sWARN %s%s%s", ColorYellow, l.prefix, msg, ColorReset)
120120
}
121121
}
122122

internal/logs/logger_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,22 @@ func TestWarnLogs(t *testing.T) {
130130
level: DebugLevel,
131131
logFunc: Warn,
132132
message: "test warn message",
133-
expectedOutput: "WARN test warn message",
133+
expectedOutput: "WARN test warn message",
134134
shouldLog: true,
135135
},
136136
{
137137
name: "warn level logs warn message",
138138
level: WarnLevel,
139139
logFunc: Warn,
140140
message: "test warn message",
141-
expectedOutput: "WARN test warn message",
141+
expectedOutput: "WARN test warn message",
142142
shouldLog: true,
143143
},
144144
{
145145
name: "error level does not log warn message",
146146
level: ErrorLevel,
147147
logFunc: Warn,
148-
message: "test warn message",
148+
message: "test warn message",
149149
expectedOutput: "",
150150
shouldLog: false,
151151
},

internal/logs/runner_writers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,28 @@ func NewRunnerWriter(w io.Writer, prefix string, level string, color string) *Ru
2626
}
2727
}
2828

29+
var (
30+
shouldLogDebug bool
31+
logLevelChecked bool
32+
)
33+
34+
func initLogLevel() {
35+
if !logLevelChecked {
36+
logLevel := strings.ToUpper(os.Getenv("N8N_RUNNERS_LAUNCHER_LOG_LEVEL"))
37+
shouldLogDebug = logLevel == "DEBUG" || logLevel == ""
38+
logLevelChecked = true
39+
}
40+
}
41+
2942
// Write implements `io.Writer` and adds color, timestamp, level and a prefix to each line.
3043
func (w *RunnerWriter) Write(p []byte) (n int, err error) {
44+
if w.level == "DEBUG" {
45+
initLogLevel()
46+
if !shouldLogDebug {
47+
return len(p), nil
48+
}
49+
}
50+
3151
scanner := bufio.NewScanner(strings.NewReader(string(p)))
3252

3353
for scanner.Scan() {

0 commit comments

Comments
 (0)