Skip to content

Commit

Permalink
Merge pull request #34 from castaneai/connect-rpc
Browse files Browse the repository at this point in the history
Connect RPC
  • Loading branch information
castaneai authored Nov 7, 2024
2 parents ac28fb7 + 0ea876f commit 30c4416
Show file tree
Hide file tree
Showing 35 changed files with 2,925 additions and 221 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Most of us are game developers, not Kubernetes experts.

## Features

- [x] Open Match compatible Frontend Service (gRPC only)
- [x] Open Match compatible Frontend Service (gRPC, gRPC-Web and [Connect](https://connectrpc.com/docs/protocol/))
- [x] Create/Get/Watch/Delete ticket
- [ ] Backfill
- [x] Run match functions and propose matches
Expand All @@ -38,6 +38,11 @@ And **Assigner** assigns a GameServer info to the established matches.
The following is a minimal code. See [examples/](./examples) for a more actual example.

```go
import (
"github.com/castaneai/minimatch"
pb "github.com/castaneai/minimatch/gen/openmatch"
)

var matchProfile = &pb.MatchProfile{...}

func MakeMatches(ctx context.Context, profile *pb.MatchProfile, poolTickets minimatch.PoolTickets) ([]*pb.Match, error) {
Expand Down Expand Up @@ -81,6 +86,7 @@ import (
"testing"

"github.com/castaneai/minimatch"
pb "github.com/castaneai/minimatch/gen/openmatch"
)

func TestSimpleMatch(t *testing.T) {
Expand Down
64 changes: 64 additions & 0 deletions api/openmatch/frontend.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
syntax = "proto3";

package openmatch;

import "openmatch/messages.proto";
import "google/protobuf/empty.proto";

message CreateTicketRequest {
Ticket ticket = 1;
}

message DeleteTicketRequest {
string ticket_id = 1;
}

message GetTicketRequest {
string ticket_id = 1;
}

message WatchAssignmentsRequest {
string ticket_id = 1;
}

message WatchAssignmentsResponse {
Assignment assignment = 1;
}

message AcknowledgeBackfillRequest {
string backfill_id = 1;
Assignment assignment = 2;
}

message AcknowledgeBackfillResponse {
Backfill backfill = 1;
repeated Ticket tickets = 2;
}

message CreateBackfillRequest {
Backfill backfill = 1;
}

message DeleteBackfillRequest {
string backfill_id = 1;
}

message GetBackfillRequest {
string backfill_id = 1;
}

message UpdateBackfillRequest {
Backfill backfill = 1;
}

service FrontendService {
rpc CreateTicket(CreateTicketRequest) returns (Ticket);
rpc DeleteTicket(DeleteTicketRequest) returns (google.protobuf.Empty);
rpc GetTicket(GetTicketRequest) returns (Ticket);
rpc WatchAssignments(WatchAssignmentsRequest) returns (stream WatchAssignmentsResponse);
rpc AcknowledgeBackfill(AcknowledgeBackfillRequest) returns (AcknowledgeBackfillResponse);
rpc CreateBackfill(CreateBackfillRequest) returns (Backfill);
rpc DeleteBackfill(DeleteBackfillRequest) returns (google.protobuf.Empty);
rpc GetBackfill(GetBackfillRequest) returns (Backfill);
rpc UpdateBackfill(UpdateBackfillRequest) returns (Backfill);
}
92 changes: 92 additions & 0 deletions api/openmatch/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
syntax = "proto3";

package openmatch;

import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";

message Ticket {
string id = 1;
Assignment assignment = 3;
SearchFields search_fields = 4;
map<string, google.protobuf.Any> extensions = 5;
map<string, google.protobuf.Any> persistent_field = 6;
google.protobuf.Timestamp create_time = 7;
reserved 2;
}

message SearchFields {
map<string, double> double_args = 1;
map<string, string> string_args = 2;
repeated string tags = 3;
}

message Assignment {
string connection = 1;
map<string, google.protobuf.Any> extensions = 4;
reserved 2, 3;
}

message DoubleRangeFilter {
string double_arg = 1;
double max = 2;
double min = 3;
enum Exclude {
NONE = 0;
MIN = 1;
MAX = 2;
BOTH = 3;
}
Exclude exclude = 4;
}

message StringEqualsFilter {
string string_arg = 1;
string value = 2;
}

message TagPresentFilter {
string tag = 1;
}

message Pool {
string name = 1;
repeated DoubleRangeFilter double_range_filters = 2;
repeated StringEqualsFilter string_equals_filters = 4;
repeated TagPresentFilter tag_present_filters = 5;
google.protobuf.Timestamp created_before = 6;
google.protobuf.Timestamp created_after = 7;
reserved 3;
}

message MatchProfile {
string name = 1;
repeated Pool pools = 3;
map<string, google.protobuf.Any> extensions = 5;
reserved 2, 4;
}

message Match {
string match_id = 1;
string match_profile = 2;
string match_function = 3;
repeated Ticket tickets = 4;
map<string, google.protobuf.Any> extensions = 7;
Backfill backfill = 8;
bool allocate_gameserver = 9;
reserved 5, 6;
}

message Backfill {
string id = 1;
SearchFields search_fields = 2;
map<string, google.protobuf.Any> extensions = 3;
map<string, google.protobuf.Any> persistent_field = 4;
google.protobuf.Timestamp create_time = 5;
int64 generation = 6;
}

message AssignmentGroup {
repeated string ticket_ids = 1;
Assignment assignment = 2;
}
13 changes: 13 additions & 0 deletions aqua.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# aqua - Declarative CLI Version Manager
# https://aquaproj.github.io/
# checksum:
# enabled: true
# require_checksum: true
# supported_envs:
# - all
registries:
- type: standard
ref: v4.248.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: bufbuild/[email protected]
2 changes: 1 addition & 1 deletion assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package minimatch
import (
"context"

"open-match.dev/open-match/pkg/pb"
pb "github.com/castaneai/minimatch/gen/openmatch"
)

// Assigner assigns a GameServer info to the established matches.
Expand Down
2 changes: 1 addition & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
"golang.org/x/sync/errgroup"
"open-match.dev/open-match/pkg/pb"

pb "github.com/castaneai/minimatch/gen/openmatch"
"github.com/castaneai/minimatch/pkg/statestore"
)

Expand Down
2 changes: 1 addition & 1 deletion backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/bojand/hri"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"open-match.dev/open-match/pkg/pb"

pb "github.com/castaneai/minimatch/gen/openmatch"
"github.com/castaneai/minimatch/pkg/statestore"
)

Expand Down
16 changes: 16 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v2
managed:
enabled: true
override:
- file_option: go_package_prefix
value: github.com/castaneai/minimatch/gen
plugins:
- remote: buf.build/connectrpc/go:v1.17.0
out: gen
opt:
- paths=source_relative
# dependencies
- remote: buf.build/protocolbuffers/go:v1.34.2
out: gen
opt:
- paths=source_relative
10 changes: 10 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
lint:
use:
- STANDARD
breaking:
use:
- FILE
modules:
- path: api
4 changes: 2 additions & 2 deletions charts/minimatch-scaled/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ frontend:
deployment:
replicas: 1
image:
env: {}
env: []
resources: {}
backend:
tickRate: "1s"
deployment:
replicas: 1
image:
env: {}
env: []
resources: {}
podMonitor:
enabled: false
2 changes: 1 addition & 1 deletion evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package minimatch
import (
"context"

"open-match.dev/open-match/pkg/pb"
pb "github.com/castaneai/minimatch/gen/openmatch"
)

type Evaluator interface {
Expand Down
22 changes: 12 additions & 10 deletions examples/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"log"
"testing"

"connectrpc.com/connect"
"github.com/bojand/hri"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"open-match.dev/open-match/pkg/pb"

"github.com/castaneai/minimatch"
pb "github.com/castaneai/minimatch/gen/openmatch"
"github.com/castaneai/minimatch/gen/openmatch/openmatchconnect"
)

var anyProfile = &pb.MatchProfile{
Expand Down Expand Up @@ -39,21 +41,21 @@ func TestMatchmaking(t *testing.T) {
assert.Equal(t, as1.Connection, as2.Connection)
}

func mustCreateTicket(ctx context.Context, t *testing.T, c pb.FrontendServiceClient, ticket *pb.Ticket) *pb.Ticket {
func mustCreateTicket(ctx context.Context, t *testing.T, c openmatchconnect.FrontendServiceClient, ticket *pb.Ticket) *pb.Ticket {
t.Helper()
resp, err := c.CreateTicket(ctx, &pb.CreateTicketRequest{Ticket: ticket})
resp, err := c.CreateTicket(ctx, connect.NewRequest(&pb.CreateTicketRequest{Ticket: ticket}))
require.NoError(t, err)
require.NotEmpty(t, resp.Id)
require.NotNil(t, resp.CreateTime)
return resp
require.NotEmpty(t, resp.Msg.Id)
require.NotNil(t, resp.Msg.CreateTime)
return resp.Msg
}

func mustAssignment(ctx context.Context, t *testing.T, c pb.FrontendServiceClient, ticketID string) *pb.Assignment {
func mustAssignment(ctx context.Context, t *testing.T, c openmatchconnect.FrontendServiceClient, ticketID string) *pb.Assignment {
t.Helper()
resp, err := c.GetTicket(ctx, &pb.GetTicketRequest{TicketId: ticketID})
resp, err := c.GetTicket(ctx, connect.NewRequest(&pb.GetTicketRequest{TicketId: ticketID}))
require.NoError(t, err)
require.NotNil(t, resp.Assignment)
return resp.Assignment
require.NotNil(t, resp.Msg.Assignment)
return resp.Msg.Assignment
}

func dummyAssign(ctx context.Context, matches []*pb.Match) ([]*pb.AssignmentGroup, error) {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple1vs1/simple1vs1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

"github.com/bojand/hri"
"open-match.dev/open-match/pkg/pb"

"github.com/castaneai/minimatch"
pb "github.com/castaneai/minimatch/gen/openmatch"
)

var matchProfile = &pb.MatchProfile{
Expand Down
3 changes: 2 additions & 1 deletion filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"time"

"google.golang.org/protobuf/types/known/timestamppb"
"open-match.dev/open-match/pkg/pb"

pb "github.com/castaneai/minimatch/gen/openmatch"
)

type filteredEntity interface {
Expand Down
Loading

0 comments on commit 30c4416

Please sign in to comment.