Skip to content

feat: add pprof and prometheus metrics to coder server #1266

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2022
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
fixup! rename flags
  • Loading branch information
coadler committed May 2, 2022
commit dca1216a89c3caac26a85739b3f413c276fe7dd2
8 changes: 5 additions & 3 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ func server() *cobra.Command {
// This prevents the pprof import from being accidentally deleted.
var _ = pprof.Handler
if pprofEnabled {
//nolint:revive
defer serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")()
}
if promEnabled {
//nolint:revive
defer serveHandler(cmd.Context(), logger, promhttp.Handler(), promAddress, "prometheus")()
}

Expand Down Expand Up @@ -680,14 +682,14 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
}, nil
}

func serveHandler(ctx context.Context, log slog.Logger, handler http.Handler, addr, name string) (closeFunc func()) {
log.Debug(ctx, "http server listening", slog.F("addr", addr), slog.F("name", name))
func serveHandler(ctx context.Context, logger slog.Logger, handler http.Handler, addr, name string) (closeFunc func()) {
logger.Debug(ctx, "http server listening", slog.F("addr", addr), slog.F("name", name))

srv := &http.Server{Addr: addr, Handler: handler}
go func() {
err := srv.ListenAndServe()
if err != nil && !xerrors.Is(err, http.ErrServerClosed) {
log.Error(ctx, "http server listen", slog.F("name", name), slog.Error(err))
logger.Error(ctx, "http server listen", slog.F("name", name), slog.Error(err))
}
}()

Expand Down