Skip to content

Commit

Permalink
feat: add ready indicator to cf app command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maxmoehl committed Jan 7, 2025
1 parent fcd2cbc commit a60217e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions api/cloudcontroller/ccv3/process_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type ProcessInstance struct {
LogRate uint64
// State is the state of the instance.
State constant.ProcessInstanceState
// Routeable is the readiness state of the instance, can be true, false or null.
Routable *bool
// Type is the process type for the instance.
Type string
// Uptime is the duration that the instance has been running.
Expand All @@ -56,6 +58,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
MemQuota uint64 `json:"mem_quota"`
LogRateLimit int64 `json:"log_rate_limit"`
State string `json:"state"`
Routable *bool `json:"routable"`
Type string `json:"type"`
Uptime int64 `json:"uptime"`
Usage struct {
Expand Down Expand Up @@ -84,6 +87,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
instance.LogRateLimit = inputInstance.LogRateLimit
instance.LogRate = inputInstance.Usage.LogRate
instance.State = constant.ProcessInstanceState(inputInstance.State)
instance.Routable = inputInstance.Routable
instance.Type = inputInstance.Type
instance.Uptime, err = time.ParseDuration(fmt.Sprintf("%ds", inputInstance.Uptime))
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions command/v7/shared/app_summary_displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ func formatCPUEntitlement(cpuEntitlement types.NullFloat64) string {
return fmt.Sprintf("%.1f%%", cpuEntitlement.Value*100)
}

func formatRoutable(b *bool) string {
if b == nil {
return "-"
}

return fmt.Sprintf("%t", *b)
}

func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7action.ProcessSummary) {
table := [][]string{
{
"",
display.UI.TranslateText("state"),
display.UI.TranslateText("since"),
display.UI.TranslateText("ready"),
display.UI.TranslateText("cpu"),
display.UI.TranslateText("memory"),
display.UI.TranslateText("disk"),
Expand All @@ -100,6 +109,7 @@ func (display AppSummaryDisplayer) displayAppInstancesTable(processSummary v7act
fmt.Sprintf("#%d", instance.Index),
display.UI.TranslateText(strings.ToLower(string(instance.State))),
display.appInstanceDate(instance.StartTime()),
formatRoutable(instance.Routable),
fmt.Sprintf("%.1f%%", instance.CPU*100),
display.UI.TranslateText("{{.MemUsage}} of {{.MemQuota}}", map[string]interface{}{
"MemUsage": bytefmt.ByteSize(instance.MemoryUsage),
Expand Down
10 changes: 9 additions & 1 deletion command/v7/shared/app_summary_displayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

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

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

var (
appSummaryDisplayer *AppSummaryDisplayer
Expand Down Expand Up @@ -48,6 +48,10 @@ var _ = Describe("app summary displayer", func() {

BeforeEach(func() {
uptime = time.Since(time.Unix(267321600, 0))
var (
bTrue = true
bFalse = false
)
summary = v7action.DetailedApplicationSummary{
ApplicationSummary: v7action.ApplicationSummary{
Application: resources.Application{
Expand All @@ -67,6 +71,7 @@ var _ = Describe("app summary displayer", func() {
v7action.ProcessInstance{
Index: 0,
State: constant.ProcessInstanceRunning,
Routable: nil,
CPUEntitlement: types.NullFloat64{Value: 0, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 1000000,
Expand All @@ -80,6 +85,7 @@ var _ = Describe("app summary displayer", func() {
v7action.ProcessInstance{
Index: 1,
State: constant.ProcessInstanceRunning,
Routable: &bTrue,
CPUEntitlement: types.NullFloat64{Value: 0, IsSet: false},
MemoryUsage: 2000000,
DiskUsage: 2000000,
Expand All @@ -93,6 +99,7 @@ var _ = Describe("app summary displayer", func() {
v7action.ProcessInstance{
Index: 2,
State: constant.ProcessInstanceRunning,
Routable: &bFalse,
CPUEntitlement: types.NullFloat64{Value: 0.03, IsSet: true},
MemoryUsage: 3000000,
DiskUsage: 3000000,
Expand All @@ -116,6 +123,7 @@ var _ = Describe("app summary displayer", func() {
v7action.ProcessInstance{
Index: 0,
State: constant.ProcessInstanceRunning,
Routable: &bTrue,
MemoryUsage: 1000000,
DiskUsage: 1000000,
LogRate: 128,
Expand Down
12 changes: 7 additions & 5 deletions integration/helpers/app_instance_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type AppInstanceRow struct {
Index string
State string
Ready string
Since string
CPU string
Memory string
Expand Down Expand Up @@ -57,7 +58,7 @@ func ParseV3AppProcessTable(input []byte) AppTable {

switch {
case strings.HasPrefix(row, "#"):
const columnCount = 9
const columnCount = 10

// instance row
columns := splitColumns(row)
Expand All @@ -73,10 +74,11 @@ func ParseV3AppProcessTable(input []byte) AppTable {
Index: columns[0],
State: columns[1],
Since: columns[2],
CPU: columns[3],
Memory: columns[4],
Disk: columns[5],
LogRate: columns[6],
Ready: columns[3],
CPU: columns[4],
Memory: columns[5],
Disk: columns[6],
LogRate: columns[7],
CPUEntitlement: cpuEntitlement,
Details: details,
}
Expand Down

0 comments on commit a60217e

Please sign in to comment.