Skip to content

Commit

Permalink
Set default CPU limit as 2 and show in TMDEv2/v3/v4 task metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
chienhanlin committed Jan 6, 2021
1 parent ef0f5c7 commit cce8ef9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions agent/handlers/v2/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type LimitsResponse struct {
Memory *int64 `json:"Memory,omitempty"`
}

// Agent versions >= 1.2.0: Null, zero, and CPU values of 1
// are passed to Docker as two CPU shares
const minimumCPUUnit = 2

// NewTaskResponse creates a new response object for the task
func NewTaskResponse(
taskARN string,
Expand Down Expand Up @@ -218,6 +222,12 @@ func NewContainerResponse(
ExitCode: container.GetKnownExitCode(),
Labels: container.GetLabels(),
}

if container.CPU < minimumCPUUnit {
defaultCPU := func(val float64) *float64 { return &val }(minimumCPUUnit)
resp.Limits.CPU = defaultCPU
}

// V4 metadata endpoint calls this function for consistency across versions,
// but needs additional metadata only available at this scope.
if includeV4Metadata {
Expand Down

0 comments on commit cce8ef9

Please sign in to comment.