Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add cpu entitlement to app process table (v9) #2850

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 56 additions & 56 deletions actor/v7action/application_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ var _ = Describe("Application Summary Actions", func() {
fakeCloudControllerClient.GetProcessInstancesReturns(
[]ccv3.ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
ccv3.Warnings{"get-process-instances-warning"},
Expand Down Expand Up @@ -207,13 +207,13 @@ var _ = Describe("Application Summary Actions", func() {
},
InstanceDetails: []ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
},
Expand All @@ -227,13 +227,13 @@ var _ = Describe("Application Summary Actions", func() {
},
InstanceDetails: []ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
},
Expand Down Expand Up @@ -543,13 +543,13 @@ var _ = Describe("Application Summary Actions", func() {
fakeCloudControllerClient.GetProcessInstancesReturns(
[]ccv3.ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
ccv3.Warnings{"get-process-instances-warning"},
Expand Down Expand Up @@ -612,13 +612,13 @@ var _ = Describe("Application Summary Actions", func() {
},
InstanceDetails: []ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
},
Expand All @@ -638,13 +638,13 @@ var _ = Describe("Application Summary Actions", func() {
},
InstanceDetails: []ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
},
Expand Down Expand Up @@ -756,13 +756,13 @@ var _ = Describe("Application Summary Actions", func() {
},
InstanceDetails: []ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
},
Expand All @@ -782,13 +782,13 @@ var _ = Describe("Application Summary Actions", func() {
},
InstanceDetails: []ProcessInstance{
{
State: constant.ProcessInstanceRunning,
CPU: 0.01,
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
State: constant.ProcessInstanceRunning,
CPUEntitlement: types.NullFloat64{Value: 0.01, IsSet: true},
MemoryUsage: 1000000,
DiskUsage: 2000000,
MemoryQuota: 3000000,
DiskQuota: 4000000,
Index: 0,
},
},
},
Expand Down
15 changes: 8 additions & 7 deletions api/cloudcontroller/ccv3/process_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
"code.cloudfoundry.org/cli/types"
)

// ProcessInstance represents a single process instance for a particular
// application.
type ProcessInstance struct {
// CPU is the current CPU usage of the instance.
CPU float64
// CPUEntitlement is the current CPU entitlement usage of the instance.
CPUEntitlement types.NullFloat64
// Details is information about errors placing the instance.
Details string
// DiskQuota is the maximum disk the instance is allowed to use.
Expand Down Expand Up @@ -56,10 +57,10 @@ func (instance *ProcessInstance) UnmarshalJSON(data []byte) error {
Type string `json:"type"`
Uptime int64 `json:"uptime"`
Usage struct {
CPU float64 `json:"cpu"`
Mem uint64 `json:"mem"`
Disk uint64 `json:"disk"`
LogRate uint64 `json:"log_rate"`
CPUEntitlement types.NullFloat64 `json:"cpu_entitlement"`
Mem uint64 `json:"mem"`
Disk uint64 `json:"disk"`
LogRate uint64 `json:"log_rate"`
} `json:"usage"`
}

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

instance.CPU = inputInstance.Usage.CPU
instance.CPUEntitlement = inputInstance.Usage.CPUEntitlement
instance.Details = inputInstance.Details
instance.DiskQuota = inputInstance.DiskQuota
instance.DiskUsage = inputInstance.Usage.Disk
Expand Down
52 changes: 50 additions & 2 deletions api/cloudcontroller/ccv3/process_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/ghttp"
Expand Down Expand Up @@ -92,6 +93,7 @@ var _ = Describe("ProcessInstance", func() {
"state": "RUNNING",
"usage": {
"cpu": 0.01,
"cpu_entitlement": 0.02,
"mem": 1000000,
"disk": 2000000,
"log_rate": 5000
Expand All @@ -109,6 +111,7 @@ var _ = Describe("ProcessInstance", func() {
"state": "RUNNING",
"usage": {
"cpu": 0.02,
"cpu_entitlement": 0.04,
"mem": 8000000,
"disk": 16000000,
"log_rate": 32000
Expand All @@ -135,7 +138,7 @@ var _ = Describe("ProcessInstance", func() {

Expect(processes).To(ConsistOf(
ProcessInstance{
CPU: 0.01,
CPUEntitlement: types.NullFloat64{Value: 0.02, IsSet: true},
Details: "some details",
DiskQuota: 4000000,
DiskUsage: 2000000,
Expand All @@ -150,7 +153,7 @@ var _ = Describe("ProcessInstance", func() {
Uptime: 123 * time.Second,
},
ProcessInstance{
CPU: 0.02,
CPUEntitlement: types.NullFloat64{Value: 0.04, IsSet: true},
DiskQuota: 32000000,
DiskUsage: 16000000,
Index: 1,
Expand All @@ -168,6 +171,51 @@ var _ = Describe("ProcessInstance", func() {
})
})

When("CPU entitlement is null", func() {
BeforeEach(func() {
response := `{
"resources": [
{
"type": "web",
"usage": {
"cpu_entitlement": null
}
}
]
}`
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodGet, "/v3/processes/some-process-guid/stats"),
RespondWith(http.StatusOK, response),
),
)
})

It("marks the cpu entitlement as not set", func() {
Expect(executeErr).ToNot(HaveOccurred())
Expect(processes).To(HaveLen(1))
Expect(processes[0].CPUEntitlement.IsSet).To(BeFalse())
})
})

When("CPU entitlement is not present", func() {
BeforeEach(func() {
response := `{ "resources": [ { "type": "web", "usage": {} } ] }`
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodGet, "/v3/processes/some-process-guid/stats"),
RespondWith(http.StatusOK, response),
),
)
})

It("marks the cpu entitlement as not set", func() {
Expect(executeErr).ToNot(HaveOccurred())
Expect(processes).To(HaveLen(1))
Expect(processes[0].CPUEntitlement.IsSet).To(BeFalse())
})
})

When("cloud controller returns an error", func() {
BeforeEach(func() {
response := `{
Expand Down
4 changes: 2 additions & 2 deletions api/cloudcontroller/ccversion/minimum_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ccversion

const (
MinSupportedV2ClientVersion = "2.128.0"
MinSupportedClientVersionV8 = "3.99.0"
MinSupportedClientVersionV9 = "3.160.0"

MinVersionUpdateServiceNameWhenPlanNotVisibleV2 = "2.131.0"
MinVersionUpdateServiceInstanceMaintenanceInfoV2 = "2.135.0"
Expand All @@ -14,5 +14,5 @@ const (
MinVersionHTTP2RoutingV3 = "3.104.0"
MinVersionSpaceSupporterV3 = "3.104.0"

MinVersionLogRateLimitingV3 = "3.124.0" // TODO: update this when we have a CAPI release
MinVersionLogRateLimitingV3 = "3.125.0"
)
9 changes: 5 additions & 4 deletions command/v7/auth_command_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package v7_test

import (
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"errors"

"code.cloudfoundry.org/cli/cf/configuration/coreconfig"

"code.cloudfoundry.org/cli/api/uaa"
"code.cloudfoundry.org/cli/api/uaa/constant"
"code.cloudfoundry.org/cli/api/uaa/uaaversion"
Expand Down Expand Up @@ -44,7 +45,7 @@ var _ = Describe("auth Command", func() {
binaryName = "faceman"
fakeConfig.BinaryNameReturns(binaryName)
fakeConfig.UAAOAuthClientReturns("cf")
fakeConfig.APIVersionReturns("3.99.0")
fakeConfig.APIVersionReturns("3.160.0")
k8sLoginPrompts = map[string]coreconfig.AuthPrompt{
"k8s-auth-info": {
Entries: []string{"myuser"},
Expand Down Expand Up @@ -226,14 +227,14 @@ var _ = Describe("auth Command", func() {
cmd.RequiredArgs.Password = testSecret
})

When("the API version is older than the minimum supported API version for the v7 CLI", func() {
When("the API version is older than the minimum supported API version for the v9 CLI", func() {
BeforeEach(func() {
fakeConfig.APIVersionReturns("3.83.0")
})
It("warns that the user is targeting an unsupported API version and that things may not work correctly", func() {
Expect(err).ToNot(HaveOccurred())
Expect(testUI.Out).To(Say("API endpoint: %s", fakeConfig.Target()))
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."))
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."))
})
})

Expand Down
6 changes: 3 additions & 3 deletions command/v7/login_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("login Command", func() {
cmd.APIEndpoint = ""

fakeActorReloader.ReloadReturns(fakeActor, nil)
fakeConfig.APIVersionReturns("3.99.0")
fakeConfig.APIVersionReturns("3.160.0")
})

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

When("the API version is older than the minimum supported API version for the v7 CLI", func() {
When("the API version is older than the minimum supported API version for the v9 CLI", func() {
BeforeEach(func() {
fakeConfig.APIVersionReturns("3.83.0")
})
It("warns that the user is targeting an unsupported API version and that things may not work correctly", func() {
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."))
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."))
})
})

Expand Down
Loading
Loading