Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: log long-lived connections acceptance#17219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
40 commits
Select commitHold shift + click to select a range
0e397ed
initial implementation of RequestLoggerContext and example usage in P…
ibetitsmikeApr 2, 2025
c384706
fix empty RequestLoggerContext
ibetitsmikeApr 2, 2025
686f4db
referenced httplog while creating RequestLoggerContext
ibetitsmikeApr 2, 2025
7edb8c3
refactored fields extension on the logger
ibetitsmikeApr 2, 2025
5feb4e4
fixed log formatting
ibetitsmikeApr 2, 2025
7500ef5
typo comment fix
ibetitsmikeApr 2, 2025
66e2c3e
added logging to long lived connection opening functions
ibetitsmikeApr 2, 2025
4e5f36e
added logging to other places
ibetitsmikeApr 2, 2025
b7822b3
updated comments
ibetitsmikeApr 3, 2025
a772430
renamed context fetcher
ibetitsmikeApr 3, 2025
2a1dbe3
refactored logging in the logger middleware and added tests for logger
ibetitsmikeApr 3, 2025
5a0fa05
removed unecessary helpers
ibetitsmikeApr 3, 2025
30bb53d
added test for an http request
ibetitsmikeApr 3, 2025
89e987e
linting fixes
ibetitsmikeApr 3, 2025
1649116
added handling of internal test circumventing RequestLoggerContext in…
ibetitsmikeApr 3, 2025
7ea2dd6
reverted the original behavior of logging WARN on Status Code >=500
ibetitsmikeApr 3, 2025
338fd20
refactored logger to remove extending it with fields permanently
ibetitsmikeApr 4, 2025
2708286
Removed nil checks when fetching RequestLogger
ibetitsmikeApr 6, 2025
ca3c4d3
refactored tests to use a fakesink to verify the written messages
ibetitsmikeApr 6, 2025
dfa2f4f
added WebSocket test to verify early logging
ibetitsmikeApr 6, 2025
845ff0f
fix lint for response body leak
ibetitsmikeApr 6, 2025
1f7acfb
reverted bodyclose lint fix
ibetitsmikeApr 6, 2025
58aa736
fix for race condition in the test
ibetitsmikeApr 6, 2025
2c63b32
linter fixes
ibetitsmikeApr 6, 2025
d268a3c
actually added logging early to test early logging
ibetitsmikeApr 7, 2025
8f550c5
added a WaitGroup in logger internal tests to remove the race condition
ibetitsmikeApr 7, 2025
81e1527
refactor after code review
ibetitsmikeApr 7, 2025
b9e2b61
added checking the logger fields in the test
ibetitsmikeApr 7, 2025
deb1a41
refactored mock request logger to fit current codebase
ibetitsmikeApr 7, 2025
09e46d0
added mocked files to Makefile
ibetitsmikeApr 7, 2025
9b16cf9
format fix
ibetitsmikeApr 7, 2025
2e331a3
fixed path in Makefile
ibetitsmikeApr 7, 2025
7e9f083
fixed Makefile path
ibetitsmikeApr 7, 2025
b82776f
fixed nested path in Makefile
ibetitsmikeApr 7, 2025
3d44727
Merge branch 'main' into mike/16904-request-logging-on-long-lived-con…
ibetitsmikeApr 8, 2025
cb118a9
added additional checks
ibetitsmikeApr 8, 2025
754cee6
refactored the WebSocket test to actually read and close the connection
ibetitsmikeApr 8, 2025
d28f2bd
Merge branch 'main' into mike/16904-request-logging-on-long-lived-con…
ibetitsmikeApr 8, 2025
57a49d5
Merge branch 'main' into mike/16904-request-logging-on-long-lived-con…
ibetitsmikeApr 8, 2025
cb130de
Merge branch 'main' into mike/16904-request-logging-on-long-lived-con…
ibetitsmikeApr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
initial implementation of RequestLoggerContext and example usage in P…
…rovisionerJobs logs
  • Loading branch information
@ibetitsmike
ibetitsmike committedApr 7, 2025
commit0e397edf6197b7650c3f25a303a61b5d916924ce
43 changes: 42 additions & 1 deletioncoderd/httpmw/logger.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,14 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
slog.F("start", start),
)

next.ServeHTTP(sw, r)
logContext := &RequestLoggerContext{}
defer func() {
logContext.WriteLog(r.Context(), "", sw.Status)
}()

ctx := context.WithValue(r.Context(), logContextKey{}, logContext)

next.ServeHTTP(sw, r.WithContext(ctx))

end := time.Now()

Expand DownExpand Up@@ -74,3 +81,37 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
})
}
}

type RequestLoggerContext struct {
Fields map[string]any

log *slog.Logger
written bool
}

func (c *RequestLoggerContext) WriteLog(ctx context.Context, msg string, status int) {
if c.written {
return
}
c.written = true
// append extra fields to the logger
for k, v := range c.Fields {
c.log.With(slog.F(k, v))
}

if status >= http.StatusInternalServerError {
c.log.Error(ctx, msg)
} else {
c.log.Debug(ctx, msg)
}
}

type logContextKey struct{}

func FromContext(ctx context.Context) *RequestLoggerContext {
val := ctx.Value(logContextKey{})
if logCtx, ok := val.(*RequestLoggerContext); ok {
return logCtx
}
return nil
}
4 changes: 4 additions & 0 deletionscoderd/provisionerjobs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -554,6 +554,10 @@ func (f *logFollower) follow() {
return
}

// write the initial logs to the connection
httpmw.FromContext(f.ctx).WriteLog(
f.ctx, "ProvisionerJobs log follower WS connection established", http.StatusAccepted)

// no need to wait if the job is done
if f.complete {
return
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp