-
Notifications
You must be signed in to change notification settings - Fork 41
NO-ISSUE: Add opt-in pprof endpoint to machine-controller-manager #189
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
openshift-merge-bot
merged 1 commit into
openshift:main
from
perdasilva:fix/pprof-endpoints
Jun 23, 2026
+170
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net" | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestPprofServerResponds(t *testing.T) { | ||
| listener, err := net.Listen("tcp", "127.0.0.1:0") | ||
| if err != nil { | ||
| t.Fatalf("failed to listen: %v", err) | ||
| } | ||
| addr := listener.Addr().String() | ||
| listener.Close() | ||
|
perdasilva marked this conversation as resolved.
|
||
|
|
||
| srv := &pprofServer{ | ||
| Addr: addr, | ||
| } | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| errCh := make(chan error, 1) | ||
| go func() { | ||
| errCh <- srv.Start(ctx) | ||
| }() | ||
|
|
||
| var resp *http.Response | ||
| for i := 0; i < 20; i++ { | ||
| resp, err = http.Get(fmt.Sprintf("http://%s/debug/pprof/", addr)) | ||
| if err == nil { | ||
| break | ||
| } | ||
| time.Sleep(50 * time.Millisecond) | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("pprof server did not respond: %v", err) | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode != http.StatusOK { | ||
| t.Errorf("expected status 200, got %d", resp.StatusCode) | ||
| } | ||
|
|
||
| cancel() | ||
| select { | ||
| case err := <-errCh: | ||
| if err != nil { | ||
| t.Errorf("server returned error on shutdown: %v", err) | ||
| } | ||
| case <-time.After(10 * time.Second): | ||
| t.Fatal("server did not shut down within 10 seconds") | ||
| } | ||
| } | ||
|
|
||
| func TestPprofServerGracefulShutdown(t *testing.T) { | ||
| listener, err := net.Listen("tcp", "127.0.0.1:0") | ||
| if err != nil { | ||
| t.Fatalf("failed to listen: %v", err) | ||
| } | ||
| addr := listener.Addr().String() | ||
| listener.Close() | ||
|
|
||
| srv := &pprofServer{ | ||
| Addr: addr, | ||
| } | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
|
|
||
| errCh := make(chan error, 1) | ||
| go func() { | ||
| errCh <- srv.Start(ctx) | ||
| }() | ||
|
|
||
| for i := 0; i < 20; i++ { | ||
| resp, getErr := http.Get(fmt.Sprintf("http://%s/debug/pprof/", addr)) | ||
| if getErr == nil { | ||
| resp.Body.Close() | ||
| break | ||
| } | ||
| time.Sleep(50 * time.Millisecond) | ||
| } | ||
|
|
||
| cancel() | ||
|
|
||
| select { | ||
| case err := <-errCh: | ||
| if err != nil { | ||
| t.Errorf("server returned error on shutdown: %v", err) | ||
| } | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("server did not shut down within 5 seconds") | ||
| } | ||
| } | ||
|
|
||
| func TestPprofServerNeedLeaderElection(t *testing.T) { | ||
| srv := &pprofServer{} | ||
| if srv.NeedLeaderElection() { | ||
| t.Error("pprofServer.NeedLeaderElection() returned true, expected false") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| type pprofServer struct { | ||
| Addr string | ||
| } | ||
|
|
||
| func (s *pprofServer) Start(ctx context.Context) error { | ||
| srv := &http.Server{ | ||
| Addr: s.Addr, | ||
| Handler: http.DefaultServeMux, | ||
| } | ||
| klog.Infof("Starting pprof server on %s", s.Addr) | ||
|
|
||
| errCh := make(chan error, 1) | ||
| go func() { | ||
| if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
| errCh <- err | ||
| } | ||
| close(errCh) | ||
| }() | ||
|
|
||
| select { | ||
| case err := <-errCh: | ||
| return fmt.Errorf("pprof server failed: %w", err) | ||
| case <-ctx.Done(): | ||
| } | ||
|
|
||
| shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| return srv.Shutdown(shutdownCtx) | ||
| } | ||
|
|
||
| func (s *pprofServer) NeedLeaderElection() bool { | ||
| return false | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.