Skip to content

Commit b4ec021

Browse files
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 Co-authored-by: João Pereira <joao.pereira@broadcom.com>
1 parent a8ccec6 commit b4ec021

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

api/cloudcontroller/ccv3/process_instance.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type ProcessInstance struct {
3838
LogRate uint64
3939
// State is the state of the instance.
4040
State constant.ProcessInstanceState
41+
// Routeable is the readiness state of the instance, can be true, false or null.
42+
Routable *bool
4143
// Type is the process type for the instance.
4244
Type string
4345
// Uptime is the duration that the instance has been running.
@@ -54,6 +56,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
5456
MemQuota uint64 `json:"mem_quota"`
5557
LogRateLimit int64 `json:"log_rate_limit"`
5658
State string `json:"state"`
59+
Routable *bool `json:"routable"`
5760
Type string `json:"type"`
5861
Uptime int64 `json:"uptime"`
5962
Usage struct {
@@ -80,6 +83,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
8083
instance.LogRateLimit = inputInstance.LogRateLimit
8184
instance.LogRate = inputInstance.Usage.LogRate
8285
instance.State = constant.ProcessInstanceState(inputInstance.State)
86+
instance.Routable = inputInstance.Routable
8387
instance.Type = inputInstance.Type
8488
instance.Uptime, err = time.ParseDuration(fmt.Sprintf("%ds", inputInstance.Uptime))
8589
if err != nil {

command/v7/shared/app_summary_displayer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ func formatCPU(instance v7action.ProcessInstance) string {
7979
return fmt.Sprintf("%.1f%%", instance.CPUEntitlement.Value*100)
8080
}
8181

82+
func formatRoutable(b *bool) string {
83+
if b == nil {
84+
return "-"
85+
}
86+
87+
return fmt.Sprintf("%t", *b)
88+
}
89+
8290
func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7action.ProcessSummary) {
8391
table := [][]string{
8492
{
@@ -90,6 +98,7 @@ func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7act
9098
display.UI.TranslateText("disk"),
9199
display.UI.TranslateText("logging"),
92100
display.UI.TranslateText("details"),
101+
display.UI.TranslateText("ready"),
93102
},
94103
}
95104

@@ -112,6 +121,7 @@ func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7act
112121
"LogRateLimit": formatLogRateLimit(instance.LogRateLimit),
113122
}),
114123
instance.Details,
124+
formatRoutable(instance.Routable),
115125
})
116126
}
117127

command/v7/shared/app_summary_displayer_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
var _ = Describe("app summary displayer", func() {
19-
const instanceStatsTitles = `state\s+since\s+cpu entitlement\s+memory\s+disk\s+logging\s+details`
19+
const instanceStatsTitles = `state\s+since\s+cpu entitlement\s+memory\s+disk\s+logging\s+details\s+ready`
2020

2121
var (
2222
output *Buffer
@@ -45,6 +45,10 @@ var _ = Describe("app summary displayer", func() {
4545

4646
BeforeEach(func() {
4747
uptime = time.Since(time.Unix(267321600, 0))
48+
var (
49+
bTrue = true
50+
bFalse = false
51+
)
4852
summary = v7action.DetailedApplicationSummary{
4953
ApplicationSummary: v7action.ApplicationSummary{
5054
Application: resources.Application{
@@ -61,7 +65,7 @@ var _ = Describe("app summary displayer", func() {
6165
},
6266
Sidecars: []resources.Sidecar{},
6367
InstanceDetails: []v7action.ProcessInstance{
64-
v7action.ProcessInstance{
68+
{
6569
Index: 0,
6670
State: constant.ProcessInstanceRunning,
6771
CPUEntitlement: types.NullFloat64{Value: 0.0, IsSet: true},
@@ -73,8 +77,9 @@ var _ = Describe("app summary displayer", func() {
7377
LogRateLimit: 1024 * 5,
7478
Uptime: uptime,
7579
Details: "Some Details 1",
80+
Routable: &bTrue,
7681
},
77-
v7action.ProcessInstance{
82+
{
7883
Index: 1,
7984
State: constant.ProcessInstanceRunning,
8085
CPUEntitlement: types.NullFloat64{Value: 1.0, IsSet: true},
@@ -86,8 +91,9 @@ var _ = Describe("app summary displayer", func() {
8691
LogRateLimit: 1024 * 5,
8792
Uptime: time.Since(time.Unix(330480000, 0)),
8893
Details: "Some Details 2",
94+
Routable: &bTrue,
8995
},
90-
v7action.ProcessInstance{
96+
{
9197
Index: 2,
9298
State: constant.ProcessInstanceRunning,
9399
CPUEntitlement: types.NullFloat64{Value: 0.03, IsSet: true},
@@ -98,6 +104,7 @@ var _ = Describe("app summary displayer", func() {
98104
DiskQuota: 6000000,
99105
LogRateLimit: 1024 * 5,
100106
Uptime: time.Since(time.Unix(1277164800, 0)),
107+
Routable: &bFalse,
101108
},
102109
},
103110
},
@@ -110,7 +117,7 @@ var _ = Describe("app summary displayer", func() {
110117
},
111118
Sidecars: []resources.Sidecar{},
112119
InstanceDetails: []v7action.ProcessInstance{
113-
v7action.ProcessInstance{
120+
{
114121
Index: 0,
115122
State: constant.ProcessInstanceRunning,
116123
CPUEntitlement: types.NullFloat64{Value: 0.0, IsSet: true},
@@ -121,6 +128,8 @@ var _ = Describe("app summary displayer", func() {
121128
DiskQuota: 8000000,
122129
LogRateLimit: 256,
123130
Uptime: time.Since(time.Unix(167572800, 0)),
131+
Details: "",
132+
Routable: &bTrue,
124133
},
125134
},
126135
},

integration/helpers/app_instance_table.go

Lines changed: 4 additions & 2 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
CPUEntitlement string
1516
Memory string
@@ -56,13 +57,13 @@ func ParseV3AppProcessTable(input []byte) AppTable {
5657

5758
switch {
5859
case strings.HasPrefix(row, "#"):
59-
const columnCount = 8
60+
const columnCount = 9
6061

6162
// instance row
6263
columns := splitColumns(row)
6364
details := ""
6465
if len(columns) >= columnCount {
65-
details = columns[columnCount-1]
66+
details = columns[len(columns)-2]
6667
}
6768

6869
instanceRow := AppInstanceRow{
@@ -74,6 +75,7 @@ func ParseV3AppProcessTable(input []byte) AppTable {
7475
Disk: columns[5],
7576
LogRate: columns[6],
7677
Details: details,
78+
Ready: columns[len(columns)-1],
7779
}
7880
lastProcessIndex := len(appTable.Processes) - 1
7981
appTable.Processes[lastProcessIndex].Instances = append(

0 commit comments

Comments
 (0)