-
Notifications
You must be signed in to change notification settings - Fork 816
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
I ran the HA tests on #3843 overnight in a loop and still noticed a very low grade flake in the allocator, so I decided to go ahead and clean up the issues I noticed while working on the previous PR: * 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 (note that I think this ^ is why the extensions flake disappeared after I added a pause). * also plumbs context-awareness through the allocator run{Mux,REST,GRPC} functions, which is I suspect hy we're seeing a low-grade flake in allocator still. (I think the delay I added previously has sufficient to drive it off, too, but this PR should be more better.)
- Loading branch information
Showing
4 changed files
with
95 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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" | ||
) | ||
|
||
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 | ||
} |