Skip to content

Commit cf7541f

Browse files
committed
chore: add more logs for the worker
1 parent 2549106 commit cf7541f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

threadregular.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (handler *regularThread) beforeScriptExecution() string {
4646
panic("unexpected state: " + handler.state.name())
4747
}
4848

49-
// return true if the worker should continue to run
5049
func (handler *regularThread) afterScriptExecution(int) {
5150
handler.afterRequest()
5251
}

threadworker.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,30 @@ func tearDownWorkerScript(handler *workerThread, exitStatus int) {
119119
// TODO: make the max restart configurable
120120
metrics.StopWorker(worker.name, StopReasonRestart)
121121
handler.backoff.recordSuccess()
122-
logger.LogAttrs(ctx, slog.LevelDebug, "restarting", slog.String("worker", worker.name))
122+
logger.LogAttrs(ctx, slog.LevelDebug, "restarting", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex), slog.Int("exit_status", exitStatus))
123+
123124
return
124125
}
125126

126127
// worker has thrown a fatal error or has not reached frankenphp_handle_request
127128
metrics.StopWorker(worker.name, StopReasonCrash)
128129

129130
if !handler.isBootingScript {
130-
// fatal error (could be due to timeouts, etc.)
131+
// fatal error (could be due to exit(1), timeouts, etc.)
132+
logger.LogAttrs(ctx, slog.LevelDebug, "restarting", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex), slog.Int("exit_status", exitStatus))
133+
131134
return
132135
}
133136

134-
logger.LogAttrs(ctx, slog.LevelError, "worker script has not reached frankenphp_handle_request", slog.String("worker", worker.name))
137+
logger.LogAttrs(ctx, slog.LevelError, "worker script has not reached frankenphp_handle_request()", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex))
135138

136139
// panic after exponential backoff if the worker has never reached frankenphp_handle_request
137140
if handler.backoff.recordFailure() {
138141
if !watcherIsEnabled && !handler.state.is(stateReady) {
139-
logger.LogAttrs(ctx, slog.LevelError, "too many consecutive worker failures", slog.String("worker", worker.name), slog.Int("failures", handler.backoff.failureCount))
142+
logger.LogAttrs(ctx, slog.LevelError, "too many consecutive worker failures", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex), slog.Int("failures", handler.backoff.failureCount))
140143
panic("too many consecutive worker failures")
141144
}
142-
logger.LogAttrs(ctx, slog.LevelWarn, "many consecutive worker failures", slog.String("worker", worker.name), slog.Int("failures", handler.backoff.failureCount))
145+
logger.LogAttrs(ctx, slog.LevelWarn, "many consecutive worker failures", slog.String("worker", worker.name), slog.Int("thread", handler.thread.threadIndex), slog.Int("failures", handler.backoff.failureCount))
143146
}
144147
}
145148

@@ -149,7 +152,7 @@ func (handler *workerThread) waitForWorkerRequest() bool {
149152
handler.thread.Unpin()
150153

151154
ctx := context.Background()
152-
logger.LogAttrs(ctx, slog.LevelDebug, "waiting for request", slog.String("worker", handler.worker.name))
155+
logger.LogAttrs(ctx, slog.LevelDebug, "waiting for request", slog.String("worker", handler.worker.name), slog.Int("thread", handler.thread.threadIndex))
153156

154157
// Clear the first dummy request created to initialize the worker
155158
if handler.isBootingScript {
@@ -172,7 +175,7 @@ func (handler *workerThread) waitForWorkerRequest() bool {
172175
var fc *frankenPHPContext
173176
select {
174177
case <-handler.thread.drainChan:
175-
logger.LogAttrs(ctx, slog.LevelDebug, "shutting down", slog.String("worker", handler.worker.name))
178+
logger.LogAttrs(ctx, slog.LevelDebug, "shutting down", slog.String("worker", handler.worker.name), slog.Int("thread", handler.thread.threadIndex))
176179

177180
// flush the opcache when restarting due to watcher or admin api
178181
// note: this is done right before frankenphp_handle_request() returns 'false'
@@ -188,11 +191,11 @@ func (handler *workerThread) waitForWorkerRequest() bool {
188191
handler.workerContext = fc
189192
handler.state.markAsWaiting(false)
190193

191-
logger.LogAttrs(ctx, slog.LevelDebug, "request handling started", slog.String("worker", handler.worker.name), slog.String("url", fc.request.RequestURI))
194+
logger.LogAttrs(ctx, slog.LevelDebug, "request handling started", slog.String("worker", handler.worker.name), slog.Int("thread", handler.thread.threadIndex), slog.String("url", fc.request.RequestURI))
192195

193196
if err := updateServerContext(handler.thread, fc, true); err != nil {
194197
// Unexpected error or invalid request
195-
logger.LogAttrs(ctx, slog.LevelDebug, "unexpected error", slog.String("worker", handler.worker.name), slog.String("url", fc.request.RequestURI), slog.Any("error", err))
198+
logger.LogAttrs(ctx, slog.LevelDebug, "unexpected error", slog.String("worker", handler.worker.name), slog.Int("thread", handler.thread.threadIndex), slog.String("url", fc.request.RequestURI), slog.Any("error", err))
196199
fc.rejectBadRequest(err.Error())
197200
handler.workerContext = nil
198201

0 commit comments

Comments
 (0)