-
Notifications
You must be signed in to change notification settings - Fork 716
feat: Ignore ready and stats listener metrics in shutdown manager calculation #7985
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
+322
−43
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5b470db
feat: Ignore ready and stats listener metrics in shutdown manager cal…
zirain 2dc8876
fix
zirain fd38e68
fix
zirain 70c05a0
refactor
zirain df8600f
remove USE_SERVER_CONNECTIONS
zirain b055d92
address review comment
zirain 0719791
display the real value
zirain 2d9ad56
comment for worker thread
zirain 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,240 @@ | ||
| // Copyright Envoy Gateway Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // The full text of the Apache license is available in the LICENSE file at | ||
| // the root of the repo. | ||
|
|
||
| package envoy | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "net" | ||
| "net/http" | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "k8s.io/utils/ptr" | ||
| ) | ||
|
|
||
| // setupFakeEnvoyStats set up an HTTP server return content | ||
| func setupFakeEnvoyStats(t *testing.T, content string) *http.Server { | ||
| l, err := net.Listen("tcp", ":0") //nolint: gosec | ||
| require.NoError(t, err) | ||
| require.NoError(t, l.Close()) | ||
| mux := http.NewServeMux() | ||
| mux.HandleFunc("/", func(writer http.ResponseWriter, _ *http.Request) { | ||
| writer.Header().Set("Content-Type", "application/json") | ||
| writer.WriteHeader(http.StatusOK) | ||
| _, _ = writer.Write([]byte(content)) | ||
| }) | ||
|
|
||
| addr := l.Addr().String() | ||
| s := &http.Server{ | ||
| Addr: addr, | ||
| Handler: mux, | ||
| ReadHeaderTimeout: time.Second, | ||
| } | ||
| t.Logf("start to listen at %s ", addr) | ||
| go func() { | ||
| if err := s.ListenAndServe(); err != nil { | ||
| fmt.Println("fail to listen: ", err) | ||
| } | ||
| }() | ||
|
|
||
| return s | ||
| } | ||
|
|
||
| func TestGetTotalConnections(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| input string | ||
|
|
||
| expectedError error | ||
| expectedCount *int | ||
| }{ | ||
| { | ||
| name: "downstream_cx_active", | ||
| input: `{ | ||
| "stats": [ | ||
| { | ||
| "name": "listener.0.0.0.0_8000.downstream_cx_active", | ||
| "value": 1 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_0.downstream_cx_active", | ||
| "value": 1 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_1.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_2.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_3.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_4.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_5.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_6.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_7.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_8.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.0.0.0.0_8000.worker_9.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_0.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_1.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_2.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_3.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_4.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_5.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_6.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_7.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_8.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8080.worker_9.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_0.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_1.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_2.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_3.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_4.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_5.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_6.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_7.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_8.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.127.0.0.1_8081.worker_9.downstream_cx_active", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "name": "listener.admin.downstream_cx_active", | ||
| "value": 2 | ||
| }, | ||
| { | ||
| "name": "listener.admin.main_thread.downstream_cx_active", | ||
| "value": 2 | ||
| } | ||
| ] | ||
| }`, | ||
| expectedCount: ptr.To(1), | ||
| }, | ||
| { | ||
| name: "invalid", | ||
| input: `{"stats":[{"name":"listener.0.0.0.0_8000.downstream_cx_active","value":1]}`, | ||
| expectedError: errors.New("error getting listener downstream_cx_active stat"), | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| s := setupFakeEnvoyStats(t, tc.input) | ||
| _, port, err := net.SplitHostPort(s.Addr) | ||
| require.NoError(t, err) | ||
|
|
||
| p, err := strconv.Atoi(port) | ||
| require.NoError(t, err) | ||
| defer func() { | ||
| _ = s.Close() | ||
| }() | ||
| reader := strings.NewReader(tc.input) | ||
| rc := io.NopCloser(reader) | ||
| defer func() { | ||
| _ = rc.Close() | ||
| }() | ||
|
|
||
| gotCount, gotError := getTotalConnections(p) | ||
| if tc.expectedError != nil { | ||
| require.ErrorContains(t, gotError, tc.expectedError.Error()) | ||
| return | ||
| } | ||
| require.NoError(t, gotError) | ||
| require.Equal(t, tc.expectedCount, gotCount) | ||
| }) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can there be a case where
respis nilThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK,
respshouldn't be nil when there's no error.