From 1902a23b8679891e341547fc5e35dfbcaabea0a6 Mon Sep 17 00:00:00 2001 From: Poonam Jadhav Date: Wed, 28 Jun 2023 16:37:44 -0400 Subject: [PATCH] feat: update operator usange cli command to includes nodes count --- api/operator_usage.go | 1 + command/operator/usage/instances/usage_instances.go | 6 +++++- command/operator/usage/instances/usage_instances_test.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/operator_usage.go b/api/operator_usage.go index e47d4b53e037a..8977449ddd361 100644 --- a/api/operator_usage.go +++ b/api/operator_usage.go @@ -10,6 +10,7 @@ type Usage struct { // ServiceUsage contains information about the number of services and service instances for a datacenter. type ServiceUsage struct { + Nodes int Services int ServiceInstances int ConnectServiceInstances map[string]int diff --git a/command/operator/usage/instances/usage_instances.go b/command/operator/usage/instances/usage_instances.go index 5e8dba201ce87..615771e21bfad 100644 --- a/command/operator/usage/instances/usage_instances.go +++ b/command/operator/usage/instances/usage_instances.go @@ -72,6 +72,7 @@ func (c *cmd) Run(args []string) int { } billableTotal := 0 + nodesTotal := 0 var datacenterBillableTotals []string usage, _, err := client.Operator().Usage(&api.QueryOptions{Global: c.allDatacenters}) if err != nil { @@ -80,13 +81,16 @@ func (c *cmd) Run(args []string) int { } for dc, usage := range usage.Usage { billableTotal += usage.BillableServiceInstances + nodesTotal += usage.Nodes datacenterBillableTotals = append(datacenterBillableTotals, - fmt.Sprintf("%s Billable Service Instances: %d", dc, usage.BillableServiceInstances)) + fmt.Sprintf("%s Billable Service Instances: %d", dc, usage.BillableServiceInstances), + fmt.Sprintf("%s Nodes: %d", dc, usage.Nodes)) } // Output billable service counts if !c.onlyConnect { c.UI.Output(fmt.Sprintf("Billable Service Instances Total: %d", billableTotal)) + c.UI.Output(fmt.Sprintf("Nodes Total: %d", nodesTotal)) sort.Strings(datacenterBillableTotals) for _, datacenterTotal := range datacenterBillableTotals { c.UI.Output(datacenterTotal) diff --git a/command/operator/usage/instances/usage_instances_test.go b/command/operator/usage/instances/usage_instances_test.go index 8ad38e1b0c53a..094f07dbfc3ff 100644 --- a/command/operator/usage/instances/usage_instances_test.go +++ b/command/operator/usage/instances/usage_instances_test.go @@ -48,7 +48,7 @@ func TestUsageInstancesCommand(t *testing.T) { }{ { name: "basic output", - output: "Billable Service Instances Total: 2", + output: "Billable Service Instances Total: 2\nNodes Total: 1\ndc1 Billable Service Instances: 2\ndc1 Nodes: 1", }, { name: "billable and connect flags together are invalid",