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

update Go version; add websocket / correct endpoints to 'src gateway benchmark' #1125

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

slimsag
Copy link
Member

@slimsag slimsag commented Nov 15, 2024

Continues development of #1124

  • Updates Go version used in this repository (I had to do this to develop, see https://sourcegraph.slack.com/archives/C07KZF47K/p1731627487087909)
  • Checks the status code returned by HTTP endpoints.
  • Updates Sourcegraph HTTP endpoints to /.api/gateway and /.api/gateway/websocket.
  • Updates gateway HTTP endpoints to /v2 and /v2/websocket
  • Adds websocket client.
  • Respects -gateway parameter and SRC_ENDPOINT/SRC_ACCESS_TOKEN

This should be sufficient for testing against the actual production endpoints once they are added / working / live in prod.

Test plan

Not tested yet since endpoints are not live yet. Command not in use yet, so no risk.

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
@slimsag slimsag requested a review from vdavid November 15, 2024 04:49
@slimsag slimsag requested a review from a team as a code owner November 15, 2024 04:49
Copy link
Contributor

@vdavid vdavid left a comment

Choose a reason for hiding this comment

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

Approved to unblock and because it's generally 👌. Also left a few suggestions to improve it further before merging.

gatewayWebsocket, sourcegraphWebsocket *websocket.Conn
err error
httpClient = &http.Client{}
endpoints = map[string]any{}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would help clarify that any.

Suggested change
endpoints = map[string]any{}
endpoints = map[string]any{} // Values: URL `string`s or `*websocket.Conn`s

endpoints = map[string]any{}
)
if *gatewayEndpoint != "" {
wsURL := strings.Replace(fmt.Sprint(*gatewayEndpoint, "/v2/websocket"), "http", "ws", 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, the httpws replacement is nice and elegant to keep that optional s. Self-explanatory once I saw it, but I missed it in my original version. Thanks! 👏

Comment on lines +73 to +74
endpoints["wss: gateway"] = gatewayWebsocket
endpoints["https: gateway"] = fmt.Sprint(*gatewayEndpoint, "/v2")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, maybe this would be more precise? We output these names, so might be worth adjusting.

Suggested change
endpoints["wss: gateway"] = gatewayWebsocket
endpoints["https: gateway"] = fmt.Sprint(*gatewayEndpoint, "/v2")
endpoints["ws(s): gateway"] = gatewayWebsocket
endpoints["http(s): gateway"] = fmt.Sprint(*gatewayEndpoint, "/v2")

(same for sourcegraph endpoints below)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this update messed up something, see the check annotations below. Also, would be nice to mention in the PR description that you updated packages, and state the reason (incl. whether it was related or unrelated to the main purpose of the PR).

Comment on lines -143 to +170
defer func(Body io.ReadCloser) {
err := Body.Close()
defer func(body io.ReadCloser) {
err := body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thanks! This was IntelliJ's autogenerated code. Will watch out for this in the future.

Comment on lines +181 to +184
if resp.StatusCode != http.StatusOK {
fmt.Printf("non-200 response: %v\n", resp.Status)
return 0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe check the body as well? I think it's a great call that you checked for response body == "pong" for WebSockets. I think we should do the same here. I'll adjust the endpoints to respond with "pong"


func benchmarkEndpointWebSocket(conn *websocket.Conn) time.Duration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming: I'd have called this benchmarkEndpointWebsocket with a non-capital "s". I looked up the Go docs and your version seems more idiomatic with Go.
If we agree that "WebSocket" is the correct capitalization for entity names in Go then please also rename gatewayWebsocket and sourcegraphWebsocket accordingly. (I'd do it to fix my mistake but I don't want to mess or conflict with your PR.)

Copy link
Contributor

@vdavid vdavid Nov 15, 2024

Choose a reason for hiding this comment

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

I've changed it to "WebSocket" everywhere in my other PR https://github.com/sourcegraph/sourcegraph/pull/1526

Copy link
Member Author

Choose a reason for hiding this comment

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

wikipedia says WebSocket so yea let's go with that capitalization

fmt.Printf("WebSocket read error: %v\n", err)
return 0
}
if string(message) != "pong" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've changed my other PR https://github.com/sourcegraph/sourcegraph/pull/1526 to respond with "pong" on all three endpoints.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fantastic!

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.

2 participants