forked from googleforgames/agones
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agones-{extensions,allocator}: Make servers context aware, add gRPC h…
…ealth check * adds an `httpserver` utility package to handle the `Run` function that controller/extensions use. Make that context aware using the same method as https.Run: https://github.com/googleforgames/agones/blob/dfa414e5e4da37798833bbf8c33919acb5f3c2ea/pkg/util/https/server.go#L127-L130 * also plumbs context-awareness through the allocator run{Mux,REST,GRPC} functions. * adds a gRPC health server to the allocator, calls .Shutdown() on it during graceful termination - this seems to push the client off correctly. Tested with e2e in a loop. Towards googleforgames#3853
- Loading branch information
Showing
12 changed files
with
500 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package httpserver | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"agones.dev/agones/pkg/util/runtime" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Server is a HTTPs server that conforms to the runner interface | ||
// we use in /cmd/controller. | ||
type Server struct { | ||
http.ServeMux | ||
|
||
Logger *logrus.Entry | ||
} | ||
|
||
// Run runs an http server on port :8080. | ||
func (s *Server) Run(ctx context.Context, _ int) error { | ||
s.Logger.Info("Starting http server...") | ||
srv := &http.Server{ | ||
Addr: ":8080", | ||
Handler: s, | ||
} | ||
go func() { | ||
<-ctx.Done() | ||
_ = srv.Close() | ||
}() | ||
|
||
if err := srv.ListenAndServe(); err != nil { | ||
if err == http.ErrServerClosed { | ||
s.Logger.WithError(err).Info("http server closed") | ||
} else { | ||
wrappedErr := errors.Wrap(err, "Could not listen on :8080") | ||
runtime.HandleError(s.Logger.WithError(wrappedErr), wrappedErr) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.