Skip to content

Commit

Permalink
feat(api,ui,sdk): Make CPU limits configurable (#381)
Browse files Browse the repository at this point in the history
* Update swagger docs

* Update sdk autogenerated openapi classes

* Refactor knativeServiceConfig and make it an attribute of the service builder

* Add cpu limit to resource requests and refactor knative service struct

* Simplify diff reporting steps in unit test helper function

* Fix k8s service unit test

* Refactor how cpu and memory limits are set for fluentd stateful set

* Simplify if else-block in cpu limit helper function

* Update openapi specs

* Update python unit tests

* Add cpu limit form group component

* Refactor cpu limit as nullable field

* Add default values for cpu limit in all router components

* Fix tooltip description

* Rename cpu limit section

* Update docs

* Replace env var append function with merge with replace function

* Add codecov config file that adds a threshold to allow random code coverage decreases

* Replace outdated comment with more detailed on describing the flow of setting resource requirement values

* Simplify if/else conditions in getCPULimit
  • Loading branch information
deadlycoconuts committed Jun 3, 2024
1 parent 0d6f578 commit cbebbd6
Show file tree
Hide file tree
Showing 38 changed files with 748 additions and 428 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codecov-config/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
patch:
default:
threshold: 0.03%
1 change: 1 addition & 0 deletions .github/workflows/sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
flags: sdk-test-${{ matrix.python-version }}
name: sdk-test-${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}
codecov_yml_path: ./.github/workflows/codecov-config/codecov.yml

release-rules:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/turing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ jobs:
name: api-test
token: ${{ secrets.CODECOV_TOKEN }}
working-directory: api
codecov_yml_path: ../.github/workflows/codecov-config/codecov.yml

test-engines-router:
runs-on: ubuntu-latest
Expand Down
22 changes: 22 additions & 0 deletions api/api/openapi.bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@ components:
port: 5
created_at: 2000-01-23T04:56:07.000+00:00
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2161,6 +2162,7 @@ components:
updated_at: 2000-01-23T04:56:07.000+00:00
default_route_id: default_route_id
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand All @@ -2174,6 +2176,7 @@ components:
project_id: 7
ensembler_id: 9
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2207,6 +2210,7 @@ components:
target: target
port: 2
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2311,6 +2315,7 @@ components:
type: object
ResourceRequest:
example:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand All @@ -2323,6 +2328,10 @@ components:
cpu_request:
pattern: ^(\d{1,3}(\.\d{1,3})?)$|^(\d{2,5}m)$
type: string
cpu_limit:
nullable: true
pattern: ^(\d{1,3}(\.\d{1,3})?)$|^(\d{2,5}m)$
type: string
memory_request:
pattern: ^\d+(Ei?|Pi?|Ti?|Gi?|Mi?|Ki?)?$
type: string
Expand Down Expand Up @@ -2419,6 +2428,7 @@ components:
port: 5
created_at: 2000-01-23T04:56:07.000+00:00
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2481,6 +2491,7 @@ components:
project_id: 7
ensembler_id: 9
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2514,6 +2525,7 @@ components:
target: target
port: 2
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2588,6 +2600,7 @@ components:
target: target
port: 2
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2640,6 +2653,7 @@ components:
project_id: 7
ensembler_id: 9
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2770,6 +2784,7 @@ components:
port: 5
created_at: 2000-01-23T04:56:07.000+00:00
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2830,6 +2845,7 @@ components:
- values
operator: in
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand All @@ -2842,6 +2858,7 @@ components:
project_id: 7
ensembler_id: 9
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2875,6 +2892,7 @@ components:
target: target
port: 2
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2929,6 +2947,7 @@ components:
port: 5
created_at: 2000-01-23T04:56:07.000+00:00
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -2989,6 +3008,7 @@ components:
- values
operator: in
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand All @@ -3001,6 +3021,7 @@ components:
project_id: 7
ensembler_id: 9
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down Expand Up @@ -3034,6 +3055,7 @@ components:
target: target
port: 2
resource_request:
cpu_limit: cpu_limit
min_replica: 0
max_replica: 6
memory_request: memory_request
Expand Down
4 changes: 4 additions & 0 deletions api/api/specs/routers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ components:
cpu_request:
type: "string"
pattern: '^(\d{1,3}(\.\d{1,3})?)$|^(\d{2,5}m)$'
cpu_limit:
type: "string"
pattern: '^(\d{1,3}(\.\d{1,3})?)$|^(\d{2,5}m)$'
nullable: true
memory_request:
type: "string"
pattern: '^\d+(Ei?|Pi?|Ti?|Gi?|Mi?|Ki?)?$'
Expand Down
12 changes: 2 additions & 10 deletions api/turing/cluster/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ type KnativeService struct {
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints"`

// Resource properties
QueueProxyResourcePercentage int `json:"queueProxyResourcePercentage"`
UserContainerCPULimitRequestFactor float64 `json:"userContainerLimitCPURequestFactor"`
UserContainerMemoryLimitRequestFactor float64 `json:"userContainerLimitMemoryRequestFactor"`
QueueProxyResourcePercentage int `json:"queueProxyResourcePercentage"`
}

// Creates a new config object compatible with the knative serving API, from
Expand Down Expand Up @@ -131,12 +129,6 @@ func (cfg *KnativeService) buildSvcSpec(
// Revision name
revisionName := getDefaultRevisionName(cfg.Name)

// Build resource requirements for the user container
resourceReqs := cfg.buildResourceReqs(
cfg.UserContainerCPULimitRequestFactor,
cfg.UserContainerMemoryLimitRequestFactor,
)

// Build container spec
var portName string
// If protocol is using GRPC, add "h2c" which is required for grpc knative
Expand All @@ -151,7 +143,7 @@ func (cfg *KnativeService) buildSvcSpec(
ContainerPort: cfg.ContainerPort,
},
},
Resources: resourceReqs,
Resources: cfg.buildResourceReqs(),
VolumeMounts: cfg.VolumeMounts,
Env: cfg.Envs,
}
Expand Down
Loading

0 comments on commit cbebbd6

Please sign in to comment.