-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of Ping Discovery Service (#73)
This includes * Go code to lookup Ping Services, and return one for each region (randomly distributed across requests). * README for API description and basic building and running steps. * Docker file for image building. Next will be creating a Cloud Build and Cloud Deploy to take it live (and hopefully set the template for that work). Work on #46
- Loading branch information
1 parent
0bef8bc
commit 839f6a3
Showing
5 changed files
with
595 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Copyright 2023 Google LLC | ||
# | ||
# 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. | ||
# | ||
|
||
FROM golang:1.19 as build | ||
|
||
WORKDIR /go/src/ping-discovery | ||
COPY . . | ||
|
||
RUN go mod download | ||
RUN go vet -v | ||
RUN go test -v | ||
|
||
RUN CGO_ENABLED=0 go build -o /go/bin/ping-discovery | ||
|
||
FROM gcr.io/distroless/static-debian11:nonroot | ||
|
||
COPY --from=build /go/bin/ping-discovery / | ||
|
||
ENV GIN_MODE=release | ||
USER nonroot:nonroot | ||
CMD ["/ping-discovery"] |
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,75 @@ | ||
# Ping Discovery Service | ||
|
||
This service will inspect a Google Cloud project for | ||
[Agones Latency Ping endpoints](https://agones.dev/site/docs/guides/ping-service/), and return one for each region | ||
that Agones is installed. | ||
|
||
The Service will choose an endpoint at random on each request for each region, assuming there are more than one. | ||
This is to distribute the load amongst clusters. | ||
|
||
## API | ||
|
||
<table> | ||
<thead> | ||
<td>Endpoint</td> | ||
<td>Input</td> | ||
<td>Return</td> | ||
<td>Description</td> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><code>GET /list</code></td> | ||
<td> None </td> | ||
<td> | ||
<pre> | ||
{ | ||
"asia-east1": { | ||
"Name": "agones-ping-udp-service", | ||
"Namespace": "agones-system", | ||
"Region": "asia-east1", | ||
"Address": "104.155.211.151", | ||
"Protocol": "UDP" | ||
}, | ||
"europe-west1": { | ||
"Name": "agones-ping-udp-service", | ||
"Namespace": "agones-system", | ||
"Region": "europe-west1", | ||
"Address": "34.22.151.131", | ||
"Protocol": "UDP" | ||
}, | ||
"us-central1": { | ||
"Name": "agones-ping-udp-service", | ||
"Namespace": "agones-system", | ||
"Region": "us-central1", | ||
"Address": "35.227.137.95", | ||
"Protocol": "UDP" | ||
} | ||
} | ||
</pre> | ||
</td> | ||
<td> | ||
Map of region, where the key is the region name, and a singular | ||
endpoint for the UDP ping service for each region as the value. | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
## Running locally | ||
|
||
When running locally, make sure you have [gcloud](https://cloud.google.com/sdk/docs/install) installed, | ||
and a default project authenticated and configured, so that the binary can determine the project it should be | ||
scanning for | ||
Ping endpoints. | ||
|
||
```shell | ||
go run main.go | ||
``` | ||
|
||
## Building image | ||
|
||
```shell | ||
docker build . -t ping-discovery | ||
``` | ||
|
||
Note: The docker image will fail locally, since it has no access Google Cloud Application Default Credentials. |
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,47 @@ | ||
module ping-discovery | ||
|
||
go 1.19 | ||
|
||
require ( | ||
cloud.google.com/go/compute v1.18.0 | ||
github.com/gin-gonic/gin v1.9.0 | ||
github.com/jellydator/ttlcache/v3 v3.0.1 | ||
golang.org/x/oauth2 v0.5.0 | ||
google.golang.org/api v0.108.0 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go/compute/metadata v0.2.3 // indirect | ||
github.com/bytedance/sonic v1.8.0 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.11.2 // indirect | ||
github.com/goccy/go-json v0.10.0 // indirect | ||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect | ||
github.com/googleapis/gax-go/v2 v2.7.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.9 // indirect | ||
go.opencensus.io v0.24.0 // indirect | ||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect | ||
golang.org/x/crypto v0.5.0 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/sync v0.1.0 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
golang.org/x/text v0.7.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/genproto v0.0.0-20230124163310-31e0e69b6fc2 // indirect | ||
google.golang.org/grpc v1.51.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.