From 2225ef9d62b88085d11ee046ed10a8dd04a74dfe Mon Sep 17 00:00:00 2001 From: Jon Foust Date: Mon, 26 Oct 2020 16:24:08 -0400 Subject: [PATCH 1/2] Skill based match function. Moved from previous PR in Open Match (core) repo --- skill-based/.DS_Store | Bin 0 -> 6148 bytes skill-based/Dockerfile | 24 +++++ skill-based/main.go | 37 +++++++ skill-based/mmf/matchfunction.go | 142 ++++++++++++++++++++++++++ skill-based/mmf/matchfunction_test.go | 42 ++++++++ skill-based/mmf/server.go | 62 +++++++++++ 6 files changed, 307 insertions(+) create mode 100644 skill-based/.DS_Store create mode 100644 skill-based/Dockerfile create mode 100644 skill-based/main.go create mode 100644 skill-based/mmf/matchfunction.go create mode 100644 skill-based/mmf/matchfunction_test.go create mode 100644 skill-based/mmf/server.go diff --git a/skill-based/.DS_Store b/skill-based/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fea4bd79455e2f414708ec06a81680e98ddf1494 GIT binary patch literal 6148 zcmeHK&2G~`5Z+Bfv5AC?)I%$AScwBd${__xuO_6NkU+Si2Y!N$O=HRNMvjvlqDU4G zzyrXA1GMi^cm~v$;MjX-cBhakz^w?-Of>t=&d$unpI5tHA%yIV;|(D^A%p{pSaYHI ziQqWulGMnv0w}S@Xc%QWg5Gg7T#9DL-^c*IySf;_?{zd?e1BOwD%5 zOHH?Vx#>O+`g$6aVL2Xk!lLJ04bnJ?!eTd#%l=N1Z)eFQ$sZOE!ZInIV(^aE83b56 zjGm;)wCAnf(|H-Dc~Y2qw#KvFG>`SPqsMtXGVxU0*pI@p4|SYtey9wSuH*K+wb|_E z=4MMlGjFNc)>gZvZr{2ypSzB;e*OOA7vnc?-@X6%Y5(Bxv&j+?ma35}gs1QY45A|2 z+X!Ci0WIS7Z$Cx`y4$5i?tHlMwRbc*yt_CW|7LX9U#!~3d1<~$P~@4;_rP=d?{Jib z8DIvOfpcPjwi>5-PW8DgGr$b|yA0s|pg<9Q!pfrAI-oIE0Kf*gjew1J3CvN1K4E1M zMnI%Z1+=M>t{Bp$gI`gcPgq&B=|a-wL( ticket.SearchFields.DoubleArgs["mmr"] { + low = ticket.SearchFields.DoubleArgs["mmr"] + } + } + quality = high - low + + return quality +} diff --git a/skill-based/mmf/matchfunction_test.go b/skill-based/mmf/matchfunction_test.go new file mode 100644 index 0000000..5e825d1 --- /dev/null +++ b/skill-based/mmf/matchfunction_test.go @@ -0,0 +1,42 @@ +// Copyright 2020 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 mmf + +import ( + "math" + "testing" + + "github.com/stretchr/testify/require" + "open-match.dev/open-match/pkg/pb" +) + +func TestCheckQuality(t *testing.T) { + t.Run("no tickets", func(t *testing.T) { + q := computeQuality(nil) + require.Equal(t, math.Inf(-1), q) + }) + t.Run("one ticket", func(t *testing.T) { + q := computeQuality([]*pb.Ticket{ + { + SearchFields: &pb.SearchFields{ + DoubleArgs: map[string]float64{ + "mmr": 3, + }, + }, + }, + }) + require.Equal(t, 0.0, q) + }) +} diff --git a/skill-based/mmf/server.go b/skill-based/mmf/server.go new file mode 100644 index 0000000..9ea14b6 --- /dev/null +++ b/skill-based/mmf/server.go @@ -0,0 +1,62 @@ +// Copyright 2019 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 mmf + +import ( + "fmt" + "log" + "net" + + "google.golang.org/grpc" + "open-match.dev/open-match/pkg/pb" +) + +// MatchFunctionService implements pb.MatchFunctionServer, the server generated +// by compiling the protobuf, by fulfilling the pb.MatchFunctionServer interface. +type MatchFunctionService struct { + grpc *grpc.Server + queryServiceClient pb.QueryServiceClient + port int +} + +// Start creates and starts the Match Function server and also connects to Open +// Match's queryService. This connection is used at runtime to fetch tickets +// for pools specified in MatchProfile. +func Start(queryServiceAddr string, serverPort int) { + // Connect to QueryService. + conn, err := grpc.Dial(queryServiceAddr, grpc.WithInsecure()) + if err != nil { + log.Fatalf("Failed to connect to Open Match, got %s", err.Error()) + } + defer conn.Close() + + mmfService := MatchFunctionService{ + queryServiceClient: pb.NewQueryServiceClient(conn), + } + + // Create and host a new gRPC service on the configured port. + server := grpc.NewServer() + pb.RegisterMatchFunctionServer(server, &mmfService) + ln, err := net.Listen("tcp", fmt.Sprintf(":%d", serverPort)) + if err != nil { + log.Fatalf("TCP net listener initialization failed for port %v, got %s", serverPort, err.Error()) + } + + log.Printf("TCP net listener initialized for port %v", serverPort) + err = server.Serve(ln) + if err != nil { + log.Fatalf("gRPC serve failed, got %s", err.Error()) + } +} From 2d864d24bca8a27ca69611e904d6c379aae0131f Mon Sep 17 00:00:00 2001 From: Jon Foust Date: Mon, 26 Oct 2020 18:58:01 -0400 Subject: [PATCH 2/2] Updated dockerfile to reflect move from open match core repo to ecosystem repo --- skill-based/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skill-based/Dockerfile b/skill-based/Dockerfile index b9e5ae2..435fd6b 100644 --- a/skill-based/Dockerfile +++ b/skill-based/Dockerfile @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM open-match-base-build as builder +FROM golang:1.15.2 as builder -WORKDIR /go/src/open-match.dev/open-match/examples/functions/golang/skill-based +WORKDIR /go/src/open-match.dev/open-match-ecosystem/skill-based RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o matchfunction . FROM gcr.io/distroless/static:nonroot WORKDIR /app/ -COPY --from=builder --chown=nonroot /go/src/open-match.dev/open-match/examples/functions/golang/skill-based/matchfunction /app/ +COPY --from=builder --chown=nonroot /go/src/open-match.dev/open-match-ecosystem/skill-based/matchfunction /app/ ENTRYPOINT ["/app/matchfunction"]