Skip to content

Commit a60217e

Browse files
committed
feat: add ready indicator to cf app command
CC version 3.144.0 introduced readiness checks and with them a new status field for processes: routable. This commit exposes that new field in the `cf app` command to allow users to easily determine the state of their application instances. See: https://github.com/cloudfoundry/capi-release/releases/tag/1.158.0
1 parent fcd2cbc commit a60217e

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

api/cloudcontroller/ccv3/process_instance.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type ProcessInstance struct {
4040
LogRate uint64
4141
// State is the state of the instance.
4242
State constant.ProcessInstanceState
43+
// Routeable is the readiness state of the instance, can be true, false or null.
44+
Routable *bool
4345
// Type is the process type for the instance.
4446
Type string
4547
// Uptime is the duration that the instance has been running.
@@ -56,6 +58,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
5658
MemQuota uint64 `json:"mem_quota"`
5759
LogRateLimit int64 `json:"log_rate_limit"`
5860
State string `json:"state"`
61+
Routable *bool `json:"routable"`
5962
Type string `json:"type"`
6063
Uptime int64 `json:"uptime"`
6164
Usage struct {
@@ -84,6 +87,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
8487
instance.LogRateLimit = inputInstance.LogRateLimit
8588
instance.LogRate = inputInstance.Usage.LogRate
8689
instance.State = constant.ProcessInstanceState(inputInstance.State)
90+
instance.Routable = inputInstance.Routable
8791
instance.Type = inputInstance.Type
8892
instance.Uptime, err = time.ParseDuration(fmt.Sprintf("%ds", inputInstance.Uptime))
8993
if err != nil {

command/v7/shared/app_summary_displayer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ func formatCPUEntitlement(cpuEntitlement types.NullFloat64) string {
8080
return fmt.Sprintf("%.1f%%", cpuEntitlement.Value*100)
8181
}
8282

83+
func formatRoutable(b *bool) string {
84+
if b == nil {
85+
return "-"
86+
}
87+
88+
return fmt.Sprintf("%t", *b)
89+
}
90+
8391
func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7action.ProcessSummary) {
8492
table := [][]string{
8593
{
8694
"",
8795
display.UI.TranslateText("state"),
8896
display.UI.TranslateText("since"),
97+
display.UI.TranslateText("ready"),
8998
display.UI.TranslateText("cpu"),
9099
display.UI.TranslateText("memory"),
91100
display.UI.TranslateText("disk"),
@@ -100,6 +109,7 @@ func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7act
100109
fmt.Sprintf("#%d", instance.Index),
101110
display.UI.TranslateText(strings.ToLower(string(instance.State))),
102111
display.appInstanceDate(instance.StartTime()),
112+
formatRoutable(instance.Routable),
103113
fmt.Sprintf("%.1f%%", instance.CPU*100),
104114
display.UI.TranslateText("{{.MemUsage}} of {{.MemQuota}}", map[string]interface{}{
105115
"MemUsage": bytefmt.ByteSize(instance.MemoryUsage),

command/v7/shared/app_summary_displayer_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
var _ = Describe("app summary displayer", func() {
1919

20-
const instanceStatsTitles = `state\s+since\s+cpu\s+memory\s+disk\s+logging\s+cpu entitlement\s+details`
20+
const instanceStatsTitles = `state\s+since\s+ready\s+cpu\s+memory\s+disk\s+logging\s+cpu entitlement\s+details`
2121

2222
var (
2323
appSummaryDisplayer *AppSummaryDisplayer
@@ -48,6 +48,10 @@ var _ = Describe("app summary displayer", func() {
4848

4949
BeforeEach(func() {
5050
uptime = time.Since(time.Unix(267321600, 0))
51+
var (
52+
bTrue = true
53+
bFalse = false
54+
)
5155
summary = v7action.DetailedApplicationSummary{
5256
ApplicationSummary: v7action.ApplicationSummary{
5357
Application: resources.Application{
@@ -67,6 +71,7 @@ var _ = Describe("app summary displayer", func() {
6771
v7action.ProcessInstance{
6872
Index: 0,
6973
State: constant.ProcessInstanceRunning,
74+
Routable: nil,
7075
CPUEntitlement: types.NullFloat64{Value: 0, IsSet: true},
7176
MemoryUsage: 1000000,
7277
DiskUsage: 1000000,
@@ -80,6 +85,7 @@ var _ = Describe("app summary displayer", func() {
8085
v7action.ProcessInstance{
8186
Index: 1,
8287
State: constant.ProcessInstanceRunning,
88+
Routable: &bTrue,
8389
CPUEntitlement: types.NullFloat64{Value: 0, IsSet: false},
8490
MemoryUsage: 2000000,
8591
DiskUsage: 2000000,
@@ -93,6 +99,7 @@ var _ = Describe("app summary displayer", func() {
9399
v7action.ProcessInstance{
94100
Index: 2,
95101
State: constant.ProcessInstanceRunning,
102+
Routable: &bFalse,
96103
CPUEntitlement: types.NullFloat64{Value: 0.03, IsSet: true},
97104
MemoryUsage: 3000000,
98105
DiskUsage: 3000000,
@@ -116,6 +123,7 @@ var _ = Describe("app summary displayer", func() {
116123
v7action.ProcessInstance{
117124
Index: 0,
118125
State: constant.ProcessInstanceRunning,
126+
Routable: &bTrue,
119127
MemoryUsage: 1000000,
120128
DiskUsage: 1000000,
121129
LogRate: 128,

integration/helpers/app_instance_table.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
type AppInstanceRow struct {
1111
Index string
1212
State string
13+
Ready string
1314
Since string
1415
CPU string
1516
Memory string
@@ -57,7 +58,7 @@ func ParseV3AppProcessTable(input []byte) AppTable {
5758

5859
switch {
5960
case strings.HasPrefix(row, "#"):
60-
const columnCount = 9
61+
const columnCount = 10
6162

6263
// instance row
6364
columns := splitColumns(row)
@@ -73,10 +74,11 @@ func ParseV3AppProcessTable(input []byte) AppTable {
7374
Index: columns[0],
7475
State: columns[1],
7576
Since: columns[2],
76-
CPU: columns[3],
77-
Memory: columns[4],
78-
Disk: columns[5],
79-
LogRate: columns[6],
77+
Ready: columns[3],
78+
CPU: columns[4],
79+
Memory: columns[5],
80+
Disk: columns[6],
81+
LogRate: columns[7],
8082
CPUEntitlement: cpuEntitlement,
8183
Details: details,
8284
}

0 commit comments

Comments
 (0)