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

xds-server updates #437

Merged
merged 5 commits into from
Nov 29, 2021
Merged

xds-server updates #437

merged 5 commits into from
Nov 29, 2021

Conversation

iffyio
Copy link
Collaborator

@iffyio iffyio commented Nov 12, 2021

  • Adds health probes and configurable logging
  • Fixes a bug where we pass each endpoint as its own locality
    rather than all in the same locality
  • Add support for routing tokens - if a routing token annotation
    is set, then the server configures the proxy with a
    CaptureBytes=>TokenRouter in the filter chain.
  • Adds a simple dockerfile that can be used to build the server

- Adds health probes and configurable logging
- Fixes a bug where we pass each endpoint as its own locality
  rather than all in the same locality
- Add support for routing tokens - if a routing token annotation
  is set, then the server configures the proxy with a
  `CaptureBytes=>TokenRouter` in the filter chain.
- Adds a simple dockerfile that can be used to build the server
@google-cla google-cla bot added the cla: yes label Nov 12, 2021
@iffyio iffyio marked this pull request as ready for review November 12, 2021 14:28
Copy link
Collaborator

@XAMPPRocky XAMPPRocky left a comment

Choose a reason for hiding this comment

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

LGTM, though I'll obviously defer to @markmandel on the Go code.

xds/ci/Dockerfile Show resolved Hide resolved
xds/pkg/server/server.go Show resolved Hide resolved
}
}

func (s *Server) startAdminServer(ctx context.Context, address string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (s *Server) startAdminServer(ctx context.Context, address string) {
func (s *Server) Run(ctx context.Context) {

Move address into New, and then this object matches the New/Run pattern as everywhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated to create address within the function, this is a helper function that is already being called from Server.Run

}

// NewServer returns a new Server
func New(
logger *log.Logger,
port int16,
xdsPort int16,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should fail linting 🤔 , since the function name doesn't match the comment (and it should be NewServer)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure how to configure it, golint fails as expected but golangci-lint doesn't do this check

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the config we use for Agones:
https://github.com/googleforgames/agones/blob/97dbf4677ac1c5223e434bca8ffc84654f6ae851/.golangci.yml#L47-L65

There's lots more linters 😃 (want to do it here, or in aseparatee PR?)

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL (source)

When a function returns a value of type pkg.T, where T is not Pkg, the function name may include T to make client code easier to understand. A common situation is a package with multiple New-like functions:

So since this returns a Server, New is perfectly acceptable as a constructor name!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to use the same linters, (though none of those still catches the functionname/comment matching)

Copy link
Contributor

Choose a reason for hiding this comment

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

Weird. 🤔 Seems fine now though.

xds/cmd/controller.go Outdated Show resolved Hide resolved
xds/cmd/controller.go Show resolved Hide resolved
@iffyio iffyio requested a review from markmandel November 16, 2021 07:11
}

// NewServer returns a new Server
func New(
logger *log.Logger,
port int16,
xdsPort int16,
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the config we use for Agones:
https://github.com/googleforgames/agones/blob/97dbf4677ac1c5223e434bca8ffc84654f6ae851/.golangci.yml#L47-L65

There's lots more linters 😃 (want to do it here, or in aseparatee PR?)

}

// NewServer returns a new Server
func New(
logger *log.Logger,
port int16,
xdsPort int16,
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL (source)

When a function returns a value of type pkg.T, where T is not Pkg, the function name may include T to make client code easier to understand. A common situation is a package with multiple New-like functions:

So since this returns a Server, New is perfectly acceptable as a constructor name!


RUN go build -o /server cmd/controller.go

FROM alpine:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

This should run as a non-root user.

I would also recommend pinning an alpine version, I think major.minor is fine though, since alphine

Actually, if we are going down this path, our other image is distroless -- I would suggest keeping one base image rather than two. distroless has a very low surface area, and also makes it very easy to run as non root in an already setup best-practice environment.

Go example:
https://github.com/GoogleContainerTools/distroless/blob/main/examples/go/Dockerfile
Although we would want to run gcr.io/distroless/static:nonroot

Local example:

FROM gcr.io/distroless/cc:nonroot as base

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!


http.Handle("/metrics", promhttp.Handler())

http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be a liveness probe or a readiness probe?

It would be good if this was /live or /ready so that it was clear.

I'm assuming that it's a readiness probe, in that if the k8s control plane goes down, we don't want to keep restarting this process because the health check is failing.

In that vein, it's probably useful to have both, as if the process can't respond to a simple http response, it should probably be restarted.

But if the k8s api is down we should keep logging this via liveness, but not restart the process.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to /ready, I assume if folks want to use it for liveness they can point to the same endpoint as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah they could. But I don't think people will want to restart the container if the K8s control plane goes down (but it's a choice 😁)

Doesn't have to be this PR, but I'd be tempted to have a /live endpoint as well that was just a Http Handler that returns 200.

Reason being that if the process does freeze (and can't respond to just a simple http request) for whatever reason, then it will restart and hopefully recover again.

@iffyio iffyio requested a review from markmandel November 19, 2021 13:45
Copy link
Contributor

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Love it!

}

// NewServer returns a new Server
func New(
logger *log.Logger,
port int16,
xdsPort int16,
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird. 🤔 Seems fine now though.

@markmandel
Copy link
Contributor

Doesn't have to be this PR, but I'd be tempted to have a /live endpoint as well that was just a Http Handler that returns 200.

Only a minor thought for me - so if you want to merge as is, please feel free. Just leaving it open if it resonated and you wanted to do it with this PR 👍🏻

@iffyio iffyio force-pushed the iu/xds-server-updates branch from c37d1d4 to 7c650bb Compare November 29, 2021 06:50
@iffyio iffyio merged commit 58ac663 into main Nov 29, 2021
@iffyio iffyio deleted the iu/xds-server-updates branch November 29, 2021 08:23
@markmandel markmandel added kind/bug Something isn't working kind/feature New feature or request labels Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes kind/bug Something isn't working kind/feature New feature or request size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants