Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

frontend: use #40827 to provide the src-cli version and download endpoints#40828

Merged
LawnGnome merged 3 commits into
mainfrom
aharvey/version-cache-usage
Aug 25, 2022
Merged

frontend: use #40827 to provide the src-cli version and download endpoints#40828
LawnGnome merged 3 commits into
mainfrom
aharvey/version-cache-usage

Conversation

@LawnGnome

@LawnGnome LawnGnome commented Aug 25, 2022

Copy link
Copy Markdown
Contributor

This PR uses the sourcegraph.com API added in #40827 to implement the /.api/src-cli/version and /.api/src-cli/{download} endpoints, rather than calling out to GitHub directly.

There's also some new caching added that should mean that Sourcegraph instances don't hammer sourcegraph.com with these requests either.

If the API is unavailable or unreachable, the previous behaviour of falling back to the MinimumVersion constant is preserved. This is mostly going to come into play with any early rollouts of Sourcegraph 4.0 that occur before sourcegraph.com is upgraded to 4.0, but I don't think the behavioural change is significant enough to be a problem.

Fixes #39468.

Test plan

There's good test coverage, and I've done a bunch of testing locally of the various scenarios, monitoring the requests with ngrok to ensure that the cache behaves as expected and the sourcegraph.com API isn't hit more often than expected.

@sourcegraph-bot

sourcegraph-bot commented Aug 25, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff f38ebd5...60ebdac.

Notify File(s)
@eseliger internal/src-cli/version.go
internal/src-cli/version_test.go

@LawnGnome LawnGnome requested a review from a team August 25, 2022 00:23
Comment thread cmd/frontend/internal/httpapi/src_cli.go Outdated
}
defer resp.Body.Close()

if resp.StatusCode < 200 || resp.StatusCode > 299 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same goes for status. The standard library has constants (http.StatusOk). But in this case, there is no 299 code. So I feel this is fine.

But could always do,

// http.StatusMultipleChoices = 300
if resp.StatusCode < http.StatusOk || resp.StatusCode >= http.StatusMultipleChoices {
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a case where I actually prefer having the integers rather than using the constants, since the ordering of the constants is less immediately apparent.

@LawnGnome LawnGnome merged commit 7fc215a into main Aug 25, 2022
@LawnGnome LawnGnome deleted the aharvey/version-cache-usage branch August 25, 2022 21:28
}

func (h *srcCliVersionHandler) handleVersion(w http.ResponseWriter) {
writeJSON(w, h.Version())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you intentionally switch from

func srcCliVersionServe(w http.ResponseWriter, r *http.Request) error {
	return writeJSON(w, &struct {
		Version string `json:"version"`
	}{
		Version: srcCliVersion(),
	})

to

	writeJSON(w, h.Version())

here?
https://sourcegraph.slack.com/archives/C03DWK5QJUS/p1661505252886269

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@courier-new

Copy link
Copy Markdown
Contributor

Side question not directly related to this PR, but: is our REST API documented anywhere in particular?

@eseliger

eseliger commented Sep 5, 2022

Copy link
Copy Markdown
Member

it's not!

LawnGnome added a commit that referenced this pull request Sep 9, 2022
This was a _very_ late change in developing #40828, and was totally my
fault that it slipped through. Basically, no request to the `src-cli`
version cache could succeed, because it would already have been handled
(and 404ed) by the normal `src-cli` version endpoint.
LawnGnome added a commit that referenced this pull request Sep 9, 2022
This was a _very_ late change in developing #40828, and was totally my
fault that it slipped through. Basically, no request to the `src-cli`
version cache could succeed, because it would already have been handled
(and 404ed) by the normal `src-cli` version endpoint.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Src-cli latest version endpoint is unauthenticated and can fall back to different version

6 participants