mirror of
https://github.com/googleforgames/open-match.git
synced 2025-03-29 22:44:20 +00:00
Fix most of the lint errors from golangci. (#243)
This commit is contained in:
internal
app
backendapi/apisrv
frontendapi/apisrv
mmforc
mmlogicapi/apisrv
statestorage/redis
site
test
cmd
e2e
@ -25,6 +25,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/GoogleCloudPlatform/open-match/config"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/expbo"
|
||||
"github.com/GoogleCloudPlatform/open-match/internal/pb"
|
||||
@ -241,11 +243,6 @@ func (s *backendAPI) ListMatches(req *pb.ListMatchesRequest, matchStream pb.Back
|
||||
default:
|
||||
// Retreive results from Redis
|
||||
requestProfile := proto.Clone(p).(*pb.MatchObject)
|
||||
/*
|
||||
beLog.Debug("new profile requested!")
|
||||
beLog.Debug(requestProfile)
|
||||
beLog.Debug(&requestProfile)
|
||||
*/
|
||||
mo, err := s.CreateMatch(ctx, &pb.CreateMatchRequest{
|
||||
Match: requestProfile,
|
||||
})
|
||||
@ -258,9 +255,12 @@ func (s *backendAPI) ListMatches(req *pb.ListMatchesRequest, matchStream pb.Back
|
||||
}
|
||||
beLog.WithFields(log.Fields{"matchProperties": fmt.Sprintf("%v", mo)}).Debug("Streaming back match object")
|
||||
res := proto.Clone(mo.Match).(*pb.MatchObject)
|
||||
matchStream.Send(&pb.ListMatchesResponse{
|
||||
err = matchStream.Send(&pb.ListMatchesResponse{
|
||||
Match: res,
|
||||
})
|
||||
if err != nil {
|
||||
return status.Error(codes.Internal, errors.WithStack(err).Error())
|
||||
}
|
||||
|
||||
// TODO: This should be tunable, but there should be SOME sleep here, to give a requestor a window
|
||||
// to cleanly close the connection after receiving a match object when they know they don't want to
|
||||
@ -306,8 +306,8 @@ func (s *backendAPI) CreateAssignments(ctx context.Context, req *pb.CreateAssign
|
||||
beLog := s.logger
|
||||
|
||||
// Make a map of players and what assignments we want to send them.
|
||||
playerIDs := make([]string, 0)
|
||||
players := make(map[string]string, 0)
|
||||
playerIDs := []string{}
|
||||
players := map[string]string{}
|
||||
for _, roster := range a.Rosters { // Loop through all rosters
|
||||
for _, player := range roster.Players { // Loop through all players in this roster
|
||||
if player.Id != "" {
|
||||
@ -337,9 +337,6 @@ func (s *backendAPI) CreateAssignments(ctx context.Context, req *pb.CreateAssign
|
||||
// Send the players their assignments.
|
||||
err := redishelpers.UpdateMultiFields(ctx, s.pool, players, "assignment")
|
||||
|
||||
// Move these players from the proposed list to the deindexed list.
|
||||
ignorelist.Move(ctx, s.pool, playerIDs, "proposed", "deindexed")
|
||||
|
||||
// Issue encountered
|
||||
if err != nil {
|
||||
beLog.WithFields(log.Fields{
|
||||
@ -350,6 +347,19 @@ func (s *backendAPI) CreateAssignments(ctx context.Context, req *pb.CreateAssign
|
||||
stats.Record(fnCtx, BeAssignmentFailures.M(int64(len(players))))
|
||||
return nil, status.Error(codes.Unknown, err.Error())
|
||||
}
|
||||
// Move these players from the proposed list to the deindexed list.
|
||||
err = ignorelist.Move(ctx, s.pool, playerIDs, "proposed", "deindexed")
|
||||
|
||||
// Issue encountered
|
||||
if err != nil {
|
||||
beLog.WithFields(log.Fields{
|
||||
"error": err.Error(),
|
||||
"component": "ignorelist",
|
||||
}).Error("Error moving player to ignore list")
|
||||
|
||||
stats.Record(fnCtx, BeAssignmentFailures.M(int64(len(players))))
|
||||
return nil, status.Error(codes.Unknown, err.Error())
|
||||
}
|
||||
|
||||
// Success!
|
||||
beLog.WithFields(log.Fields{
|
||||
@ -396,7 +406,7 @@ func (s *backendAPI) DeleteAssignments(ctx context.Context, req *pb.DeleteAssign
|
||||
// getPlayerIdsFromRoster returns the slice of player ID strings contained in
|
||||
// the input roster.
|
||||
func getPlayerIdsFromRoster(r *pb.Roster) []string {
|
||||
playerIDs := make([]string, 0)
|
||||
playerIDs := []string{}
|
||||
for _, p := range r.Players {
|
||||
playerIDs = append(playerIDs, p.Id)
|
||||
}
|
||||
|
@ -78,12 +78,6 @@ var (
|
||||
KeySeverity, _ = tag.NewKey("severity")
|
||||
)
|
||||
|
||||
var (
|
||||
// Latency in buckets:
|
||||
// [>=0ms, >=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, >=1s, >=2s, >=4s, >=6s]
|
||||
latencyDistribution = view.Distribution(0, 25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000, 6000)
|
||||
)
|
||||
|
||||
// Package metrics provides some convience views.
|
||||
// You need to register the views for the data to actually be collected.
|
||||
// Note: The OpenCensus View 'Description' is exported to Prometheus as the HELP string.
|
||||
|
@ -67,16 +67,11 @@ var (
|
||||
|
||||
var (
|
||||
// KeyMethod is used to tag a measure with the currently running API method.
|
||||
KeyMethod, _ = tag.NewKey("method")
|
||||
KeyMethod, _ = tag.NewKey("method")
|
||||
// KeySeverity is used to tag a the severity of a log message.
|
||||
KeySeverity, _ = tag.NewKey("severity")
|
||||
)
|
||||
|
||||
var (
|
||||
// Latency in buckets:
|
||||
// [>=0ms, >=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, >=1s, >=2s, >=4s, >=6s]
|
||||
latencyDistribution = view.Distribution(0, 25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000, 6000)
|
||||
)
|
||||
|
||||
// Package metrics provides some convience views.
|
||||
// You need to register the views for the data to actually be collected.
|
||||
// Note: The OpenCensus View 'Description' is exported to Prometheus as the HELP string.
|
||||
|
@ -587,4 +587,3 @@ func submitJob(cfg config.View, clientset *kubernetes.Clientset, jobType string,
|
||||
|
||||
// readability functions used by generateJobSpec
|
||||
func int32Ptr(i int32) *int32 { return &i }
|
||||
func strPtr(i string) *string { return &i }
|
||||
|
@ -353,7 +353,6 @@ func (s *mmlogicAPI) GetPlayerPool(req *pb.GetPlayerPoolRequest, stream pb.MmLog
|
||||
func (s *mmlogicAPI) applyFilter(c context.Context, filter *pb.Filter) (map[string]int64, error) {
|
||||
mlLog := s.logger
|
||||
|
||||
type pName string
|
||||
pool := make(map[string]int64)
|
||||
|
||||
// Default maximum value is positive infinity (i.e. highest possible number in redis)
|
||||
|
@ -71,12 +71,6 @@ var (
|
||||
KeySeverity, _ = tag.NewKey("severity")
|
||||
)
|
||||
|
||||
var (
|
||||
// Latency in buckets:
|
||||
// [>=0ms, >=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, >=1s, >=2s, >=4s, >=6s]
|
||||
latencyDistribution = view.Distribution(0, 25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000, 6000)
|
||||
)
|
||||
|
||||
// Package metrics provides some convience views.
|
||||
// You need to register the views for the data to actually be collected.
|
||||
// Note: The OpenCensus View 'Description' is exported to Prometheus as the HELP string.
|
||||
|
@ -183,14 +183,6 @@ func Retrieve(redisConn redis.Conn, cfg config.View, il string) ([]string, error
|
||||
return results, err
|
||||
}
|
||||
|
||||
func retrieve(redisConn redis.Conn, ignorelistID string, from int64, until int64) ([]string, error) {
|
||||
cmd := "ZRANGEBYSCORE"
|
||||
|
||||
// ignorelists are sorted sets with scores set to epoch timestamps (in seconds)
|
||||
results, err := redis.Strings(redisConn.Do(cmd, ignorelistID, from, until))
|
||||
return results, err
|
||||
}
|
||||
|
||||
// buildElemmentValueLIst builds an array of strings to send to the redis commad.
|
||||
// ZADD expects values (in this case we will use epoch timestamps) followed by
|
||||
// an element (we will use player IDs).
|
||||
|
@ -140,8 +140,6 @@ func Create(ctx context.Context, pool *redis.Pool, key string, values map[string
|
||||
|
||||
// Get a connection to redis
|
||||
redisConn, err := pool.GetContext(ctx)
|
||||
defer redisConn.Close()
|
||||
|
||||
// Encountered an issue getting a connection from the pool.
|
||||
if err != nil {
|
||||
cLog.WithFields(log.Fields{
|
||||
@ -150,6 +148,8 @@ func Create(ctx context.Context, pool *redis.Pool, key string, values map[string
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer redisConn.Close()
|
||||
|
||||
// Build command arguments.
|
||||
cmdArgs := make([]interface{}, 0)
|
||||
cmdArgs = append(cmdArgs, key)
|
||||
@ -173,7 +173,6 @@ func Retrieve(ctx context.Context, pool *redis.Pool, key string) (string, error)
|
||||
|
||||
// Get a connection to redis
|
||||
redisConn, err := pool.GetContext(ctx)
|
||||
defer redisConn.Close()
|
||||
|
||||
// Encountered an issue getting a connection from the pool.
|
||||
if err != nil {
|
||||
@ -182,6 +181,7 @@ func Retrieve(ctx context.Context, pool *redis.Pool, key string) (string, error)
|
||||
"query": cmd}).Error("state storage connection error")
|
||||
return "", err
|
||||
}
|
||||
defer redisConn.Close()
|
||||
|
||||
// Run redis query and return
|
||||
return redis.String(redisConn.Do(cmd, key))
|
||||
@ -203,7 +203,6 @@ func RetrieveField(ctx context.Context, pool *redis.Pool, key string, field stri
|
||||
|
||||
// Get a connection to redis
|
||||
redisConn, err := pool.GetContext(ctx)
|
||||
defer redisConn.Close()
|
||||
|
||||
// Encountered an issue getting a connection from the pool.
|
||||
if err != nil {
|
||||
@ -212,6 +211,7 @@ func RetrieveField(ctx context.Context, pool *redis.Pool, key string, field stri
|
||||
}).Error("state storage connection error")
|
||||
return "", err
|
||||
}
|
||||
defer redisConn.Close()
|
||||
|
||||
// Run redis query and return
|
||||
cLog.Debug("state storage operation")
|
||||
|
@ -119,13 +119,10 @@ func Watcher(bo backoff.BackOffContext, pool *redis.Pool, pb om_messages.MatchOb
|
||||
go func() {
|
||||
defer close(watchChan)
|
||||
|
||||
// var declaration
|
||||
var err = errors.New("haven't queried Redis yet")
|
||||
|
||||
// Loop, querying redis until this key has a value
|
||||
for {
|
||||
results = om_messages.MatchObject{Id: pb.Id}
|
||||
err = UnmarshalFromRedis(bo.Context(), pool, &results)
|
||||
err := UnmarshalFromRedis(bo.Context(), pool, &results)
|
||||
if err == nil {
|
||||
// Return value retreived from Redis asynchonously and tell calling function we're done
|
||||
moLog.Debug("state storage watched record update detected")
|
||||
|
@ -85,7 +85,6 @@ func MarshalToRedis(ctx context.Context, pool *redis.Pool, pb proto.Message, ttl
|
||||
|
||||
// Get the Redis connection.
|
||||
redisConn, err := pool.GetContext(context.Background())
|
||||
defer redisConn.Close()
|
||||
if err != nil {
|
||||
sLog.WithFields(log.Fields{
|
||||
"error": err.Error(),
|
||||
@ -93,6 +92,7 @@ func MarshalToRedis(ctx context.Context, pool *redis.Pool, pb proto.Message, ttl
|
||||
}).Error("failed to connect to redis")
|
||||
return err
|
||||
}
|
||||
defer redisConn.Close()
|
||||
redisConn.Send("MULTI")
|
||||
|
||||
// Write all non-id fields from the protobuf message to state storage.
|
||||
@ -104,14 +104,10 @@ func MarshalToRedis(ctx context.Context, pool *redis.Pool, pb proto.Message, ttl
|
||||
//field := strings.ToLower(pbInfo.Type().Field(i).Tag.Get("json"))
|
||||
field := strings.ToLower(pbInfo.Type().Field(i).Name)
|
||||
value := ""
|
||||
//value, err = strconv.Unquote(gjson.Get(jsonMsg, field).String())
|
||||
value = gjson.Get(jsonMsg, field).String()
|
||||
if err != nil {
|
||||
resultLog.Error("Issue with Unquoting string", err)
|
||||
}
|
||||
if field != "id" {
|
||||
// This isn't the ID field, so write it to the redis hash.
|
||||
redisConn.Send(cmd, key, field, value)
|
||||
err = redisConn.Send(cmd, key, field, value)
|
||||
if err != nil {
|
||||
resultLog.WithFields(log.Fields{
|
||||
"error": err.Error(),
|
||||
@ -125,7 +121,6 @@ func MarshalToRedis(ctx context.Context, pool *redis.Pool, pb proto.Message, ttl
|
||||
"field": field,
|
||||
"value": value,
|
||||
}).Info("State storage operation")
|
||||
|
||||
}
|
||||
}
|
||||
if ttl > 0 {
|
||||
|
@ -125,10 +125,6 @@ func TestHandler(t *testing.T) {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("%s: status code = %s; want 200 OK", test.name, resp.Status)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("%s: ioutil.ReadAll: %v", test.name, err)
|
||||
continue
|
||||
}
|
||||
if got := findMeta(data, "go-import"); got != test.goImport {
|
||||
t.Errorf("%s: meta go-import = %q; want %q", test.name, got, test.goImport)
|
||||
}
|
||||
|
@ -32,12 +32,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
seed = rand.NewSource(time.Now().UnixNano())
|
||||
random = rand.New(seed)
|
||||
percents = make([]float64, 0)
|
||||
cities = make([]string, 0)
|
||||
pingStats = map[string]map[string]map[string]float64{}
|
||||
pingFiles, err = filepath.Glob("*.ping")
|
||||
seed = rand.NewSource(time.Now().UnixNano())
|
||||
random = rand.New(seed)
|
||||
percents = []float64{}
|
||||
cities = []string{}
|
||||
pingStats = map[string]map[string]map[string]float64{}
|
||||
)
|
||||
|
||||
func check(err error) {
|
||||
@ -83,6 +82,10 @@ func pingToFloat(s string) float64 {
|
||||
|
||||
// New initializes a new player generator
|
||||
func New() {
|
||||
pingFiles, err := filepath.Glob("*.ping")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
percentFile, err := os.Open("city.percent")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -110,14 +113,14 @@ func New() {
|
||||
defer pingFile.Close()
|
||||
|
||||
// Init map for this region
|
||||
pingStats[region] = make(map[string]map[string]float64)
|
||||
pingStats[region] = map[string]map[string]float64{}
|
||||
|
||||
scanner = bufio.NewScanner(pingFile)
|
||||
for scanner.Scan() {
|
||||
words := strings.Split(scanner.Text(), "\t")
|
||||
wl := len(words)
|
||||
city := words[0]
|
||||
pingStats[region][city] = make(map[string]float64)
|
||||
pingStats[region][city] = map[string]float64{}
|
||||
cur := pingStats[region][city]
|
||||
cur["avg"] = pingToFloat(words[wl-6])
|
||||
cur["min"] = pingToFloat(words[wl-4])
|
||||
@ -125,8 +128,6 @@ func New() {
|
||||
cur["std"] = pingToFloat(words[wl-2])
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Generate a player
|
||||
@ -136,8 +137,8 @@ func New() {
|
||||
func Generate() (Xid string, properties map[string]int, debug map[string]string) {
|
||||
//return Xid, properties, debug
|
||||
Xid = xid.New().String()
|
||||
properties = make(map[string]int)
|
||||
debug = make(map[string]string)
|
||||
properties = map[string]int{}
|
||||
debug = map[string]string{}
|
||||
|
||||
city := pick()
|
||||
debug["city"] = city
|
||||
|
@ -23,26 +23,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gomodule/redigo/redis"
|
||||
)
|
||||
|
||||
func indicesMap(results []string) interface{} {
|
||||
indices := make(map[string][]string)
|
||||
for _, iName := range results {
|
||||
field := strings.Split(iName, ":")
|
||||
indices[field[0]] = append(indices[field[0]], field[1])
|
||||
}
|
||||
return indices
|
||||
}
|
||||
|
||||
// PlayerIndices retrieves available indices for player parameters.
|
||||
func playerIndices(redisConn redis.Conn) (results []string, err error) {
|
||||
results, err = redis.Strings(redisConn.Do("SMEMBERS", "indices"))
|
||||
return
|
||||
}
|
||||
|
||||
// Create adds a player's JSON representation to the current matchmaker state storage,
|
||||
// and indexes all fields in that player's JSON object. All values in the JSON should be integers.
|
||||
// Example:
|
||||
@ -117,7 +101,7 @@ func Delete(redisConn redis.Conn, playerID string) (err error) {
|
||||
func Unindex(redisConn redis.Conn, playerID string) (err error) {
|
||||
results, err := Retrieve(redisConn, playerID)
|
||||
if err != nil {
|
||||
log.Println("couldn't retreive player properties for ", playerID)
|
||||
log.Printf("couldn't retreive player properties for %v, %s\n", playerID, err)
|
||||
}
|
||||
|
||||
redisConn.Send("MULTI")
|
||||
|
@ -97,10 +97,10 @@ func main() {
|
||||
|
||||
// Var init
|
||||
players[i] = &pb.Player{}
|
||||
playerData := make(map[string]interface{})
|
||||
|
||||
// Generate a new player
|
||||
players[i].Id, playerData = player.Generate()
|
||||
newPlayerID, playerData := player.Generate()
|
||||
players[i].Id = newPlayerID
|
||||
players[i].Properties = playerDataToJSONString(playerData)
|
||||
|
||||
// Start watching for results for this player (assignment/status/error)
|
||||
@ -168,8 +168,6 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func waitForQuit(quitChan chan<- bool) {
|
||||
|
@ -31,12 +31,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
seed = rand.NewSource(time.Now().UnixNano())
|
||||
random = rand.New(seed)
|
||||
percents = make([]float64, 0)
|
||||
cities = make([]string, 0)
|
||||
pingStats = map[string]map[string]map[string]float64{}
|
||||
pingFiles, err = filepath.Glob("*.ping")
|
||||
seed = rand.NewSource(time.Now().UnixNano())
|
||||
random = rand.New(seed)
|
||||
percents = []float64{}
|
||||
cities = []string{}
|
||||
pingStats = map[string]map[string]map[string]float64{}
|
||||
)
|
||||
|
||||
func check(err error) {
|
||||
@ -82,6 +81,10 @@ func pingToFloat(s string) float64 {
|
||||
|
||||
// New initializes a new player generator
|
||||
func New() {
|
||||
pingFiles, err := filepath.Glob("*.ping")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
percentFile, err := os.Open("city.percent")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -109,14 +112,14 @@ func New() {
|
||||
defer pingFile.Close()
|
||||
|
||||
// Init map for this region
|
||||
pingStats[region] = make(map[string]map[string]float64)
|
||||
pingStats[region] = map[string]map[string]float64{}
|
||||
|
||||
scanner = bufio.NewScanner(pingFile)
|
||||
for scanner.Scan() {
|
||||
words := strings.Split(scanner.Text(), "\t")
|
||||
wl := len(words)
|
||||
city := words[0]
|
||||
pingStats[region][city] = make(map[string]float64)
|
||||
pingStats[region][city] = map[string]float64{}
|
||||
cur := pingStats[region][city]
|
||||
cur["avg"] = pingToFloat(words[wl-6])
|
||||
cur["min"] = pingToFloat(words[wl-4])
|
||||
@ -124,20 +127,8 @@ func New() {
|
||||
cur["std"] = pingToFloat(words[wl-2])
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
f = map[string]interface{}{
|
||||
"Name": "Wednesday",
|
||||
"Age": 6,
|
||||
"Parents": []interface{}{
|
||||
"Gomez",
|
||||
"Morticia",
|
||||
},
|
||||
}*/
|
||||
|
||||
// Generate a player
|
||||
// For PoC, we're flattening the JSON so it can be easily indexed in Redis.
|
||||
// Flattened keys are joined using periods.
|
||||
@ -146,10 +137,10 @@ func Generate() (string, map[string]interface{}) {
|
||||
|
||||
id := xid.New().String()
|
||||
city := pick()
|
||||
properties := make(map[string]interface{})
|
||||
properties := map[string]interface{}{}
|
||||
|
||||
// Generate some fake latencies
|
||||
regions := make(map[string]int)
|
||||
regions := map[string]int{}
|
||||
for region := range pingStats {
|
||||
//fmt.Print(region, " ")
|
||||
regions[region] = normalDist(
|
||||
|
@ -13,8 +13,14 @@ func TestFrontendStartup(t *testing.T) {
|
||||
mm, closer, err := omTesting.NewMiniMatch([]*serving.ServerParams{
|
||||
frontendapi.CreateServerParams(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("cannot create mini match server, %s", err)
|
||||
}
|
||||
defer closer()
|
||||
mm.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("cannot start mini match server, %s", err)
|
||||
}
|
||||
defer mm.Stop()
|
||||
|
||||
feClient, err := mm.GetFrontendClient()
|
||||
|
@ -15,8 +15,14 @@ import (
|
||||
|
||||
func TestMinimatchStartup(t *testing.T) {
|
||||
mm, closer, err := omTesting.NewMiniMatch(minimatch.CreateServerParams())
|
||||
if err != nil {
|
||||
t.Fatalf("cannot create mini match server, %s", err)
|
||||
}
|
||||
defer closer()
|
||||
mm.Start()
|
||||
err = mm.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("cannot start mini match server, %s", err)
|
||||
}
|
||||
defer mm.Stop()
|
||||
|
||||
feClient, err := mm.GetFrontendClient()
|
||||
|
Reference in New Issue
Block a user