Skip to content

Commit 2d9b726

Browse files
acrmprroberts2222
andauthored
Feat: Add cpu entitlement to app process table (v9) (#2850)
* Correct minimum CAPI version with log rate limit support * feat: Add cpu entitlement to app process table Co-authored-by: Rebecca Roberts <[email protected]>
1 parent 7601a12 commit 2d9b726

22 files changed

+426
-233
lines changed

actor/v7action/application_summary_test.go

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ var _ = Describe("Application Summary Actions", func() {
145145
fakeCloudControllerClient.GetProcessInstancesReturns(
146146
[]ccv3.ProcessInstance{
147147
{
148-
State: constant.ProcessInstanceRunning,
149-
CPU: 0.01,
150-
MemoryUsage: 1000000,
151-
DiskUsage: 2000000,
152-
MemoryQuota: 3000000,
153-
DiskQuota: 4000000,
154-
Index: 0,
148+
State: constant.ProcessInstanceRunning,
149+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
150+
MemoryUsage: 1000000,
151+
DiskUsage: 2000000,
152+
MemoryQuota: 3000000,
153+
DiskQuota: 4000000,
154+
Index: 0,
155155
},
156156
},
157157
ccv3.Warnings{"get-process-instances-warning"},
@@ -207,13 +207,13 @@ var _ = Describe("Application Summary Actions", func() {
207207
},
208208
InstanceDetails: []ProcessInstance{
209209
{
210-
State: constant.ProcessInstanceRunning,
211-
CPU: 0.01,
212-
MemoryUsage: 1000000,
213-
DiskUsage: 2000000,
214-
MemoryQuota: 3000000,
215-
DiskQuota: 4000000,
216-
Index: 0,
210+
State: constant.ProcessInstanceRunning,
211+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
212+
MemoryUsage: 1000000,
213+
DiskUsage: 2000000,
214+
MemoryQuota: 3000000,
215+
DiskQuota: 4000000,
216+
Index: 0,
217217
},
218218
},
219219
},
@@ -227,13 +227,13 @@ var _ = Describe("Application Summary Actions", func() {
227227
},
228228
InstanceDetails: []ProcessInstance{
229229
{
230-
State: constant.ProcessInstanceRunning,
231-
CPU: 0.01,
232-
MemoryUsage: 1000000,
233-
DiskUsage: 2000000,
234-
MemoryQuota: 3000000,
235-
DiskQuota: 4000000,
236-
Index: 0,
230+
State: constant.ProcessInstanceRunning,
231+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
232+
MemoryUsage: 1000000,
233+
DiskUsage: 2000000,
234+
MemoryQuota: 3000000,
235+
DiskQuota: 4000000,
236+
Index: 0,
237237
},
238238
},
239239
},
@@ -543,13 +543,13 @@ var _ = Describe("Application Summary Actions", func() {
543543
fakeCloudControllerClient.GetProcessInstancesReturns(
544544
[]ccv3.ProcessInstance{
545545
{
546-
State: constant.ProcessInstanceRunning,
547-
CPU: 0.01,
548-
MemoryUsage: 1000000,
549-
DiskUsage: 2000000,
550-
MemoryQuota: 3000000,
551-
DiskQuota: 4000000,
552-
Index: 0,
546+
State: constant.ProcessInstanceRunning,
547+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
548+
MemoryUsage: 1000000,
549+
DiskUsage: 2000000,
550+
MemoryQuota: 3000000,
551+
DiskQuota: 4000000,
552+
Index: 0,
553553
},
554554
},
555555
ccv3.Warnings{"get-process-instances-warning"},
@@ -612,13 +612,13 @@ var _ = Describe("Application Summary Actions", func() {
612612
},
613613
InstanceDetails: []ProcessInstance{
614614
{
615-
State: constant.ProcessInstanceRunning,
616-
CPU: 0.01,
617-
MemoryUsage: 1000000,
618-
DiskUsage: 2000000,
619-
MemoryQuota: 3000000,
620-
DiskQuota: 4000000,
621-
Index: 0,
615+
State: constant.ProcessInstanceRunning,
616+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
617+
MemoryUsage: 1000000,
618+
DiskUsage: 2000000,
619+
MemoryQuota: 3000000,
620+
DiskQuota: 4000000,
621+
Index: 0,
622622
},
623623
},
624624
},
@@ -638,13 +638,13 @@ var _ = Describe("Application Summary Actions", func() {
638638
},
639639
InstanceDetails: []ProcessInstance{
640640
{
641-
State: constant.ProcessInstanceRunning,
642-
CPU: 0.01,
643-
MemoryUsage: 1000000,
644-
DiskUsage: 2000000,
645-
MemoryQuota: 3000000,
646-
DiskQuota: 4000000,
647-
Index: 0,
641+
State: constant.ProcessInstanceRunning,
642+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
643+
MemoryUsage: 1000000,
644+
DiskUsage: 2000000,
645+
MemoryQuota: 3000000,
646+
DiskQuota: 4000000,
647+
Index: 0,
648648
},
649649
},
650650
},
@@ -756,13 +756,13 @@ var _ = Describe("Application Summary Actions", func() {
756756
},
757757
InstanceDetails: []ProcessInstance{
758758
{
759-
State: constant.ProcessInstanceRunning,
760-
CPU: 0.01,
761-
MemoryUsage: 1000000,
762-
DiskUsage: 2000000,
763-
MemoryQuota: 3000000,
764-
DiskQuota: 4000000,
765-
Index: 0,
759+
State: constant.ProcessInstanceRunning,
760+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
761+
MemoryUsage: 1000000,
762+
DiskUsage: 2000000,
763+
MemoryQuota: 3000000,
764+
DiskQuota: 4000000,
765+
Index: 0,
766766
},
767767
},
768768
},
@@ -782,13 +782,13 @@ var _ = Describe("Application Summary Actions", func() {
782782
},
783783
InstanceDetails: []ProcessInstance{
784784
{
785-
State: constant.ProcessInstanceRunning,
786-
CPU: 0.01,
787-
MemoryUsage: 1000000,
788-
DiskUsage: 2000000,
789-
MemoryQuota: 3000000,
790-
DiskQuota: 4000000,
791-
Index: 0,
785+
State: constant.ProcessInstanceRunning,
786+
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
787+
MemoryUsage: 1000000,
788+
DiskUsage: 2000000,
789+
MemoryQuota: 3000000,
790+
DiskQuota: 4000000,
791+
Index: 0,
792792
},
793793
},
794794
},

api/cloudcontroller/ccv3/process_instance.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
"code.cloudfoundry.org/cli/api/cloudcontroller"
99
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
1010
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
11+
"code.cloudfoundry.org/cli/types"
1112
)
1213

1314
// ProcessInstance represents a single process instance for a particular
1415
// application.
1516
type ProcessInstance struct {
16-
// CPU is the current CPU usage of the instance.
17-
CPU float64
17+
// CPUEntitlement is the current CPU entitlement usage of the instance.
18+
CPUEntitlement types.NullFloat64
1819
// Details is information about errors placing the instance.
1920
Details string
2021
// DiskQuota is the maximum disk the instance is allowed to use.
@@ -56,10 +57,10 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
5657
Type string `json:"type"`
5758
Uptime int64 `json:"uptime"`
5859
Usage struct {
59-
CPU float64 `json:"cpu"`
60-
Mem uint64 `json:"mem"`
61-
Disk uint64 `json:"disk"`
62-
LogRate uint64 `json:"log_rate"`
60+
CPUEntitlement types.NullFloat64 `json:"cpu_entitlement"`
61+
Mem uint64 `json:"mem"`
62+
Disk uint64 `json:"disk"`
63+
LogRate uint64 `json:"log_rate"`
6364
} `json:"usage"`
6465
}
6566

@@ -68,7 +69,7 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
6869
return err
6970
}
7071

71-
instance.CPU = inputInstance.Usage.CPU
72+
instance.CPUEntitlement = inputInstance.Usage.CPUEntitlement
7273
instance.Details = inputInstance.Details
7374
instance.DiskQuota = inputInstance.DiskQuota
7475
instance.DiskUsage = inputInstance.Usage.Disk

api/cloudcontroller/ccv3/process_instance_test.go

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
88
. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
99
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
10+
"code.cloudfoundry.org/cli/types"
1011
. "github.com/onsi/ginkgo/v2"
1112
. "github.com/onsi/gomega"
1213
. "github.com/onsi/gomega/ghttp"
@@ -92,6 +93,7 @@ var _ = Describe("ProcessInstance", func() {
9293
"state": "RUNNING",
9394
"usage": {
9495
"cpu": 0.01,
96+
"cpu_entitlement": 0.02,
9597
"mem": 1000000,
9698
"disk": 2000000,
9799
"log_rate": 5000
@@ -109,6 +111,7 @@ var _ = Describe("ProcessInstance", func() {
109111
"state": "RUNNING",
110112
"usage": {
111113
"cpu": 0.02,
114+
"cpu_entitlement": 0.04,
112115
"mem": 8000000,
113116
"disk": 16000000,
114117
"log_rate": 32000
@@ -135,7 +138,7 @@ var _ = Describe("ProcessInstance", func() {
135138

136139
Expect(processes).To(ConsistOf(
137140
ProcessInstance{
138-
CPU: 0.01,
141+
CPUEntitlement: types.NullFloat64{Value: 0.02, IsSet: true},
139142
Details: "some details",
140143
DiskQuota: 4000000,
141144
DiskUsage: 2000000,
@@ -150,7 +153,7 @@ var _ = Describe("ProcessInstance", func() {
150153
Uptime: 123 * time.Second,
151154
},
152155
ProcessInstance{
153-
CPU: 0.02,
156+
CPUEntitlement: types.NullFloat64{Value: 0.04, IsSet: true},
154157
DiskQuota: 32000000,
155158
DiskUsage: 16000000,
156159
Index: 1,
@@ -168,6 +171,51 @@ var _ = Describe("ProcessInstance", func() {
168171
})
169172
})
170173

174+
When("CPU entitlement is null", func() {
175+
BeforeEach(func() {
176+
response := `{
177+
"resources": [
178+
{
179+
"type": "web",
180+
"usage": {
181+
"cpu_entitlement": null
182+
}
183+
}
184+
]
185+
}`
186+
server.AppendHandlers(
187+
CombineHandlers(
188+
VerifyRequest(http.MethodGet, "/v3/processes/some-process-guid/stats"),
189+
RespondWith(http.StatusOK, response),
190+
),
191+
)
192+
})
193+
194+
It("marks the cpu entitlement as not set", func() {
195+
Expect(executeErr).ToNot(HaveOccurred())
196+
Expect(processes).To(HaveLen(1))
197+
Expect(processes[0].CPUEntitlement.IsSet).To(BeFalse())
198+
})
199+
})
200+
201+
When("CPU entitlement is not present", func() {
202+
BeforeEach(func() {
203+
response := `{ "resources": [ { "type": "web", "usage": {} } ] }`
204+
server.AppendHandlers(
205+
CombineHandlers(
206+
VerifyRequest(http.MethodGet, "/v3/processes/some-process-guid/stats"),
207+
RespondWith(http.StatusOK, response),
208+
),
209+
)
210+
})
211+
212+
It("marks the cpu entitlement as not set", func() {
213+
Expect(executeErr).ToNot(HaveOccurred())
214+
Expect(processes).To(HaveLen(1))
215+
Expect(processes[0].CPUEntitlement.IsSet).To(BeFalse())
216+
})
217+
})
218+
171219
When("cloud controller returns an error", func() {
172220
BeforeEach(func() {
173221
response := `{

api/cloudcontroller/ccversion/minimum_version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package ccversion
22

33
const (
44
MinSupportedV2ClientVersion = "2.128.0"
5-
MinSupportedClientVersionV8 = "3.99.0"
5+
MinSupportedClientVersionV9 = "3.160.0"
66

77
MinVersionUpdateServiceNameWhenPlanNotVisibleV2 = "2.131.0"
88
MinVersionUpdateServiceInstanceMaintenanceInfoV2 = "2.135.0"
@@ -14,5 +14,5 @@ const (
1414
MinVersionHTTP2RoutingV3 = "3.104.0"
1515
MinVersionSpaceSupporterV3 = "3.104.0"
1616

17-
MinVersionLogRateLimitingV3 = "3.124.0" // TODO: update this when we have a CAPI release
17+
MinVersionLogRateLimitingV3 = "3.125.0"
1818
)

command/v7/auth_command_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package v7_test
22

33
import (
4-
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
54
"errors"
65

6+
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
7+
78
"code.cloudfoundry.org/cli/api/uaa"
89
"code.cloudfoundry.org/cli/api/uaa/constant"
910
"code.cloudfoundry.org/cli/api/uaa/uaaversion"
@@ -44,7 +45,7 @@ var _ = Describe("auth Command", func() {
4445
binaryName = "faceman"
4546
fakeConfig.BinaryNameReturns(binaryName)
4647
fakeConfig.UAAOAuthClientReturns("cf")
47-
fakeConfig.APIVersionReturns("3.99.0")
48+
fakeConfig.APIVersionReturns("3.160.0")
4849
k8sLoginPrompts = map[string]coreconfig.AuthPrompt{
4950
"k8s-auth-info": {
5051
Entries: []string{"myuser"},
@@ -226,14 +227,14 @@ var _ = Describe("auth Command", func() {
226227
cmd.RequiredArgs.Password = testSecret
227228
})
228229

229-
When("the API version is older than the minimum supported API version for the v7 CLI", func() {
230+
When("the API version is older than the minimum supported API version for the v9 CLI", func() {
230231
BeforeEach(func() {
231232
fakeConfig.APIVersionReturns("3.83.0")
232233
})
233234
It("warns that the user is targeting an unsupported API version and that things may not work correctly", func() {
234235
Expect(err).ToNot(HaveOccurred())
235236
Expect(testUI.Out).To(Say("API endpoint: %s", fakeConfig.Target()))
236-
Expect(testUI.Err).To(Say("Warning: Your targeted API's version \\(3.83.0\\) is less than the minimum supported API version \\(3.99.0\\). Some commands may not function correctly."))
237+
Expect(testUI.Err).To(Say("Warning: Your targeted API's version \\(3.83.0\\) is less than the minimum supported API version \\(3.160.0\\). Some commands may not function correctly."))
237238
})
238239
})
239240

command/v7/login_command_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var _ = Describe("login Command", func() {
5656
cmd.APIEndpoint = ""
5757

5858
fakeActorReloader.ReloadReturns(fakeActor, nil)
59-
fakeConfig.APIVersionReturns("3.99.0")
59+
fakeConfig.APIVersionReturns("3.160.0")
6060
})
6161

6262
JustBeforeEach(func() {
@@ -244,12 +244,12 @@ var _ = Describe("login Command", func() {
244244
Expect(actualSettings.URL).To(Equal("https://api.fake.com"))
245245
})
246246

247-
When("the API version is older than the minimum supported API version for the v7 CLI", func() {
247+
When("the API version is older than the minimum supported API version for the v9 CLI", func() {
248248
BeforeEach(func() {
249249
fakeConfig.APIVersionReturns("3.83.0")
250250
})
251251
It("warns that the user is targeting an unsupported API version and that things may not work correctly", func() {
252-
Expect(testUI.Err).To(Say("Warning: Your targeted API's version \\(3.83.0\\) is less than the minimum supported API version \\(3.99.0\\). Some commands may not function correctly."))
252+
Expect(testUI.Err).To(Say("Warning: Your targeted API's version \\(3.83.0\\) is less than the minimum supported API version \\(3.160.0\\). Some commands may not function correctly."))
253253
})
254254
})
255255

0 commit comments

Comments
 (0)