mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
oversubscription: adds CLI and API support
This commit updates the API to pass the MemoryMaxMB field, and the CLI to show
the max set for the task.
Also, start parsing the MemoryMaxMB in hcl2, as it's set by tags.
A sample CLI output; note the additional `Max: ` for "task":
```
$ nomad alloc status 96fbeb0b
ID = 96fbeb0b-a0b3-aa95-62bf-b8a39492fd5c
[...]
Task "cgroup-fetcher" is "running"
Task Resources
CPU Memory Disk Addresses
0/500 MHz 32 MiB/20 MiB 300 MiB
Task Events:
[...]
Task "task" is "running"
Task Resources
CPU Memory Disk Addresses
0/500 MHz 176 KiB/20 MiB 300 MiB
Max: 30 MiB
Task Events:
[...]
```
This commit is contained in:
@@ -511,7 +511,8 @@ type AllocatedCpuResources struct {
|
||||
}
|
||||
|
||||
type AllocatedMemoryResources struct {
|
||||
MemoryMB int64
|
||||
MemoryMB int64
|
||||
MemoryMaxMB int64
|
||||
}
|
||||
|
||||
type AllocatedDeviceResource struct {
|
||||
|
||||
@@ -7,12 +7,13 @@ import (
|
||||
// Resources encapsulates the required resources of
|
||||
// a given task or task group.
|
||||
type Resources struct {
|
||||
CPU *int `hcl:"cpu,optional"`
|
||||
Cores *int `hcl:"cores,optional"`
|
||||
MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"`
|
||||
DiskMB *int `mapstructure:"disk" hcl:"disk,optional"`
|
||||
Networks []*NetworkResource `hcl:"network,block"`
|
||||
Devices []*RequestedDevice `hcl:"device,block"`
|
||||
CPU *int `hcl:"cpu,optional"`
|
||||
Cores *int `hcl:"cores,optional"`
|
||||
MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"`
|
||||
MemoryMaxMB *int `mapstructure:"memory_max" hcl:"memory_max,optional"`
|
||||
DiskMB *int `mapstructure:"disk" hcl:"disk,optional"`
|
||||
Networks []*NetworkResource `hcl:"network,block"`
|
||||
Devices []*RequestedDevice `hcl:"device,block"`
|
||||
|
||||
// COMPAT(0.10)
|
||||
// XXX Deprecated. Please do not use. The field will be removed in Nomad
|
||||
|
||||
@@ -1193,6 +1193,10 @@ func ApiResourcesToStructs(in *api.Resources) *structs.Resources {
|
||||
out.Cores = *in.Cores
|
||||
}
|
||||
|
||||
if in.MemoryMaxMB != nil {
|
||||
out.MemoryMaxMB = *in.MemoryMaxMB
|
||||
}
|
||||
|
||||
// COMPAT(0.10): Only being used to issue warnings
|
||||
if in.IOPS != nil {
|
||||
out.IOPS = *in.IOPS
|
||||
|
||||
@@ -2930,6 +2930,53 @@ func TestConversion_apiLogConfigToStructs(t *testing.T) {
|
||||
}))
|
||||
}
|
||||
|
||||
func TestConversion_apiResourcesToStructs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
input *api.Resources
|
||||
expected *structs.Resources
|
||||
}{
|
||||
{
|
||||
"nil",
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"plain",
|
||||
&api.Resources{
|
||||
CPU: helper.IntToPtr(100),
|
||||
MemoryMB: helper.IntToPtr(200),
|
||||
},
|
||||
&structs.Resources{
|
||||
CPU: 100,
|
||||
MemoryMB: 200,
|
||||
},
|
||||
},
|
||||
{
|
||||
"with memory max",
|
||||
&api.Resources{
|
||||
CPU: helper.IntToPtr(100),
|
||||
MemoryMB: helper.IntToPtr(200),
|
||||
MemoryMaxMB: helper.IntToPtr(300),
|
||||
},
|
||||
&structs.Resources{
|
||||
CPU: 100,
|
||||
MemoryMB: 200,
|
||||
MemoryMaxMB: 300,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
found := ApiResourcesToStructs(c.input)
|
||||
require.Equal(t, c.expected, found)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConversion_apiConnectSidecarTaskToStructs(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.Nil(t, apiConnectSidecarTaskToStructs(nil))
|
||||
|
||||
@@ -563,13 +563,21 @@ func (c *AllocStatusCommand) outputTaskResources(alloc *api.Allocation, task str
|
||||
var resourcesOutput []string
|
||||
resourcesOutput = append(resourcesOutput, "CPU|Memory|Disk|Addresses")
|
||||
firstAddr := ""
|
||||
secondAddr := ""
|
||||
if len(addr) > 0 {
|
||||
firstAddr = addr[0]
|
||||
}
|
||||
if len(addr) > 1 {
|
||||
secondAddr = addr[1]
|
||||
}
|
||||
|
||||
// Display the rolled up stats. If possible prefer the live statistics
|
||||
cpuUsage := strconv.Itoa(*resource.CPU)
|
||||
memUsage := humanize.IBytes(uint64(*resource.MemoryMB * bytesPerMegabyte))
|
||||
memMax := ""
|
||||
if max := resource.MemoryMaxMB; max != nil && *max != 0 && *max != *resource.MemoryMB {
|
||||
memMax = "Max: " + humanize.IBytes(uint64(*resource.MemoryMaxMB*bytesPerMegabyte))
|
||||
}
|
||||
var deviceStats []*api.DeviceGroupStats
|
||||
|
||||
if stats != nil {
|
||||
@@ -588,7 +596,10 @@ func (c *AllocStatusCommand) outputTaskResources(alloc *api.Allocation, task str
|
||||
memUsage,
|
||||
humanize.IBytes(uint64(*alloc.Resources.DiskMB*bytesPerMegabyte)),
|
||||
firstAddr))
|
||||
for i := 1; i < len(addr); i++ {
|
||||
if memMax != "" || secondAddr != "" {
|
||||
resourcesOutput = append(resourcesOutput, fmt.Sprintf("|%v||%v", memMax, secondAddr))
|
||||
}
|
||||
for i := 2; i < len(addr); i++ {
|
||||
resourcesOutput = append(resourcesOutput, fmt.Sprintf("|||%v", addr[i]))
|
||||
}
|
||||
c.Ui.Output(formatListWithSpaces(resourcesOutput))
|
||||
|
||||
3
vendor/github.com/hashicorp/nomad/api/allocations.go
generated
vendored
3
vendor/github.com/hashicorp/nomad/api/allocations.go
generated
vendored
@@ -511,7 +511,8 @@ type AllocatedCpuResources struct {
|
||||
}
|
||||
|
||||
type AllocatedMemoryResources struct {
|
||||
MemoryMB int64
|
||||
MemoryMB int64
|
||||
MemoryMaxMB int64
|
||||
}
|
||||
|
||||
type AllocatedDeviceResource struct {
|
||||
|
||||
13
vendor/github.com/hashicorp/nomad/api/resources.go
generated
vendored
13
vendor/github.com/hashicorp/nomad/api/resources.go
generated
vendored
@@ -7,12 +7,13 @@ import (
|
||||
// Resources encapsulates the required resources of
|
||||
// a given task or task group.
|
||||
type Resources struct {
|
||||
CPU *int `hcl:"cpu,optional"`
|
||||
Cores *int `hcl:"cores,optional"`
|
||||
MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"`
|
||||
DiskMB *int `mapstructure:"disk" hcl:"disk,optional"`
|
||||
Networks []*NetworkResource `hcl:"network,block"`
|
||||
Devices []*RequestedDevice `hcl:"device,block"`
|
||||
CPU *int `hcl:"cpu,optional"`
|
||||
Cores *int `hcl:"cores,optional"`
|
||||
MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"`
|
||||
MemoryMaxMB *int `mapstructure:"memory_max" hcl:"memory_max,optional"`
|
||||
DiskMB *int `mapstructure:"disk" hcl:"disk,optional"`
|
||||
Networks []*NetworkResource `hcl:"network,block"`
|
||||
Devices []*RequestedDevice `hcl:"device,block"`
|
||||
|
||||
// COMPAT(0.10)
|
||||
// XXX Deprecated. Please do not use. The field will be removed in Nomad
|
||||
|
||||
Reference in New Issue
Block a user