Skip to content

add env var to start pprof server#2488

Merged
sawka merged 2 commits intomainfrom
sawka/pprof
Oct 28, 2025
Merged

add env var to start pprof server#2488
sawka merged 2 commits intomainfrom
sawka/pprof

Conversation

@sawka
Copy link
Copy Markdown
Member

@sawka sawka commented Oct 28, 2025

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 28, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds pprof profiling support to the server. Introduces maybeStartPprofServer, which reads WAVETERM_PPROFPORT, validates it as a port number, and, if set and valid, starts an HTTP pprof server bound to localhost:<port> in a new goroutine. main calls maybeStartPprofServer early in startup and returns on error. Adds imports for strconv, net/http, and a side-effect import net/http/pprof.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Port parsing and validation logic
  • Error handling in main around pprof startup
  • Goroutine startup and logging messages

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "add env var to start pprof server" accurately and clearly describes the primary change in the changeset. According to the summary, the PR adds pprof profiling support by introducing a function that reads the WAVETERM_PPROFPORT environment variable and starts a pprof HTTP server. The title is concise, specific, and directly reflects this main objective without being vague or misleading.
Description Check ✅ Passed No pull request description was provided by the author. However, since this check is explicitly very lenient and only requires that the description not be completely off-topic, the absence of a description does not violate this criterion. An empty description is not "completely unrelated" or "off-topic" to the changeset; it is simply absent.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 452a9f1 and 26e24a9.

📒 Files selected for processing (1)
  • cmd/server/main-server.go (3 hunks)

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: unknown linters: 'unusedfunc,unusedparams', run 'golangci-lint help linters' to see the list of supported linters
The command is terminated due to an error: unknown linters: 'unusedfunc,unusedparams', run 'golangci-lint help linters' to see the list of supported linters


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/server/main-server.go (1)

322-342: Consider cleaning up the environment variable for consistency.

The implementation is sound for a debugging feature. The port validation, localhost binding, and error logging are appropriate. Note that http.ListenAndServe errors occur asynchronously in the goroutine, so users won't receive immediate feedback if the server fails to bind (e.g., port already in use).

For consistency with lines 300-306 where other WAVETERM_* environment variables are removed, consider unsetting WAVETERM_PPROFPORT after reading it:

func maybeStartPprofServer() error {
	pprofPortStr := os.Getenv("WAVETERM_PPROFPORT")
	if pprofPortStr == "" {
		return nil
	}
+	defer os.Unsetenv("WAVETERM_PPROFPORT")
	pprofPort, err := strconv.Atoi(pprofPortStr)
	if err != nil {
		return fmt.Errorf("invalid WAVETERM_PPROFPORT value '%s': %v", pprofPortStr, err)
	}
	if pprofPort < 1 || pprofPort > 65535 {
		return fmt.Errorf("WAVETERM_PPROFPORT must be between 1 and 65535, got %d", pprofPort)
	}
	go func() {
		addr := fmt.Sprintf("localhost:%d", pprofPort)
		log.Printf("starting pprof server on %s\n", addr)
		if err := http.ListenAndServe(addr, nil); err != nil {
			log.Printf("[error] pprof server failed: %v\n", err)
		}
	}()
	return nil
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba573c4 and 452a9f1.

📒 Files selected for processing (1)
  • cmd/server/main-server.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (2)
cmd/server/main-server.go (2)

11-11: LGTM! Imports are correct.

The added imports are appropriate for the pprof functionality: strconv for port parsing, net/http for the server, and net/http/pprof for side effects to register profiling endpoints.

Also applies to: 44-46


345-349: LGTM! Early initialization and error handling are appropriate.

The pprof server is started early in the startup sequence with proper error handling. The change on line 356 to reuse the err variable (using = instead of :=) is good practice to avoid shadowing.

Also applies to: 356-356

@sawka sawka merged commit 5d4fa5b into main Oct 28, 2025
5 of 7 checks passed
@sawka sawka deleted the sawka/pprof branch October 28, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant