Skip to content

Commit

Permalink
feat: update operator usange cli command to includes nodes count
Browse files Browse the repository at this point in the history
  • Loading branch information
JadhavPoonam committed Jun 28, 2023
1 parent 54cdccd commit 18ada75
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/operator_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion command/operator/usage/instances/usage_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion command/operator/usage/instances/usage_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions website/content/commands/operator/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ The output looks like this:
```text
$ consul operator usage instances
Billable Service Instances Total: 3
Nodes Total: 1
dc1 Billable Service Instances: 3
dc1 Nodes: 1
Billable Services
Services Service instances
Expand All @@ -64,8 +66,11 @@ With the `-all-datacenters` flag:
```text
$ consul operator usage instances -all-datacenters
Billable Service Instances Total: 4
Nodes Total: 2
dc1 Billable Service Instances: 3
dc1 Nodes: 1
dc2 Billable Service Instances: 1
dc2 Nodes: 1
Billable Services
Datacenter Services Service instances
Expand Down

0 comments on commit 18ada75

Please sign in to comment.