diff --git a/services/cloudbuild.yaml b/services/cloudbuild.yaml index 92100de..9e48025 100644 --- a/services/cloudbuild.yaml +++ b/services/cloudbuild.yaml @@ -44,11 +44,6 @@ steps: args: [ "build", ".", "-t", "${_OPEN_MATCH_MATCHFUNCTION_IMAGE}" ] dir: open-match/matchfunction waitFor: [ '-' ] - - name: gcr.io/cloud-builders/docker - id: open-match-fake-frontend - args: [ "build", ".", "-t", "${_OPEN_MATCH_FAKE_FRONTEND_IMAGE}" ] - dir: open-match/fake-frontend - waitFor: [ '-' ] # # Deployment @@ -61,7 +56,7 @@ steps: --annotations=cloud_build=https://console.cloud.google.com/cloud-build/builds/$BUILD_ID \ --delivery-pipeline global-game-services \ --skaffold-file skaffold.yaml \ - --images ping-discovery=$_PING_IMAGE,profile=$_PROFILE_IMAGE,frontend=$_FRONTEND_IMAGE,open-match-director=$_OPEN_MATCH_DIRECTOR_IMAGE,open-match-matchfunction=$_OPEN_MATCH_MATCHFUNCTION_IMAGE,open-match-fake-frontend=$_OPEN_MATCH_FAKE_FRONTEND_IMAGE \ + --images ping-discovery=$_PING_IMAGE,profile=$_PROFILE_IMAGE,frontend=$_FRONTEND_IMAGE,open-match-director=$_OPEN_MATCH_DIRECTOR_IMAGE,open-match-matchfunction=$_OPEN_MATCH_MATCHFUNCTION_IMAGE \ --region us-central1 automapSubstitutions: true @@ -72,14 +67,12 @@ artifacts: - ${_REGISTRY}/frontend - ${_REGISTRY}/open-match-director - ${_REGISTRY}/open-match-matchfunction - - ${_REGISTRY}/open-match-fake-frontend substitutions: _PING_IMAGE: ${_REGISTRY}/ping-discovery:${BUILD_ID} _PROFILE_IMAGE: ${_REGISTRY}/profile:${BUILD_ID} _FRONTEND_IMAGE: ${_REGISTRY}/frontend:${BUILD_ID} _OPEN_MATCH_DIRECTOR_IMAGE: ${_REGISTRY}/open-match-director:${BUILD_ID} _OPEN_MATCH_MATCHFUNCTION_IMAGE: ${_REGISTRY}/open-match-matchfunction:${BUILD_ID} - _OPEN_MATCH_FAKE_FRONTEND_IMAGE: ${_REGISTRY}/open-match-fake-frontend:${BUILD_ID} _REGISTRY: us-docker.pkg.dev/${PROJECT_ID}/global-game-images options: dynamic_substitutions: true diff --git a/services/open-match/README.md b/services/open-match/README.md index d046535..e26cdc0 100644 --- a/services/open-match/README.md +++ b/services/open-match/README.md @@ -30,31 +30,6 @@ given set of match player's latencies. It does this by providing the `region` HTTP header to an Anthos Service Mesh Allocation Service - where the `region` header will route the allocation request to one of the Agones GKE clusters in that region. -## Fake Frontend - -The `openmatch-fake-frontend` deployment generates fake tickets for testing of the Open Match services -in thie directory. When enabled, the fake frontend will generate a batch of tickets every period. For -each ticket, the fake frontend waits on an Open Match assignment and then deletes the ticket. - -Note that if the Director is tied to a real Agones Fleet, this will generate arbitrary game server -allocations. You may want to use a game server binary that exits after a specific period of time, -otherwise, when enabled, the fake frontend will continue to allocate game servers. - -The fake frontend is always deployed, but does nothing unless configured: - -```shell -# Edit the `period` and `tickets_per_period` to what you want, e.g. "20s" and "20" -# The fake frontend will generate `tickets_per_period` tickets every `period`, where -# period is expressed as a Go Duration (e.g. "20s", "1m", etc.) -kubectl edit configmap/open-match-fake-frontend - -# Restart the deployment to pick up the config -kubectl rollout restart deployment/open-match-fake-frontend - -# Verify load has started -kubectl logs deployment/open-match-fake-frontend -``` - ## Credit This integration is based on the [Open Match Matchmaker 101 tutorial](https://open-match.dev/site/docs/tutorials/matchmaker101/frontend/) [(source)](https://github.com/googleforgames/open-match/tree/release-1.7/tutorials). diff --git a/services/open-match/director/Dockerfile b/services/open-match/director/Dockerfile index 26153d9..2444c5d 100644 --- a/services/open-match/director/Dockerfile +++ b/services/open-match/director/Dockerfile @@ -14,7 +14,7 @@ # limitations under the License. # -FROM golang:1.19 as build +FROM golang:1.21 as build WORKDIR /go/src/director COPY . . diff --git a/services/open-match/director/go.mod b/services/open-match/director/go.mod index b5dc18c..ef9f22a 100644 --- a/services/open-match/director/go.mod +++ b/services/open-match/director/go.mod @@ -1,20 +1,21 @@ module github.com/googleforgames/global-multiplayer-demo/services/open-match/director -go 1.19 +go 1.21 + +toolchain go1.21.9 require ( - golang.org/x/oauth2 v0.4.0 - google.golang.org/grpc v1.53.0 - open-match.dev/open-match v1.7.0 + golang.org/x/oauth2 v0.20.0 + google.golang.org/grpc v1.64.0 + open-match.dev/open-match v1.8.1 ) require ( - github.com/golang/protobuf v1.5.2 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect - google.golang.org/protobuf v1.28.1 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect + google.golang.org/protobuf v1.34.1 // indirect ) diff --git a/services/open-match/director/go.sum b/services/open-match/director/go.sum index e26f3a8..7640a6d 100644 --- a/services/open-match/director/go.sum +++ b/services/open-match/director/go.sum @@ -1,36 +1,22 @@ -github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0/go.mod h1:YDZoGHuwE+ov0c8smSH49WLF3F2LaWnYYuDVd+EWrc0= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M= -golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= -google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -open-match.dev/open-match v1.7.0 h1:EzPPzsMy92i52XNrRWx3KMXIcNzdgHwMd01KsoT7HaI= -open-match.dev/open-match v1.7.0/go.mod h1:JAkoEIVgc8p6GnfpxOC5Aqby2vkQDHrjlCbI2crP3WU= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= +golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e h1:SkdGTrROJl2jRGT/Fxv5QUf9jtdKCQh4KQJXbXVLAi0= +google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e/go.mod h1:LweJcLbyVij6rCex8YunD8DYR5VDonap/jYl3ZRxcIU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e h1:Elxv5MwEkCI9f5SkoL6afed6NTdxaGoAo39eANBwHL8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +open-match.dev/open-match v1.8.1 h1:Tp5fxeUVBugt091zFxMJim6TalE9sFDB2mNGw5zRWQQ= +open-match.dev/open-match v1.8.1/go.mod h1:FjKE1hS+BGFMxVUQvPLqXWMUjjFysYrPESdEfEpDxvM= diff --git a/services/open-match/director/main.go b/services/open-match/director/main.go index 1b75ff0..1feca6e 100644 --- a/services/open-match/director/main.go +++ b/services/open-match/director/main.go @@ -16,6 +16,7 @@ package main import ( "context" + "errors" "fmt" "io" "log" @@ -24,6 +25,7 @@ import ( allocation "github.com/googleforgames/global-multiplayer-demo/services/open-match/director/agones/swagger" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" "open-match.dev/open-match/pkg/pb" ) @@ -52,7 +54,7 @@ func main() { ctx := context.Background() // Connect to Open Match Backend. - conn, err := grpc.Dial(omBackendEndpoint, grpc.WithInsecure()) + conn, err := grpc.NewClient(omBackendEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("Failed to connect to Open Match Backend, got %s", err.Error()) } @@ -137,10 +139,9 @@ func fetch(be pb.BackendServiceClient, p *pb.MatchProfile) ([]*pb.Match, error) func assignMatch(ctx context.Context, be pb.BackendServiceClient, aas *allocation.APIClient, match *pb.Match) { aar, _, err := aas.AllocationServiceApi.Allocate(ctx, allocation.AllocationAllocationRequest{Namespace: gameNamespace}) if err != nil { - if swErr, ok := err.(allocation.GenericSwaggerError); ok { + var swErr allocation.GenericSwaggerError + if errors.As(err, &swErr) { log.Printf("Could not allocate game server from Agones for match %s: %s: %s", match.GetMatchId(), swErr.Error(), swErr.Body()) - } else { - log.Printf("Could not allocate game server from Agones for match %s (generic error): %v", match.GetMatchId(), err) } return } @@ -160,7 +161,7 @@ func assignMatch(ctx context.Context, be pb.BackendServiceClient, aas *allocatio } func assignConnToTickets(be pb.BackendServiceClient, conn string, tickets []*pb.Ticket) error { - ticketIDs := []string{} + var ticketIDs []string for _, t := range tickets { ticketIDs = append(ticketIDs, t.Id) } diff --git a/services/open-match/fake-frontend/Dockerfile b/services/open-match/fake-frontend/Dockerfile deleted file mode 100644 index 9a37906..0000000 --- a/services/open-match/fake-frontend/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ - # 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/fake-frontend -COPY . . - -RUN go mod download -RUN go vet -v -RUN go test -v - -RUN CGO_ENABLED=0 go build -o /go/bin/fake-frontend - -FROM gcr.io/distroless/static-debian11:nonroot - -COPY --from=build /go/bin/fake-frontend / - -ENV GIN_MODE=release -USER nonroot:nonroot -CMD ["/fake-frontend"] \ No newline at end of file diff --git a/services/open-match/fake-frontend/fake-frontend.yaml b/services/open-match/fake-frontend/fake-frontend.yaml deleted file mode 100644 index 0e653b3..0000000 --- a/services/open-match/fake-frontend/fake-frontend.yaml +++ /dev/null @@ -1,52 +0,0 @@ -# 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. - -apiVersion: apps/v1 -kind: Deployment -metadata: - name: open-match-fake-frontend -spec: - replicas: 1 - selector: - matchLabels: - app: open-match-fake-frontend - template: - metadata: - labels: - app: open-match-fake-frontend - spec: - containers: - - name: open-match-fake-frontend - image: open-match-fake-frontend - env: - - name: FAKE_FRONTEND_PERIOD - valueFrom: - configMapKeyRef: - name: open-match-fake-frontend - key: period - - name: FAKE_FRONTEND_TICKETS_PER_PERIOD - valueFrom: - configMapKeyRef: - name: open-match-fake-frontend - key: tickets_per_period ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: open-match-fake-frontend -data: - # fake-frontend will create `tickets_per_period` fake tickets every `period` seconds. - # fake-frontend is disabled if either `period` or `tickets_per_period` is 0 or can't be parsed. - period: "0" - tickets_per_period: "20" \ No newline at end of file diff --git a/services/open-match/fake-frontend/go.mod b/services/open-match/fake-frontend/go.mod deleted file mode 100644 index a9675d0..0000000 --- a/services/open-match/fake-frontend/go.mod +++ /dev/null @@ -1,18 +0,0 @@ -module github.com/googleforgames/global-multiplayer-demo/services/open-match/fake-frontend - -go 1.19 - -require ( - google.golang.org/grpc v1.53.0 - open-match.dev/open-match v1.7.0 -) - -require ( - github.com/golang/protobuf v1.5.2 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect - google.golang.org/protobuf v1.28.1 // indirect -) diff --git a/services/open-match/fake-frontend/go.sum b/services/open-match/fake-frontend/go.sum deleted file mode 100644 index abe5bb5..0000000 --- a/services/open-match/fake-frontend/go.sum +++ /dev/null @@ -1,25 +0,0 @@ -github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0/go.mod h1:YDZoGHuwE+ov0c8smSH49WLF3F2LaWnYYuDVd+EWrc0= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= -google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -open-match.dev/open-match v1.7.0 h1:EzPPzsMy92i52XNrRWx3KMXIcNzdgHwMd01KsoT7HaI= -open-match.dev/open-match v1.7.0/go.mod h1:JAkoEIVgc8p6GnfpxOC5Aqby2vkQDHrjlCbI2crP3WU= diff --git a/services/open-match/fake-frontend/main.go b/services/open-match/fake-frontend/main.go deleted file mode 100644 index 77e846f..0000000 --- a/services/open-match/fake-frontend/main.go +++ /dev/null @@ -1,122 +0,0 @@ -// 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. - -package main - -// The Frontend in this tutorial continuously creates Tickets in batches in Open Match. - -import ( - "context" - "log" - "math/rand" - "os" - "strconv" - "time" - - "google.golang.org/grpc" - "open-match.dev/open-match/pkg/pb" -) - -const ( - // The endpoint for the Open Match Frontend service. - omFrontendEndpoint = "open-match-frontend.open-match.svc.cluster.local:50504" -) - -func main() { - period, ticketsPerPeriod := getConfig() - if period == 0 || ticketsPerPeriod == 0 { - log.Printf("Disabled, sleeping") - for { - time.Sleep(24 * time.Hour) - } - } - - // Connect to Open Match Frontend. - conn, err := grpc.Dial(omFrontendEndpoint, grpc.WithInsecure()) - if err != nil { - log.Fatalf("Failed to connect to Open Match, got %v", err) - } - - defer conn.Close() - fe := pb.NewFrontendServiceClient(conn) - for range time.Tick(period) { - for i := 0; i <= ticketsPerPeriod; i++ { - req := &pb.CreateTicketRequest{ - Ticket: makeTicket(), - } - - log.Printf("Creating Ticket %v", req.Ticket) - resp, err := fe.CreateTicket(context.Background(), req) - if err != nil { - log.Printf("Failed to Create Ticket, got %s", err.Error()) - continue - } - - log.Println("Ticket created successfully, id:", resp.Id) - go deleteOnAssign(fe, resp) - } - } -} - -func getConfig() (time.Duration, int) { - period, err := time.ParseDuration(os.Getenv("FAKE_FRONTEND_PERIOD")) - if err != nil { - log.Printf("FAKE_FRONTEND_PERIOD not set or set to invalid duration: %v", err) - period = 0 - } - tickets, err := strconv.Atoi(os.Getenv("FAKE_FRONTEND_TICKETS_PER_PERIOD")) - if err != nil { - log.Printf("FAKE_FRONTEND_TICKETS_PER_PERIOD not set or invalid: %v", err) - tickets = 0 - } - log.Printf("Configured to generate %d tickets every %v", tickets, period) - return period, tickets -} - -// deleteOnAssign fetches the Ticket state periodically and deletes the Ticket -// once it has an assignment. -func deleteOnAssign(fe pb.FrontendServiceClient, t *pb.Ticket) { - for { - got, err := fe.GetTicket(context.Background(), &pb.GetTicketRequest{TicketId: t.GetId()}) - if err != nil { - log.Fatalf("Failed to Get Ticket %v, got %s", t.GetId(), err.Error()) - } - - if got.GetAssignment() != nil { - log.Printf("Ticket %v got assignment %v", got.GetId(), got.GetAssignment()) - break - } - - time.Sleep(time.Second * 1) - } - - _, err := fe.DeleteTicket(context.Background(), &pb.DeleteTicketRequest{TicketId: t.GetId()}) - if err != nil { - log.Fatalf("Failed to Delete Ticket %v, got %s", t.GetId(), err.Error()) - } -} - -// Ticket generates a Ticket with data using the package configuration. -func makeTicket() *pb.Ticket { - return &pb.Ticket{ - SearchFields: &pb.SearchFields{ - DoubleArgs: map[string]float64{ - "skill": 2 * rand.Float64(), - "latency-us-central1": 50.0 * rand.ExpFloat64(), - "latency-europe-west1": 50.0 * rand.ExpFloat64(), - "latency-asia-east1": 50.0 * rand.ExpFloat64(), - }, - }, - } -} diff --git a/services/open-match/matchfunction/Dockerfile b/services/open-match/matchfunction/Dockerfile index 12fff88..342a736 100644 --- a/services/open-match/matchfunction/Dockerfile +++ b/services/open-match/matchfunction/Dockerfile @@ -14,7 +14,7 @@ # limitations under the License. # -FROM golang:1.19 as build +FROM golang:1.21 as build WORKDIR /go/src/matchfunction COPY . . diff --git a/services/open-match/matchfunction/go.mod b/services/open-match/matchfunction/go.mod index 9a2f26d..5481f77 100644 --- a/services/open-match/matchfunction/go.mod +++ b/services/open-match/matchfunction/go.mod @@ -1,18 +1,20 @@ module github.com/googleforgames/global-multiplayer-demo/services/open-match/matchfunction -go 1.19 +go 1.21 + +toolchain go1.21.9 require ( - google.golang.org/grpc v1.53.0 - google.golang.org/protobuf v1.28.1 - open-match.dev/open-match v1.7.0 + google.golang.org/grpc v1.64.0 + google.golang.org/protobuf v1.34.1 + open-match.dev/open-match v1.8.1 ) require ( - github.com/golang/protobuf v1.5.2 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect ) diff --git a/services/open-match/matchfunction/go.sum b/services/open-match/matchfunction/go.sum index b6f4d50..968421f 100644 --- a/services/open-match/matchfunction/go.sum +++ b/services/open-match/matchfunction/go.sum @@ -1,25 +1,20 @@ -github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 h1:gDLXvp5S9izjldquuoAhDzccbskOL6tDC5jMSyx3zxE= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2/go.mod h1:7pdNwVWBBHGiCxa9lAszqCJMbfTISJ7oMftp8+UGV08= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= -google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= -google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -open-match.dev/open-match v1.7.0 h1:EzPPzsMy92i52XNrRWx3KMXIcNzdgHwMd01KsoT7HaI= -open-match.dev/open-match v1.7.0/go.mod h1:JAkoEIVgc8p6GnfpxOC5Aqby2vkQDHrjlCbI2crP3WU= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e h1:SkdGTrROJl2jRGT/Fxv5QUf9jtdKCQh4KQJXbXVLAi0= +google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e/go.mod h1:LweJcLbyVij6rCex8YunD8DYR5VDonap/jYl3ZRxcIU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e h1:Elxv5MwEkCI9f5SkoL6afed6NTdxaGoAo39eANBwHL8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +open-match.dev/open-match v1.8.1 h1:Tp5fxeUVBugt091zFxMJim6TalE9sFDB2mNGw5zRWQQ= +open-match.dev/open-match v1.8.1/go.mod h1:FjKE1hS+BGFMxVUQvPLqXWMUjjFysYrPESdEfEpDxvM= diff --git a/services/open-match/matchfunction/mmf/matchfunction.go b/services/open-match/matchfunction/mmf/matchfunction.go index f97dfec..3b49131 100644 --- a/services/open-match/matchfunction/mmf/matchfunction.go +++ b/services/open-match/matchfunction/mmf/matchfunction.go @@ -90,7 +90,7 @@ func (s *MatchFunctionService) makeMatches(profileName, idPrefix string, tickets eval, err := anypb.New(&pb.DefaultEvaluationCriteria{Score: matchScore}) if err != nil { log.Printf("Failed to marshal DefaultEvaluationCriteria into anypb: %v", err) - return nil, fmt.Errorf("Failed to marshal DefaultEvaluationCriteria into anypb: %w", err) + return nil, fmt.Errorf("failed to marshal DefaultEvaluationCriteria into anypb: %w", err) } matches = append(matches, &pb.Match{ diff --git a/services/open-match/matchfunction/mmf/server.go b/services/open-match/matchfunction/mmf/server.go index a210b51..bb51214 100644 --- a/services/open-match/matchfunction/mmf/server.go +++ b/services/open-match/matchfunction/mmf/server.go @@ -20,6 +20,7 @@ import ( "net" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" "open-match.dev/open-match/pkg/pb" ) @@ -37,7 +38,8 @@ type MatchFunctionService struct { // for pools specified in MatchProfile. func Start(queryServiceAddr string, serverPort int, playersPerMatch int) { // Connect to QueryService. - conn, err := grpc.Dial(queryServiceAddr, grpc.WithInsecure()) + + conn, err := grpc.NewClient(queryServiceAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("Failed to connect to Open Match, got %s", err.Error()) } diff --git a/services/skaffold.yaml b/services/skaffold.yaml index fca13fd..7e0fbd7 100644 --- a/services/skaffold.yaml +++ b/services/skaffold.yaml @@ -26,7 +26,6 @@ manifests: - open-match/director/director.yaml - open-match/matchfunction/matchfunction.yaml - open-match/matchfunction/config.yaml - - open-match/fake-frontend/fake-frontend.yaml deploy: kubectl: flags: