Skip to content

Commit

Permalink
Removes Player Counter from the example fleet and game server allocation
Browse files Browse the repository at this point in the history
and reates a metric to track the number of times a game server has been allocated. This is to diagnose if the
problem is with the allocator, or with the Counter
  • Loading branch information
igooch committed Dec 19, 2024
1 parent c917986 commit d6bee84
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
17 changes: 0 additions & 17 deletions examples/allocator-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/protobuf/types/known/wrapperspb"
)

func main() {
Expand Down Expand Up @@ -62,28 +61,12 @@ func main() {
MatchLabels: map[string]string{
"version": "1.2.3",
},
Counters: map[string]*pb.CounterSelector{
"players": {
MinAvailable: 1,
},
},
},
{
GameServerState: pb.GameServerSelector_READY,
MatchLabels: map[string]string{
"version": "1.2.3",
},
Counters: map[string]*pb.CounterSelector{
"players": {
MinAvailable: 1,
},
},
},
},
Counters: map[string]*pb.CounterAction{
"players": {
Action: wrapperspb.String("Increment"),
Amount: wrapperspb.Int64(1),
},
},
MultiClusterSetting: &pb.MultiClusterSetting{
Expand Down
14 changes: 14 additions & 0 deletions pkg/gameserverallocations/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/x509"
goErrors "errors"
"fmt"
"log"
"strings"
"time"

Expand All @@ -37,6 +38,7 @@ import (
"agones.dev/agones/pkg/util/runtime"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"go.opencensus.io/stats"
"go.opencensus.io/tag"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -464,6 +466,18 @@ func (c *Allocator) allocate(ctx context.Context, gsa *allocationv1.GameServerAl

select {
case res := <-req.response: // wait for the batch to be completed
if res.err == nil && res.gs != nil {
ctx, err := tag.New(
ctx,
tag.Upsert(keyFleetName, res.gs.GetObjectMeta().GetLabels()[agonesv1.FleetNameLabel]),
tag.Upsert(keyName, res.gs.GetName()),
tag.Upsert(keyNamespace, res.gs.GetNamespace()),
)
if err != nil {
log.Fatal("Could not create tag", err)
}
stats.Record(ctx, gameServerAllocationsCount.M(1))
}
return res.gs, res.err
case <-ctx.Done():
return nil, ErrTotalTimeoutExceeded
Expand Down
14 changes: 14 additions & 0 deletions pkg/gameserverallocations/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ var (
keyMultiCluster = mt.MustTagKey("is_multicluster")
keyStatus = mt.MustTagKey("status")
keySchedulingStrategy = mt.MustTagKey("scheduling_strategy")
keyName = mt.MustTagKey("name")
keyNamespace = mt.MustTagKey("namespace")

gameServerAllocationsLatency = stats.Float64("gameserver_allocations/latency", "The duration of gameserver allocations", "s")
gameServerAllocationsRetryTotal = stats.Int64("gameserver_allocations/errors", "The errors of gameserver allocations", "1")
gameServerAllocationsCount = stats.Int64(
"gameserver_allocations/count",
"The total number of times a Game Server has been allocated.",
"1",
)
)

func init() {
Expand All @@ -61,6 +68,13 @@ func init() {
Aggregation: view.Distribution(1, 2, 3, 4, 5),
TagKeys: []tag.Key{keyFleetName, keyClusterName, keyMultiCluster, keyStatus, keySchedulingStrategy},
},
{
Name: "gameserver_allocations_count",
Measure: gameServerAllocationsCount,
Description: "The number of times a game server is allocated",
Aggregation: view.Count(),
TagKeys: []tag.Key{keyFleetName, keyName, keyNamespace},
},
}

for _, v := range stateViews {
Expand Down
10 changes: 7 additions & 3 deletions pkg/metrics/controller_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ const (

var (
// fleetAutoscalerViews are metric views associated with FleetAutoscalers
fleetAutoscalerViews = []string{fleetAutoscalerBufferLimitName, fleetAutoscalterBufferSizeName, fleetAutoscalerCurrentReplicaCountName,
fleetAutoscalersDesiredReplicaCountName, fleetAutoscalersAbleToScaleName, fleetAutoscalersLimitedName}
fleetAutoscalerViews = []string{fleetAutoscalerBufferLimitName, fleetAutoscalterBufferSizeName,
fleetAutoscalerCurrentReplicaCountName, fleetAutoscalersDesiredReplicaCountName,
fleetAutoscalersAbleToScaleName, fleetAutoscalersLimitedName}
// fleetViews are metric views associated with Fleets
fleetViews = append([]string{fleetRolloutPercent, fleetReplicaCountName, gameServersCountersName, gameServersCountName, gameServersTotalName, gameServersPlayerConnectedTotalName, gameServersPlayerCapacityTotalName, gameServerStateDurationName, fleetCountersName, fleetListsName}, fleetAutoscalerViews...)
fleetViews = append([]string{fleetRolloutPercent, fleetReplicaCountName, gameServersCountersName,
gameServersCountName, gameServersTotalName, gameServersPlayerConnectedTotalName,
gameServersPlayerCapacityTotalName, gameServerStateDurationName, fleetCountersName,
fleetListsName}, fleetAutoscalerViews...)

stateDurationSeconds = []float64{0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384}
fleetRolloutPercentStats = stats.Int64("fleets/rollout_percent", "The current fleet rollout percentage", "1")
Expand Down
2 changes: 1 addition & 1 deletion tmp/allocate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TLS_CA_FILE=ca.crt

echo "Starting go runs"

for _ in {1..10000}; do
for _ in {1..1000}; do
go run ../examples/allocator-client/main.go \
--ip "${EXTERNAL_IP}" \
--port 443 \
Expand Down
5 changes: 1 addition & 4 deletions tmp/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kind: Fleet
metadata:
name: simple-game-server
spec:
replicas: 300
replicas: 100
template:
metadata:
labels:
Expand All @@ -26,9 +26,6 @@ spec:
ports:
- name: default
containerPort: 7654
counters:
players:
capacity: 300
template:
spec:
containers:
Expand Down

0 comments on commit d6bee84

Please sign in to comment.