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

gRPC: migrate conf endpoint#55648

Merged
camdencheek merged 13 commits into
mainfrom
cc/grpc-config
Aug 10, 2023
Merged

gRPC: migrate conf endpoint#55648
camdencheek merged 13 commits into
mainfrom
cc/grpc-config

Conversation

@camdencheek

@camdencheek camdencheek commented Aug 8, 2023

Copy link
Copy Markdown
Member

This implements the internal conf endpoint with gRPC. This is protected by a separate environment variable, unlike most of our gRPC endpoints, because we need the site config in order to determine whether to use gRPC. This allows us to enable this on instances we control (and can monitor), and exclude the conf endpoint from the "enabled by default" in the next minor release so we can still safely disable gRPC if necessary.

This maintains the current polling method for updating config. After this is stable, we can look at switch to a server-streaming-update model.

Test plan

Added a roundtrip quick test. And it caught a small bug, so it works 🙂 The environment variable is enabled with sg, so this will get naturally tested during dev. Once this rolls out to all services, we can enable the env variable on sourcegraph.com and on managed instances.

@cla-bot cla-bot Bot added the cla-signed label Aug 8, 2023
@camdencheek camdencheek marked this pull request as ready for review August 9, 2023 01:40
@camdencheek camdencheek requested a review from ggilmore August 9, 2023 02:40
@eseliger

eseliger commented Aug 9, 2023

Copy link
Copy Markdown
Member

This maintains the current polling method for updating config. After this is stable, we can look at switch to a server-streaming-update model.

Very excited!

@ggilmore ggilmore left a comment

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.

A question: What's the behavior of the application if the site configuration can't be accessed for whatever reason?

I believe our binaries refuse to start up if they can't fetch the configuration, but what happens if the site configuration can't be fetched for a while while the binaries are already up and running?

(This could happen with REST too, but we have an additional failure mode here - the message size growing too large (however unlikely)).


var Client = &internalClient{URL: "http://" + frontendInternal}
var Client = &internalClient{
URL: "http://" + frontendInternal,

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.

I think it'd be nice to have a bit more robust url handling here.

Example: What if frontendInternal is http://foo:3090 already? With this logic, URL will be http://http://foo:3090.

Maybe you can adopt the logic that I wrote in https://github.com/sourcegraph/sourcegraph/blob/main/internal/grpc/defaults/cache.go#L97-L117?


message RawUnified {
int32 id = 1;
string site = 2;

@ggilmore ggilmore Aug 9, 2023

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.

I believe we've done our due-diligence to ensure that the site configuration must be utf-8 encoded?

It seems like this is implicitly enforced by our postgres settings: https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/docker-images/postgres-12-alpine/Dockerfile.wolfi?L27

(I also tried setting the site config json override file to an invalid utf-8 sequence and saw that sourcegraph complained as I expected: echo -n -e '\xf0\x28\x8c\xbc' > external-services-config.json )


I don't have a strong preference for this, but do you have thoughts for represnting the site config json as bytes rather than string? We already need to cast it to []byte for json.Unmarshal purposes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, I did look into this. JSON is UTF-8 by definition, so we will fail validation far before we ever get to protobuf. It's possible that the JSON encodes non-utf8 strings, but at this level (the raw JSON), we don't need to worry about that. I think string is preferable to bytes in this case mostly because that's what's used in our types now

@camdencheek camdencheek merged commit 1dd8601 into main Aug 10, 2023
@camdencheek camdencheek deleted the cc/grpc-config branch August 10, 2023 17:34
@github-actions

Copy link
Copy Markdown
Contributor

The backport to 5.1 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-5.1 5.1
# Navigate to the new working tree
cd .worktrees/backport-5.1
# Create a new branch
git switch --create backport-55648-to-5.1
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 1dd8601839b18d072718a732139355fb3793e784
# Push it to GitHub
git push --set-upstream origin backport-55648-to-5.1
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.1

Then, create a pull request where the base branch is 5.1 and the compare/head branch is backport-55648-to-5.1.

@github-actions github-actions Bot added backports failed-backport-to-5.1 release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases labels Aug 10, 2023
camdencheek added a commit that referenced this pull request Aug 10, 2023
(cherry picked from commit 1dd8601)
camdencheek added a commit that referenced this pull request Aug 17, 2023
(cherry picked from commit 1dd8601)
camdencheek added a commit that referenced this pull request Aug 17, 2023
* Backend: remove internalClient.SendEmail (#55459)

Now that config can be fetched from all services, there is no need for
this internalClient method. One fewer to implement for gRPC

(cherry picked from commit f9d67fe)

* gRPC: migrate conf endpoint (#55648)

(cherry picked from commit 1dd8601)

* Backend: remove internalClient.ExternalURL (#55463)

This removes the `internalClient.ExternalURL` method, which can be
replaced with a simple call to `conf.Get()`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backports cla-signed release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants