Skip to content

Commit

Permalink
Added exporting cpu/mem limits based on Kubernetes rather than cadvisor
Browse files Browse the repository at this point in the history
  • Loading branch information
piosz committed Jul 14, 2015
1 parent 13d86fc commit 041549e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions sinks/api/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ func TestRealInput(t *testing.T) {
case "cpu/limit":
value, ok := entry.Point.Value.(int64)
require.True(t, ok)
expected := (spec.Cpu.Limit * 1000) / 1024
assert.Equal(t, expected, value)
assert.Equal(t, spec.Cpu.Limit, value)
case "memory/limit":
value, ok := entry.Point.Value.(int64)
require.True(t, ok)
Expand Down
3 changes: 1 addition & 2 deletions sinks/api/v1/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ func TestRealInput(t *testing.T) {
case "cpu/limit":
value, ok := entry.Point.Value.(int64)
require.True(t, ok)
expected := (spec.Cpu.Limit * 1000) / 1024
assert.Equal(t, expected, value)
assert.Equal(t, spec.Cpu.Limit, value)
case "memory/limit":
value, ok := entry.Point.Value.(int64)
require.True(t, ok)
Expand Down
3 changes: 1 addition & 2 deletions sinks/api/v1/supported_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ var statMetrics = []SupportedStatMetric{
return spec.HasCpu && (spec.Cpu.Limit > 0)
},
GetValue: func(spec *cadvisor.ContainerSpec, stat *cadvisor.ContainerStats) []InternalPoint {
// Normalize to a conversion factor of 1000.
return []InternalPoint{{Value: int64(spec.Cpu.Limit*1000) / 1024}}
return []InternalPoint{{Value: int64(spec.Cpu.Limit)}}
},
OnlyExportIfChanged: true,
},
Expand Down
3 changes: 3 additions & 0 deletions sources/kube_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (self *kubeNodeMetrics) updateStats(host nodes.Host, info nodes.Info, start
hostContainer = &hostCopy
containers = append(containers[:hostIndex], containers[hostIndex+1:]...)
}
// This is temporary workaround for #399.
hostContainer.Spec.Cpu.Limit = info.CpuCapacity
hostContainer.Spec.Memory.Limit = info.MemCapacity
return hostContainer, containers, nil
}

Expand Down
4 changes: 2 additions & 2 deletions sources/nodes/coreos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func TestSuccessCase(t *testing.T) {
nodeList, err := nodesApi.List()
require.NoError(t, err)
assert.Len(t, nodeList.Items, 2)
assert.Equal(t, nodeList.Items["a"], Info{"1.2.3.4", "1.2.3.4", ""})
assert.Equal(t, nodeList.Items["b"], Info{"1.2.3.5", "1.2.3.5", ""})
assert.Equal(t, nodeList.Items["a"], Info{"1.2.3.4", "1.2.3.4", "", 0, 0})
assert.Equal(t, nodeList.Items["b"], Info{"1.2.3.5", "1.2.3.5", "", 0, 0})
}

func TestFailureCase(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions sources/nodes/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (self *kubeNodes) getNodeInfoAndHostname(node api.Node) (Info, string, erro
if node.Spec.ExternalID != "" {
nodeInfo.ExternalID = node.Spec.ExternalID
}
cpu := node.Status.Capacity[api.ResourceCPU]
mem := node.Status.Capacity[api.ResourceMemory]
nodeInfo.CpuCapacity = uint64(cpu.MilliValue())
nodeInfo.MemCapacity = uint64(mem.Value())
return nodeInfo, hostname, nodeErr
}

Expand Down
4 changes: 4 additions & 0 deletions sources/nodes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type Info struct {
InternalIP string
// An optional ID assigned to nodes by either the cloud provider or user.
ExternalID string
// Cpu capacity of node in millicores.
CpuCapacity uint64
// Memory capacity of node in bytes.
MemCapacity uint64
}

// NodeList contains the nodes that an instance of heapster is required to
Expand Down

0 comments on commit 041549e

Please sign in to comment.