Skip to content
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

Add timeout for /health endpoint checks #145

Merged
merged 7 commits into from
Jul 21, 2023

Conversation

cristinaleonr
Copy link
Contributor

@cristinaleonr cristinaleonr commented Jul 20, 2023

This change is Reviewable

Copy link
Contributor

@stephen-soltesz stephen-soltesz left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 6 files at r1.
Reviewable status: 0 of 1 approvals obtained (waiting on @cristinaleonr)


cmd/heartbeat/health/checker_test.go line 28 at r1 (raw file):

				},
				&EndpointClient{
					Client: http.Client{},

nit: the Client value is a literal (not a pointer) and the zero value for http.Client is what's being declared here. Is it sufficient to simply declare &EndpointClient{} here?


cmd/heartbeat/health/checker_test.go line 151 at r1 (raw file):

				},
				&EndpointClient{
					Client: http.Client{},

Do any of these cases induce a timeout event for the health endpoint client? Which one if so? Please add one if not. This is the functionality being added. One test verifying that behavior would be welcome.

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/checker_test.go line 28 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

nit: the Client value is a literal (not a pointer) and the zero value for http.Client is what's being declared here. Is it sufficient to simply declare &EndpointClient{} here?

Changed.


cmd/heartbeat/health/checker_test.go line 151 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Do any of these cases induce a timeout event for the health endpoint client? Which one if so? Please add one if not. This is the functionality being added. One test verifying that behavior would be welcome.

I have added a test in the test file for the class where the behavior was implemented.

Copy link
Contributor

@stephen-soltesz stephen-soltesz left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 approvals obtained (waiting on @cristinaleonr)


cmd/heartbeat/health/endpoint-check_test.go line 55 at r2 (raw file):

			}

			hc := NewEndpointClient(time.Second)

Where is tt.timeout used?

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/endpoint-check_test.go line 55 at r2 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Where is tt.timeout used?

Whoops, sorry! The test was passing for a different reason, which I have now fixed.

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/endpoint-check_test.go line 55 at r2 (raw file):

Previously, cristinaleonr (Cristina Leon) wrote…

Whoops, sorry! The test was passing for a different reason, which I have now fixed.

Nvm, wait.

Copy link
Contributor

@stephen-soltesz stephen-soltesz left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 approvals obtained (waiting on @cristinaleonr)


cmd/heartbeat/health/endpoint-check_test.go line 31 at r3 (raw file):

			name:     "timeout",
			code:     http.StatusOK,
			timeout:  0,

This error case is labeled "timeout" -- but iiuc, an http.Client behavior with timeout = 0 is no timeout. What is this case testing?


cmd/heartbeat/health/endpoint-check_test.go line 45 at r3 (raw file):

		},
		{
			name:    "error",

What is the error case? Please use a slightly more descriptive name.


cmd/heartbeat/health/endpoint-check_test.go line 53 at r3 (raw file):

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if !tt.wantErr {

Where is tt.startSrv used?

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Apologies for the multiple revisions! I double checked it now 😅.

Reviewable status: 0 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/endpoint-check_test.go line 31 at r3 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

This error case is labeled "timeout" -- but iiuc, an http.Client behavior with timeout = 0 is no timeout. What is this case testing?

I separated this into a new test with a 1 second timeout.


cmd/heartbeat/health/endpoint-check_test.go line 45 at r3 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

What is the error case? Please use a slightly more descriptive name.

The server is not running. Done.


cmd/heartbeat/health/endpoint-check_test.go line 53 at r3 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Where is tt.startSrv used?

Sorry, I removed it and just moved the test case to its own function.

I realized that and that's why I added the "Nvm, wait" comment 👼.

Copy link
Contributor

@stephen-soltesz stephen-soltesz left a comment

Choose a reason for hiding this comment

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

One suggested refinement if possible. :lgtm:

Reviewed 3 of 6 files at r1, 1 of 2 files at r2, 1 of 2 files at r4.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @cristinaleonr)


cmd/heartbeat/health/endpoint-check_test.go line 66 at r4 (raw file):

	got, err := hc.checkHealthEndpoint()
	if err == nil {
		t.Errorf("checkHealthEndpoint() error = %v, wantErr %s", err, "context deadline error")

Is it possible to add an affirmative errors.Is check for context deadline error? I see context.DeadlineExceeded -- this would be nice if possible. Not blocking if not.


cmd/heartbeat/health/healthtest/healthtest.go line 18 at r4 (raw file):

}

func TestTimeoutServer(timeout time.Duration) *httptest.Server {

👍

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/endpoint-check_test.go line 66 at r4 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Is it possible to add an affirmative errors.Is check for context deadline error? I see context.DeadlineExceeded -- this would be nice if possible. Not blocking if not.

Even though the error message is of the form Get "http://127.0.0.1:44235/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers), it must not specifically wrap that error since the errors.Is check returns false.

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/endpoint-check_test.go line 66 at r4 (raw file):

Previously, cristinaleonr (Cristina Leon) wrote…

Even though the error message is of the form Get "http://127.0.0.1:44235/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers), it must not specifically wrap that error since the errors.Is check returns false.

Agh, hold on again, please.

Copy link
Contributor Author

@cristinaleonr cristinaleonr left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @stephen-soltesz)


cmd/heartbeat/health/endpoint-check_test.go line 66 at r4 (raw file):

Previously, cristinaleonr (Cristina Leon) wrote…

Agh, hold on again, please.

Yep, my original statement above is right (I was double checking 👼).

@cristinaleonr cristinaleonr merged commit 362c3c7 into main Jul 21, 2023
@cristinaleonr cristinaleonr deleted the sandbox-cristinaleon-health-timeout branch July 21, 2023 15:47
@cristinaleonr
Copy link
Contributor Author

Related to #149.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants