diff --git a/examples/allocator-client/main.go b/examples/allocator-client/main.go index 23cb3bf99a..73512ba600 100644 --- a/examples/allocator-client/main.go +++ b/examples/allocator-client/main.go @@ -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() { @@ -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{ diff --git a/pkg/gameserverallocations/allocator.go b/pkg/gameserverallocations/allocator.go index d0699514f0..72567ae72a 100644 --- a/pkg/gameserverallocations/allocator.go +++ b/pkg/gameserverallocations/allocator.go @@ -20,6 +20,7 @@ import ( "crypto/x509" goErrors "errors" "fmt" + "log" "strings" "time" @@ -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" @@ -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 diff --git a/pkg/gameserverallocations/metrics.go b/pkg/gameserverallocations/metrics.go index 64fb4d50ec..142621c122 100644 --- a/pkg/gameserverallocations/metrics.go +++ b/pkg/gameserverallocations/metrics.go @@ -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() { @@ -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 { diff --git a/pkg/metrics/controller_metrics.go b/pkg/metrics/controller_metrics.go index 605e8c7a75..cbaf17093d 100644 --- a/pkg/metrics/controller_metrics.go +++ b/pkg/metrics/controller_metrics.go @@ -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") diff --git a/tmp/allocate.sh b/tmp/allocate.sh index 0b0d11c3ba..719179ae28 100644 --- a/tmp/allocate.sh +++ b/tmp/allocate.sh @@ -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 \ diff --git a/tmp/fleet.yaml b/tmp/fleet.yaml index 621cdb37a4..3593edaecc 100644 --- a/tmp/fleet.yaml +++ b/tmp/fleet.yaml @@ -17,7 +17,7 @@ kind: Fleet metadata: name: simple-game-server spec: - replicas: 300 + replicas: 100 template: metadata: labels: @@ -26,9 +26,6 @@ spec: ports: - name: default containerPort: 7654 - counters: - players: - capacity: 300 template: spec: containers: