diff --git a/pkg/metrics/controller.go b/pkg/metrics/controller.go index 3ca067fc95..f2ac8b4bb7 100644 --- a/pkg/metrics/controller.go +++ b/pkg/metrics/controller.go @@ -241,6 +241,15 @@ func (c *Controller) recordFleetChanges(obj interface{}) { c.recordFleetReplicas(f.Name, f.Namespace, f.Status.Replicas, f.Status.AllocatedReplicas, f.Status.ReadyReplicas, f.Spec.Replicas, f.Status.ReservedReplicas) + + if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) { + if f.Status.Counters != nil { + c.recordCounters(f.Name, f.Namespace, f.Status.Counters) + } + if f.Status.Lists != nil { + c.recordLists(f.Name, f.Namespace, f.Status.Lists) + } + } } func (c *Controller) recordFleetDeletion(obj interface{}) { @@ -317,6 +326,40 @@ func (c *Controller) recordFleetReplicas(fleetName, fleetNamespace string, total fleetsReplicasCountStats.M(int64(reserved))) } +// nolint:dupl // Linter errors on lines are duplicate of recordLists +func (c *Controller) recordCounters(fleetName, fleetNamespace string, counters map[string]agonesv1.AggregatedCounterStatus) { + + ctx, _ := tag.New(context.Background(), tag.Upsert(keyName, fleetName), tag.Upsert(keyNamespace, fleetNamespace)) + + for counter, counterStatus := range counters { + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "allocated_count"), tag.Upsert(keyCounter, counter)}, + fleetCountersStats.M(counterStatus.AllocatedCount)) + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "allocated_capacity"), tag.Upsert(keyCounter, counter)}, + fleetCountersStats.M(counterStatus.AllocatedCapacity)) + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "total_count"), tag.Upsert(keyCounter, counter)}, + fleetCountersStats.M(counterStatus.Count)) + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "total_capacity"), tag.Upsert(keyCounter, counter)}, + fleetCountersStats.M(counterStatus.Capacity)) + } +} + +// nolint:dupl // Linter errors on lines are duplicate of recordCounters +func (c *Controller) recordLists(fleetName, fleetNamespace string, lists map[string]agonesv1.AggregatedListStatus) { + + ctx, _ := tag.New(context.Background(), tag.Upsert(keyName, fleetName), tag.Upsert(keyNamespace, fleetNamespace)) + + for list, listStatus := range lists { + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "allocated_count"), tag.Upsert(keyList, list)}, + fleetListsStats.M(listStatus.AllocatedCount)) + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "allocated_capacity"), tag.Upsert(keyList, list)}, + fleetListsStats.M(listStatus.AllocatedCapacity)) + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "total_count"), tag.Upsert(keyList, list)}, + fleetListsStats.M(listStatus.Count)) + recordWithTags(ctx, []tag.Mutator{tag.Upsert(keyType, "total_capacity"), tag.Upsert(keyList, list)}, + fleetListsStats.M(listStatus.Capacity)) + } +} + // recordGameServerStatusChanged records gameserver status changes, however since it's based // on cache events some events might collapsed and not appear, for example transition state // like creating, port allocation, could be skipped. diff --git a/pkg/metrics/controller_metrics.go b/pkg/metrics/controller_metrics.go index 2ce57877dd..895018249f 100644 --- a/pkg/metrics/controller_metrics.go +++ b/pkg/metrics/controller_metrics.go @@ -28,6 +28,8 @@ const ( fleetAutoscalersDesiredReplicaCountName = "fleet_autoscalers_desired_replicas_count" fleetAutoscalersAbleToScaleName = "fleet_autoscalers_able_to_scale" fleetAutoscalersLimitedName = "fleet_autoscalers_limited" + fleetCountersName = "fleet_counters" + fleetListsName = "fleet_lists" gameServersCountName = "gameservers_count" gameServersTotalName = "gameservers_total" gameServersPlayerConnectedTotalName = "gameserver_player_connected_total" @@ -52,6 +54,8 @@ var ( fasDesiredReplicasStats = stats.Int64("fas/desired_replicas_count", "The desired replicas cout as seen by autoscalers", "1") fasAbleToScaleStats = stats.Int64("fas/able_to_scale", "The fleet autoscaler can access the fleet to scale (0 indicates false, 1 indicates true)", "1") fasLimitedStats = stats.Int64("fas/limited", "The fleet autoscaler is capped (0 indicates false, 1 indicates true)", "1") + fleetCountersStats = stats.Int64("fleets/counters", "Aggregated counts of the Counters across GameServers in the Fleet", "1") + fleetListsStats = stats.Int64("fleets/lists", "Aggregated numbers of items in the Lists across GameServers in the Fleet", "1") gameServerCountStats = stats.Int64("gameservers/count", "The count of gameservers", "1") gameServerTotalStats = stats.Int64("gameservers/total", "The total of gameservers", "1") gameServerPlayerConnectedTotal = stats.Int64("gameservers/player_connected", "The total number of players connected to gameservers", "1") @@ -110,6 +114,20 @@ var ( Aggregation: view.LastValue(), TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace}, }, + { + Name: fleetCountersName, + Measure: fleetCountersStats, + Description: "Aggregated counts of the Counters across GameServers in the Fleet", + Aggregation: view.LastValue(), + TagKeys: []tag.Key{keyName, keyType, keyFleetName, keyNamespace, keyCounter}, + }, + { + Name: fleetListsName, + Measure: fleetListsStats, + Description: "Aggregated numbers of items in the Lists across GameServers in the Fleet", + Aggregation: view.LastValue(), + TagKeys: []tag.Key{keyName, keyType, keyFleetName, keyNamespace, keyList}, + }, { Name: gameServersCountName, Measure: gameServerCountStats, diff --git a/pkg/metrics/util.go b/pkg/metrics/util.go index 8cdc85e889..43fa524c24 100644 --- a/pkg/metrics/util.go +++ b/pkg/metrics/util.go @@ -38,6 +38,8 @@ var ( keyVerb = MustTagKey("verb") keyEndpoint = MustTagKey("endpoint") keyEmpty = MustTagKey("empty") + keyCounter = MustTagKey("counter") + keyList = MustTagKey("list") ) func recordWithTags(ctx context.Context, mutators []tag.Mutator, ms ...stats.Measurement) {