mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Update cAdvisor dependency.
Picks up fixes for events and OOM handling.
This commit is contained in:
parent
7505bed054
commit
b049a3cccf
64
Godeps/Godeps.json
generated
64
Godeps/Godeps.json
generated
@ -197,83 +197,83 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/api",
|
"ImportPath": "github.com/google/cadvisor/api",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/container",
|
"ImportPath": "github.com/google/cadvisor/container",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/events",
|
"ImportPath": "github.com/google/cadvisor/events",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/fs",
|
"ImportPath": "github.com/google/cadvisor/fs",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/healthz",
|
"ImportPath": "github.com/google/cadvisor/healthz",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/http",
|
"ImportPath": "github.com/google/cadvisor/http",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/info/v1",
|
"ImportPath": "github.com/google/cadvisor/info/v1",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/info/v2",
|
"ImportPath": "github.com/google/cadvisor/info/v2",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/manager",
|
"ImportPath": "github.com/google/cadvisor/manager",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/metrics",
|
"ImportPath": "github.com/google/cadvisor/metrics",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/pages",
|
"ImportPath": "github.com/google/cadvisor/pages",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/storage",
|
"ImportPath": "github.com/google/cadvisor/storage",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/summary",
|
"ImportPath": "github.com/google/cadvisor/summary",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/utils",
|
"ImportPath": "github.com/google/cadvisor/utils",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/validate",
|
"ImportPath": "github.com/google/cadvisor/validate",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/cadvisor/version",
|
"ImportPath": "github.com/google/cadvisor/version",
|
||||||
"Comment": "0.11.0-26-g417cd5e",
|
"Comment": "0.12.0-21-g3166552",
|
||||||
"Rev": "417cd5ead23d33eff717a41d3be80ea73bf307cd"
|
"Rev": "3166552cc4481e48dc1002e000d7e4ae8d5b9850"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/google/gofuzz",
|
"ImportPath": "github.com/google/gofuzz",
|
||||||
|
13
Godeps/_workspace/src/github.com/google/cadvisor/api/handler.go
generated
vendored
13
Godeps/_workspace/src/github.com/google/cadvisor/api/handler.go
generated
vendored
@ -67,7 +67,7 @@ const (
|
|||||||
func handleRequest(supportedApiVersions map[string]ApiVersion, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
func handleRequest(supportedApiVersions map[string]ApiVersion, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
glog.V(2).Infof("Request took %s", time.Since(start))
|
glog.V(4).Infof("Request took %s", time.Since(start))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
request := r.URL.Path
|
request := r.URL.Path
|
||||||
@ -151,11 +151,9 @@ func streamResults(eventChannel *events.EventChannel, w http.ResponseWriter, r *
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-cn.CloseNotify():
|
case <-cn.CloseNotify():
|
||||||
glog.V(3).Infof("Received CloseNotify event. About to return from api/handler:streamResults")
|
|
||||||
m.CloseEventChannel(eventChannel.GetWatchId())
|
m.CloseEventChannel(eventChannel.GetWatchId())
|
||||||
return nil
|
return nil
|
||||||
case ev := <-eventChannel.GetChannel():
|
case ev := <-eventChannel.GetChannel():
|
||||||
glog.V(3).Infof("Received event from watch channel in api: %v", ev)
|
|
||||||
err := enc.Encode(ev)
|
err := enc.Encode(ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("error encoding message %+v for result stream: %v", ev, err)
|
glog.Errorf("error encoding message %+v for result stream: %v", ev, err)
|
||||||
@ -207,6 +205,12 @@ func getEventRequest(r *http.Request) (*events.Request, bool, error) {
|
|||||||
query.EventType[info.EventOom] = newBool
|
query.EventType[info.EventOom] = newBool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if val, ok := urlMap["oom_kill_events"]; ok {
|
||||||
|
newBool, err := strconv.ParseBool(val[0])
|
||||||
|
if err == nil {
|
||||||
|
query.EventType[info.EventOomKill] = newBool
|
||||||
|
}
|
||||||
|
}
|
||||||
if val, ok := urlMap["creation_events"]; ok {
|
if val, ok := urlMap["creation_events"]; ok {
|
||||||
newBool, err := strconv.ParseBool(val[0])
|
newBool, err := strconv.ParseBool(val[0])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -238,9 +242,6 @@ func getEventRequest(r *http.Request) (*events.Request, bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(2).Infof(
|
|
||||||
"%v was returned in api/handler.go:getEventRequest from the url rawQuery %v",
|
|
||||||
query, r.URL.RawQuery)
|
|
||||||
return query, stream, nil
|
return query, stream, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
Godeps/_workspace/src/github.com/google/cadvisor/api/versions.go
generated
vendored
30
Godeps/_workspace/src/github.com/google/cadvisor/api/versions.go
generated
vendored
@ -17,6 +17,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@ -79,7 +80,7 @@ func (self *version1_0) SupportedRequestTypes() []string {
|
|||||||
func (self *version1_0) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
func (self *version1_0) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||||
switch requestType {
|
switch requestType {
|
||||||
case machineApi:
|
case machineApi:
|
||||||
glog.V(2).Infof("Api - Machine")
|
glog.V(4).Infof("Api - Machine")
|
||||||
|
|
||||||
// Get the MachineInfo
|
// Get the MachineInfo
|
||||||
machineInfo, err := m.GetMachineInfo()
|
machineInfo, err := m.GetMachineInfo()
|
||||||
@ -93,7 +94,7 @@ func (self *version1_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
}
|
}
|
||||||
case containersApi:
|
case containersApi:
|
||||||
containerName := getContainerName(request)
|
containerName := getContainerName(request)
|
||||||
glog.V(2).Infof("Api - Container(%s)", containerName)
|
glog.V(4).Infof("Api - Container(%s)", containerName)
|
||||||
|
|
||||||
// Get the query request.
|
// Get the query request.
|
||||||
query, err := getContainerInfoRequest(r.Body)
|
query, err := getContainerInfoRequest(r.Body)
|
||||||
@ -143,7 +144,7 @@ func (self *version1_1) HandleRequest(requestType string, request []string, m ma
|
|||||||
switch requestType {
|
switch requestType {
|
||||||
case subcontainersApi:
|
case subcontainersApi:
|
||||||
containerName := getContainerName(request)
|
containerName := getContainerName(request)
|
||||||
glog.V(2).Infof("Api - Subcontainers(%s)", containerName)
|
glog.V(4).Infof("Api - Subcontainers(%s)", containerName)
|
||||||
|
|
||||||
// Get the query request.
|
// Get the query request.
|
||||||
query, err := getContainerInfoRequest(r.Body)
|
query, err := getContainerInfoRequest(r.Body)
|
||||||
@ -192,7 +193,7 @@ func (self *version1_2) SupportedRequestTypes() []string {
|
|||||||
func (self *version1_2) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
func (self *version1_2) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||||
switch requestType {
|
switch requestType {
|
||||||
case dockerApi:
|
case dockerApi:
|
||||||
glog.V(2).Infof("Api - Docker(%v)", request)
|
glog.V(4).Infof("Api - Docker(%v)", request)
|
||||||
|
|
||||||
// Get the query request.
|
// Get the query request.
|
||||||
query, err := getContainerInfoRequest(r.Body)
|
query, err := getContainerInfoRequest(r.Body)
|
||||||
@ -261,18 +262,19 @@ func (self *version1_3) SupportedRequestTypes() []string {
|
|||||||
func (self *version1_3) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
func (self *version1_3) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||||
switch requestType {
|
switch requestType {
|
||||||
case eventsApi:
|
case eventsApi:
|
||||||
return handleEventRequest(m, w, r)
|
return handleEventRequest(request, m, w, r)
|
||||||
default:
|
default:
|
||||||
return self.baseVersion.HandleRequest(requestType, request, m, w, r)
|
return self.baseVersion.HandleRequest(requestType, request, m, w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleEventRequest(m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
func handleEventRequest(request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||||
query, stream, err := getEventRequest(r)
|
query, stream, err := getEventRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("Api - Events(%v)", query)
|
query.ContainerName = path.Join("/", getContainerName(request))
|
||||||
|
glog.V(4).Infof("Api - Events(%v)", query)
|
||||||
if !stream {
|
if !stream {
|
||||||
pastEvents, err := m.GetPastEvents(query)
|
pastEvents, err := m.GetPastEvents(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -312,14 +314,14 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
}
|
}
|
||||||
switch requestType {
|
switch requestType {
|
||||||
case versionApi:
|
case versionApi:
|
||||||
glog.V(2).Infof("Api - Version")
|
glog.V(4).Infof("Api - Version")
|
||||||
versionInfo, err := m.GetVersionInfo()
|
versionInfo, err := m.GetVersionInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return writeResult(versionInfo.CadvisorVersion, w)
|
return writeResult(versionInfo.CadvisorVersion, w)
|
||||||
case attributesApi:
|
case attributesApi:
|
||||||
glog.V(2).Info("Api - Attributes")
|
glog.V(4).Info("Api - Attributes")
|
||||||
|
|
||||||
machineInfo, err := m.GetMachineInfo()
|
machineInfo, err := m.GetMachineInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -332,7 +334,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
info := v2.GetAttributes(machineInfo, versionInfo)
|
info := v2.GetAttributes(machineInfo, versionInfo)
|
||||||
return writeResult(info, w)
|
return writeResult(info, w)
|
||||||
case machineApi:
|
case machineApi:
|
||||||
glog.V(2).Info("Api - Machine")
|
glog.V(4).Info("Api - Machine")
|
||||||
|
|
||||||
// TODO(rjnagal): Move machineInfo from v1.
|
// TODO(rjnagal): Move machineInfo from v1.
|
||||||
machineInfo, err := m.GetMachineInfo()
|
machineInfo, err := m.GetMachineInfo()
|
||||||
@ -342,7 +344,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
return writeResult(machineInfo, w)
|
return writeResult(machineInfo, w)
|
||||||
case summaryApi:
|
case summaryApi:
|
||||||
containerName := getContainerName(request)
|
containerName := getContainerName(request)
|
||||||
glog.V(2).Infof("Api - Summary for container %q, options %+v", containerName, opt)
|
glog.V(4).Infof("Api - Summary for container %q, options %+v", containerName, opt)
|
||||||
|
|
||||||
stats, err := m.GetDerivedStats(containerName, opt)
|
stats, err := m.GetDerivedStats(containerName, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -351,7 +353,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
return writeResult(stats, w)
|
return writeResult(stats, w)
|
||||||
case statsApi:
|
case statsApi:
|
||||||
name := getContainerName(request)
|
name := getContainerName(request)
|
||||||
glog.V(2).Infof("Api - Stats: Looking for stats for container %q, options %+v", name, opt)
|
glog.V(4).Infof("Api - Stats: Looking for stats for container %q, options %+v", name, opt)
|
||||||
conts, err := m.GetRequestedContainersInfo(name, opt)
|
conts, err := m.GetRequestedContainersInfo(name, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -363,7 +365,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
return writeResult(contStats, w)
|
return writeResult(contStats, w)
|
||||||
case specApi:
|
case specApi:
|
||||||
containerName := getContainerName(request)
|
containerName := getContainerName(request)
|
||||||
glog.V(2).Infof("Api - Spec for container %q, options %+v", containerName, opt)
|
glog.V(4).Infof("Api - Spec for container %q, options %+v", containerName, opt)
|
||||||
specs, err := m.GetContainerSpec(containerName, opt)
|
specs, err := m.GetContainerSpec(containerName, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -388,7 +390,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
}
|
}
|
||||||
return writeResult(fi, w)
|
return writeResult(fi, w)
|
||||||
case eventsApi:
|
case eventsApi:
|
||||||
return handleEventRequest(m, w, r)
|
return handleEventRequest(request, m, w, r)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown request type %q", requestType)
|
return fmt.Errorf("unknown request type %q", requestType)
|
||||||
}
|
}
|
||||||
|
6
Godeps/_workspace/src/github.com/google/cadvisor/container/factory.go
generated
vendored
6
Godeps/_workspace/src/github.com/google/cadvisor/container/factory.go
generated
vendored
@ -65,13 +65,13 @@ func NewContainerHandler(name string) (ContainerHandler, error) {
|
|||||||
for _, factory := range factories {
|
for _, factory := range factories {
|
||||||
canHandle, err := factory.CanHandle(name)
|
canHandle, err := factory.CanHandle(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(1).Infof("Error trying to work out if we can hande %s: %v", name, err)
|
glog.V(4).Infof("Error trying to work out if we can hande %s: %v", name, err)
|
||||||
}
|
}
|
||||||
if canHandle {
|
if canHandle {
|
||||||
glog.V(1).Infof("Using factory %q for container %q", factory, name)
|
glog.V(3).Infof("Using factory %q for container %q", factory, name)
|
||||||
return factory.NewContainerHandler(name)
|
return factory.NewContainerHandler(name)
|
||||||
} else {
|
} else {
|
||||||
glog.V(1).Infof("Factory %q was unable to handle container %q", factory, name)
|
glog.V(4).Infof("Factory %q was unable to handle container %q", factory, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
Godeps/_workspace/src/github.com/google/cadvisor/events/handler.go
generated
vendored
4
Godeps/_workspace/src/github.com/google/cadvisor/events/handler.go
generated
vendored
@ -174,7 +174,7 @@ func getMaxEventsReturned(request *Request, eSlice EventSlice) EventSlice {
|
|||||||
// equivalent
|
// equivalent
|
||||||
func checkIfIsSubcontainer(request *Request, event *info.Event) bool {
|
func checkIfIsSubcontainer(request *Request, event *info.Event) bool {
|
||||||
if request.IncludeSubcontainers == true {
|
if request.IncludeSubcontainers == true {
|
||||||
return strings.HasPrefix(event.ContainerName+"/", request.ContainerName+"/")
|
return request.ContainerName == "/" || strings.HasPrefix(event.ContainerName+"/", request.ContainerName+"/")
|
||||||
}
|
}
|
||||||
return event.ContainerName == request.ContainerName
|
return event.ContainerName == request.ContainerName
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ func (self *events) AddEvent(e *info.Event) error {
|
|||||||
for _, watchObject := range watchesToSend {
|
for _, watchObject := range watchesToSend {
|
||||||
watchObject.eventChannel.GetChannel() <- e
|
watchObject.eventChannel.GetChannel() <- e
|
||||||
}
|
}
|
||||||
glog.V(1).Infof("Added event %v", e)
|
glog.V(4).Infof("Added event %v", e)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
Godeps/_workspace/src/github.com/google/cadvisor/events/handler_test.go
generated
vendored
11
Godeps/_workspace/src/github.com/google/cadvisor/events/handler_test.go
generated
vendored
@ -67,6 +67,8 @@ func ensureProperEventReturned(t *testing.T, expectedEvent *info.Event, eventObj
|
|||||||
func TestCheckIfIsSubcontainer(t *testing.T) {
|
func TestCheckIfIsSubcontainer(t *testing.T) {
|
||||||
myRequest := NewRequest()
|
myRequest := NewRequest()
|
||||||
myRequest.ContainerName = "/root"
|
myRequest.ContainerName = "/root"
|
||||||
|
rootRequest := NewRequest()
|
||||||
|
rootRequest.ContainerName = "/"
|
||||||
|
|
||||||
sameContainerEvent := &info.Event{
|
sameContainerEvent := &info.Event{
|
||||||
ContainerName: "/root",
|
ContainerName: "/root",
|
||||||
@ -78,6 +80,10 @@ func TestCheckIfIsSubcontainer(t *testing.T) {
|
|||||||
ContainerName: "/root-completely-different-container",
|
ContainerName: "/root-completely-different-container",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if checkIfIsSubcontainer(rootRequest, sameContainerEvent) {
|
||||||
|
t.Errorf("should not have found %v to be a subcontainer of %v",
|
||||||
|
sameContainerEvent, rootRequest)
|
||||||
|
}
|
||||||
if !checkIfIsSubcontainer(myRequest, sameContainerEvent) {
|
if !checkIfIsSubcontainer(myRequest, sameContainerEvent) {
|
||||||
t.Errorf("should have found %v and %v had the same container name",
|
t.Errorf("should have found %v and %v had the same container name",
|
||||||
myRequest, sameContainerEvent)
|
myRequest, sameContainerEvent)
|
||||||
@ -87,8 +93,13 @@ func TestCheckIfIsSubcontainer(t *testing.T) {
|
|||||||
myRequest, subContainerEvent)
|
myRequest, subContainerEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rootRequest.IncludeSubcontainers = true
|
||||||
myRequest.IncludeSubcontainers = true
|
myRequest.IncludeSubcontainers = true
|
||||||
|
|
||||||
|
if !checkIfIsSubcontainer(rootRequest, sameContainerEvent) {
|
||||||
|
t.Errorf("should have found %v to be a subcontainer of %v",
|
||||||
|
sameContainerEvent.ContainerName, rootRequest.ContainerName)
|
||||||
|
}
|
||||||
if !checkIfIsSubcontainer(myRequest, sameContainerEvent) {
|
if !checkIfIsSubcontainer(myRequest, sameContainerEvent) {
|
||||||
t.Errorf("should have found %v and %v had the same container",
|
t.Errorf("should have found %v and %v had the same container",
|
||||||
myRequest.ContainerName, sameContainerEvent.ContainerName)
|
myRequest.ContainerName, sameContainerEvent.ContainerName)
|
||||||
|
15
Godeps/_workspace/src/github.com/google/cadvisor/info/v1/container.go
generated
vendored
15
Godeps/_workspace/src/github.com/google/cadvisor/info/v1/container.go
generated
vendored
@ -494,12 +494,13 @@ type Event struct {
|
|||||||
|
|
||||||
// EventType is an enumerated type which lists the categories under which
|
// EventType is an enumerated type which lists the categories under which
|
||||||
// events may fall. The Event field EventType is populated by this enum.
|
// events may fall. The Event field EventType is populated by this enum.
|
||||||
type EventType int
|
type EventType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EventOom EventType = iota
|
EventOom EventType = "oom"
|
||||||
EventContainerCreation
|
EventOomKill = "oomKill"
|
||||||
EventContainerDeletion
|
EventContainerCreation = "containerCreation"
|
||||||
|
EventContainerDeletion = "containerDeletion"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Extra information about an event. Only one type will be set.
|
// Extra information about an event. Only one type will be set.
|
||||||
@ -507,8 +508,8 @@ type EventData struct {
|
|||||||
// Information about a container creation event.
|
// Information about a container creation event.
|
||||||
Created *CreatedEventData `json:"created,omitempty"`
|
Created *CreatedEventData `json:"created,omitempty"`
|
||||||
|
|
||||||
// Information about an OOM event.
|
// Information about an OOM kill event.
|
||||||
Oom *OomEventData `json:"oom,omitempty"`
|
OomKill *OomKillEventData `json:"oom,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information related to a container creation event.
|
// Information related to a container creation event.
|
||||||
@ -518,7 +519,7 @@ type CreatedEventData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Information related to an OOM kill instance
|
// Information related to an OOM kill instance
|
||||||
type OomEventData struct {
|
type OomKillEventData struct {
|
||||||
// process id of the killed process
|
// process id of the killed process
|
||||||
Pid int `json:"pid"`
|
Pid int `json:"pid"`
|
||||||
|
|
||||||
|
3
Godeps/_workspace/src/github.com/google/cadvisor/manager/container.go
generated
vendored
3
Godeps/_workspace/src/github.com/google/cadvisor/manager/container.go
generated
vendored
@ -162,11 +162,9 @@ func (self *containerData) nextHousekeeping(lastHousekeeping time.Time) time.Tim
|
|||||||
if self.housekeepingInterval > *maxHousekeepingInterval {
|
if self.housekeepingInterval > *maxHousekeepingInterval {
|
||||||
self.housekeepingInterval = *maxHousekeepingInterval
|
self.housekeepingInterval = *maxHousekeepingInterval
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("Raising housekeeping interval for %q to %v", self.info.Name, self.housekeepingInterval)
|
|
||||||
} else if self.housekeepingInterval != *HousekeepingInterval {
|
} else if self.housekeepingInterval != *HousekeepingInterval {
|
||||||
// Lower interval back to the baseline.
|
// Lower interval back to the baseline.
|
||||||
self.housekeepingInterval = *HousekeepingInterval
|
self.housekeepingInterval = *HousekeepingInterval
|
||||||
glog.V(3).Infof("Lowering housekeeping interval for %q to %v", self.info.Name, self.housekeepingInterval)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +268,6 @@ func (c *containerData) updateLoad(newLoad uint64) {
|
|||||||
} else {
|
} else {
|
||||||
c.loadAvg = c.loadAvg*loadDecay + float64(newLoad)*(1.0-loadDecay)
|
c.loadAvg = c.loadAvg*loadDecay + float64(newLoad)*(1.0-loadDecay)
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("New load for %q: %v. latest sample: %d", c.info.Name, c.loadAvg, newLoad)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *containerData) updateStats() error {
|
func (c *containerData) updateStats() error {
|
||||||
|
26
Godeps/_workspace/src/github.com/google/cadvisor/manager/manager.go
generated
vendored
26
Godeps/_workspace/src/github.com/google/cadvisor/manager/manager.go
generated
vendored
@ -41,6 +41,7 @@ import (
|
|||||||
|
|
||||||
var globalHousekeepingInterval = flag.Duration("global_housekeeping_interval", 1*time.Minute, "Interval between global housekeepings")
|
var globalHousekeepingInterval = flag.Duration("global_housekeeping_interval", 1*time.Minute, "Interval between global housekeepings")
|
||||||
var logCadvisorUsage = flag.Bool("log_cadvisor_usage", false, "Whether to log the usage of the cAdvisor container")
|
var logCadvisorUsage = flag.Bool("log_cadvisor_usage", false, "Whether to log the usage of the cAdvisor container")
|
||||||
|
var enableLoadReader = flag.Bool("enable_load_reader", false, "Whether to enable cpu load reader")
|
||||||
|
|
||||||
// The Manager interface defines operations for starting a manager and getting
|
// The Manager interface defines operations for starting a manager and getting
|
||||||
// container and machine information.
|
// container and machine information.
|
||||||
@ -175,8 +176,8 @@ type manager struct {
|
|||||||
|
|
||||||
// Start the container manager.
|
// Start the container manager.
|
||||||
func (self *manager) Start() error {
|
func (self *manager) Start() error {
|
||||||
// TODO(rjnagal): Skip creating cpu load reader while we improve resource usage and accuracy.
|
|
||||||
if false {
|
if *enableLoadReader {
|
||||||
// Create cpu load reader.
|
// Create cpu load reader.
|
||||||
cpuLoadReader, err := cpuload.New()
|
cpuLoadReader, err := cpuload.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -273,7 +274,7 @@ func (self *manager) globalHousekeeping(quit chan error) {
|
|||||||
// Log if housekeeping took too long.
|
// Log if housekeeping took too long.
|
||||||
duration := time.Since(start)
|
duration := time.Since(start)
|
||||||
if duration >= longHousekeeping {
|
if duration >= longHousekeeping {
|
||||||
glog.V(1).Infof("Global Housekeeping(%d) took %s", t.Unix(), duration)
|
glog.V(3).Infof("Global Housekeeping(%d) took %s", t.Unix(), duration)
|
||||||
}
|
}
|
||||||
case <-quit:
|
case <-quit:
|
||||||
// Quit if asked to do so.
|
// Quit if asked to do so.
|
||||||
@ -878,21 +879,32 @@ func (self *manager) watchForNewOoms() error {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for oomInstance := range outStream {
|
for oomInstance := range outStream {
|
||||||
|
// Surface OOM and OOM kill events.
|
||||||
newEvent := &info.Event{
|
newEvent := &info.Event{
|
||||||
ContainerName: oomInstance.ContainerName,
|
ContainerName: oomInstance.ContainerName,
|
||||||
Timestamp: oomInstance.TimeOfDeath,
|
Timestamp: oomInstance.TimeOfDeath,
|
||||||
EventType: info.EventOom,
|
EventType: info.EventOom,
|
||||||
|
}
|
||||||
|
err := self.eventHandler.AddEvent(newEvent)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("failed to add OOM event for %q: %v", oomInstance.ContainerName, err)
|
||||||
|
}
|
||||||
|
glog.V(3).Infof("Created an OOM event in container %q at %v", oomInstance.ContainerName, oomInstance.TimeOfDeath)
|
||||||
|
|
||||||
|
newEvent = &info.Event{
|
||||||
|
ContainerName: oomInstance.VictimContainerName,
|
||||||
|
Timestamp: oomInstance.TimeOfDeath,
|
||||||
|
EventType: info.EventOomKill,
|
||||||
EventData: info.EventData{
|
EventData: info.EventData{
|
||||||
Oom: &info.OomEventData{
|
OomKill: &info.OomKillEventData{
|
||||||
Pid: oomInstance.Pid,
|
Pid: oomInstance.Pid,
|
||||||
ProcessName: oomInstance.ProcessName,
|
ProcessName: oomInstance.ProcessName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("Created an oom event: %v", newEvent)
|
err = self.eventHandler.AddEvent(newEvent)
|
||||||
err := self.eventHandler.AddEvent(newEvent)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("failed to add event %v, got error: %v", newEvent, err)
|
glog.Errorf("failed to add OOM kill event for %q: %v", oomInstance.ContainerName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
2
Godeps/_workspace/src/github.com/google/cadvisor/manager/manager_test.go
generated
vendored
2
Godeps/_workspace/src/github.com/google/cadvisor/manager/manager_test.go
generated
vendored
@ -81,7 +81,7 @@ func expectManagerWithContainers(containers []string, query *info.ContainerInfoR
|
|||||||
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
|
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
memoryStorage := memory.New(query.NumStats, nil)
|
memoryStorage := memory.New(time.Duration(query.NumStats)*time.Second, nil)
|
||||||
sysfs := &fakesysfs.FakeSysFs{}
|
sysfs := &fakesysfs.FakeSysFs{}
|
||||||
m := createManagerAndAddContainers(
|
m := createManagerAndAddContainers(
|
||||||
memoryStorage,
|
memoryStorage,
|
||||||
|
2
Godeps/_workspace/src/github.com/google/cadvisor/pages/containers.go
generated
vendored
2
Godeps/_workspace/src/github.com/google/cadvisor/pages/containers.go
generated
vendored
@ -242,6 +242,6 @@ func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) e
|
|||||||
glog.Errorf("Failed to apply template: %s", err)
|
glog.Errorf("Failed to apply template: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("Request took %s", time.Since(start))
|
glog.V(5).Infof("Request took %s", time.Since(start))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
2
Godeps/_workspace/src/github.com/google/cadvisor/pages/docker.go
generated
vendored
2
Godeps/_workspace/src/github.com/google/cadvisor/pages/docker.go
generated
vendored
@ -111,6 +111,6 @@ func serveDockerPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error
|
|||||||
glog.Errorf("Failed to apply template: %s", err)
|
glog.Errorf("Failed to apply template: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("Request took %s", time.Since(start))
|
glog.V(5).Infof("Request took %s", time.Since(start))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
28
Godeps/_workspace/src/github.com/google/cadvisor/storage/memory/memory.go
generated
vendored
28
Godeps/_workspace/src/github.com/google/cadvisor/storage/memory/memory.go
generated
vendored
@ -22,14 +22,15 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
"github.com/google/cadvisor/storage"
|
"github.com/google/cadvisor/storage"
|
||||||
|
"github.com/google/cadvisor/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO(vmarmol): See about refactoring this class, we have an unecessary redirection of containerStorage and InMemoryStorage.
|
// TODO(vmarmol): See about refactoring this class, we have an unecessary redirection of containerStorage and InMemoryStorage.
|
||||||
// containerStorage is used to store per-container information
|
// containerStorage is used to store per-container information
|
||||||
type containerStorage struct {
|
type containerStorage struct {
|
||||||
ref info.ContainerReference
|
ref info.ContainerReference
|
||||||
recentStats *StatsBuffer
|
recentStats *utils.TimedStore
|
||||||
maxNumStats int
|
maxAge time.Duration
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,28 +39,33 @@ func (self *containerStorage) AddStats(stats *info.ContainerStats) error {
|
|||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
|
|
||||||
// Add the stat to storage.
|
// Add the stat to storage.
|
||||||
self.recentStats.Add(stats)
|
self.recentStats.Add(stats.Timestamp, stats)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *containerStorage) RecentStats(start, end time.Time, maxStats int) ([]*info.ContainerStats, error) {
|
func (self *containerStorage) RecentStats(start, end time.Time, maxStats int) ([]*info.ContainerStats, error) {
|
||||||
self.lock.RLock()
|
self.lock.RLock()
|
||||||
defer self.lock.RUnlock()
|
defer self.lock.RUnlock()
|
||||||
return self.recentStats.InTimeRange(start, end, maxStats), nil
|
result := self.recentStats.InTimeRange(start, end, maxStats)
|
||||||
|
converted := make([]*info.ContainerStats, len(result))
|
||||||
|
for i, el := range result {
|
||||||
|
converted[i] = el.(*info.ContainerStats)
|
||||||
|
}
|
||||||
|
return converted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContainerStore(ref info.ContainerReference, maxNumStats int) *containerStorage {
|
func newContainerStore(ref info.ContainerReference, maxAge time.Duration) *containerStorage {
|
||||||
return &containerStorage{
|
return &containerStorage{
|
||||||
ref: ref,
|
ref: ref,
|
||||||
recentStats: NewStatsBuffer(maxNumStats),
|
recentStats: utils.NewTimedStore(maxAge),
|
||||||
maxNumStats: maxNumStats,
|
maxAge: maxAge,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type InMemoryStorage struct {
|
type InMemoryStorage struct {
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
containerStorageMap map[string]*containerStorage
|
containerStorageMap map[string]*containerStorage
|
||||||
maxNumStats int
|
maxAge time.Duration
|
||||||
backend storage.StorageDriver
|
backend storage.StorageDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +77,7 @@ func (self *InMemoryStorage) AddStats(ref info.ContainerReference, stats *info.C
|
|||||||
self.lock.Lock()
|
self.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
if cstore, ok = self.containerStorageMap[ref.Name]; !ok {
|
if cstore, ok = self.containerStorageMap[ref.Name]; !ok {
|
||||||
cstore = newContainerStore(ref, self.maxNumStats)
|
cstore = newContainerStore(ref, self.maxAge)
|
||||||
self.containerStorageMap[ref.Name] = cstore
|
self.containerStorageMap[ref.Name] = cstore
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -113,12 +119,12 @@ func (self *InMemoryStorage) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
maxNumStats int,
|
maxAge time.Duration,
|
||||||
backend storage.StorageDriver,
|
backend storage.StorageDriver,
|
||||||
) *InMemoryStorage {
|
) *InMemoryStorage {
|
||||||
ret := &InMemoryStorage{
|
ret := &InMemoryStorage{
|
||||||
containerStorageMap: make(map[string]*containerStorage, 32),
|
containerStorageMap: make(map[string]*containerStorage, 32),
|
||||||
maxNumStats: maxNumStats,
|
maxAge: maxAge,
|
||||||
backend: backend,
|
backend: backend,
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
4
Godeps/_workspace/src/github.com/google/cadvisor/storage/memory/memory_test.go
generated
vendored
4
Godeps/_workspace/src/github.com/google/cadvisor/storage/memory/memory_test.go
generated
vendored
@ -47,7 +47,7 @@ func getRecentStats(t *testing.T, memoryStorage *InMemoryStorage, numStats int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddStats(t *testing.T) {
|
func TestAddStats(t *testing.T) {
|
||||||
memoryStorage := New(60, nil)
|
memoryStorage := New(60*time.Second, nil)
|
||||||
|
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
assert.Nil(memoryStorage.AddStats(containerRef, makeStat(0)))
|
assert.Nil(memoryStorage.AddStats(containerRef, makeStat(0)))
|
||||||
@ -70,7 +70,7 @@ func TestRecentStatsNoRecentStats(t *testing.T) {
|
|||||||
|
|
||||||
// Make an instance of InMemoryStorage with n stats.
|
// Make an instance of InMemoryStorage with n stats.
|
||||||
func makeWithStats(n int) *InMemoryStorage {
|
func makeWithStats(n int) *InMemoryStorage {
|
||||||
memoryStorage := New(60, nil)
|
memoryStorage := New(60*time.Second, nil)
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
memoryStorage.AddStats(containerRef, makeStat(i))
|
memoryStorage.AddStats(containerRef, makeStat(i))
|
||||||
|
3
Godeps/_workspace/src/github.com/google/cadvisor/summary/percentiles.go
generated
vendored
3
Godeps/_workspace/src/github.com/google/cadvisor/summary/percentiles.go
generated
vendored
@ -21,7 +21,6 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
info "github.com/google/cadvisor/info/v2"
|
info "github.com/google/cadvisor/info/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -172,10 +171,8 @@ func GetMinutePercentiles(stats []*secondSample) info.Usage {
|
|||||||
if !lastSample.Timestamp.IsZero() {
|
if !lastSample.Timestamp.IsZero() {
|
||||||
cpuRate, err := getCpuRate(*stat, lastSample)
|
cpuRate, err := getCpuRate(*stat, lastSample)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(3).Infof("Skipping sample, %v", err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("Adding cpu rate sample : %d", cpuRate)
|
|
||||||
cpu.AddSample(cpuRate)
|
cpu.AddSample(cpuRate)
|
||||||
memory.AddSample(stat.Memory)
|
memory.AddSample(stat.Memory)
|
||||||
} else {
|
} else {
|
||||||
|
4
Godeps/_workspace/src/github.com/google/cadvisor/utils/cpuload/netlink/reader.go
generated
vendored
4
Godeps/_workspace/src/github.com/google/cadvisor/utils/cpuload/netlink/reader.go
generated
vendored
@ -37,7 +37,7 @@ func New() (*NetlinkReader, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get netlink family id for task stats: %s", err)
|
return nil, fmt.Errorf("failed to get netlink family id for task stats: %s", err)
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("Family id for taskstats: %d", id)
|
glog.V(4).Infof("Family id for taskstats: %d", id)
|
||||||
return &NetlinkReader{
|
return &NetlinkReader{
|
||||||
familyId: id,
|
familyId: id,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
@ -73,6 +73,6 @@ func (self *NetlinkReader) GetCpuLoad(name string, path string) (info.LoadStats,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return info.LoadStats{}, err
|
return info.LoadStats{}, err
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("Task stats for %q: %+v", path, stats)
|
glog.V(4).Infof("Task stats for %q: %+v", path, stats)
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
27
Godeps/_workspace/src/github.com/google/cadvisor/utils/oomparser/oomparser.go
generated
vendored
27
Godeps/_workspace/src/github.com/google/cadvisor/utils/oomparser/oomparser.go
generated
vendored
@ -16,7 +16,7 @@ package oomparser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -30,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var containerRegexp *regexp.Regexp = regexp.MustCompile(
|
var containerRegexp *regexp.Regexp = regexp.MustCompile(
|
||||||
`Task in (.*) killed as a result of limit of `)
|
`Task in (.*) killed as a result of limit of (.*)`)
|
||||||
var lastLineRegexp *regexp.Regexp = regexp.MustCompile(
|
var lastLineRegexp *regexp.Regexp = regexp.MustCompile(
|
||||||
`(^[A-Z]{1}[a-z]{2} .*[0-9]{1,2} [0-9]{1,2}:[0-9]{2}:[0-9]{2}) .* Killed process ([0-9]+) \(([0-9A-Za-z_]+)\)`)
|
`(^[A-Z]{1}[a-z]{2} .*[0-9]{1,2} [0-9]{1,2}:[0-9]{2}:[0-9]{2}) .* Killed process ([0-9]+) \(([0-9A-Za-z_]+)\)`)
|
||||||
var firstLineRegexp *regexp.Regexp = regexp.MustCompile(
|
var firstLineRegexp *regexp.Regexp = regexp.MustCompile(
|
||||||
@ -52,6 +52,9 @@ type OomInstance struct {
|
|||||||
TimeOfDeath time.Time
|
TimeOfDeath time.Time
|
||||||
// the absolute name of the container that OOMed
|
// the absolute name of the container that OOMed
|
||||||
ContainerName string
|
ContainerName string
|
||||||
|
// the absolute name of the container that was killed
|
||||||
|
// due to the OOM.
|
||||||
|
VictimContainerName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets the container name from a line and adds it to the oomInstance.
|
// gets the container name from a line and adds it to the oomInstance.
|
||||||
@ -61,6 +64,7 @@ func getContainerName(line string, currentOomInstance *OomInstance) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
currentOomInstance.ContainerName = path.Join("/", parsedLine[1])
|
currentOomInstance.ContainerName = path.Join("/", parsedLine[1])
|
||||||
|
currentOomInstance.VictimContainerName = path.Join("/", parsedLine[2])
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,17 +187,20 @@ func trySystemd() (*OomParser, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List of possible kernel log files. These are prioritized in order so that
|
||||||
|
// we will use the first one that is available.
|
||||||
|
var kernelLogFiles = []string{"/var/log/kern.log", "/var/log/messages", "/var/log/syslog"}
|
||||||
|
|
||||||
// looks for system files that contain kernel messages and if one is found, sets
|
// looks for system files that contain kernel messages and if one is found, sets
|
||||||
// the systemFile attribute of the OomParser object
|
// the systemFile attribute of the OomParser object
|
||||||
func getSystemFile() (string, error) {
|
func getSystemFile() (string, error) {
|
||||||
const varLogMessages = "/var/log/messages"
|
for _, logFile := range kernelLogFiles {
|
||||||
const varLogSyslog = "/var/log/syslog"
|
if utils.FileExists(logFile) {
|
||||||
if utils.FileExists(varLogMessages) {
|
glog.Infof("OOM parser using kernel log file: %q", logFile)
|
||||||
return varLogMessages, nil
|
return logFile, nil
|
||||||
} else if utils.FileExists(varLogSyslog) {
|
}
|
||||||
return varLogSyslog, nil
|
|
||||||
}
|
}
|
||||||
return "", errors.New("neither " + varLogSyslog + " nor " + varLogMessages + " exists from which to read kernel errors")
|
return "", fmt.Errorf("unable to find any kernel log file available from our set: %v", kernelLogFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
// initializes an OomParser object and calls getSystemFile to set the systemFile
|
// initializes an OomParser object and calls getSystemFile to set the systemFile
|
||||||
@ -201,12 +208,10 @@ func getSystemFile() (string, error) {
|
|||||||
func New() (*OomParser, error) {
|
func New() (*OomParser, error) {
|
||||||
systemFile, err := getSystemFile()
|
systemFile, err := getSystemFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(1).Infof("received error %v when calling getSystemFile", err)
|
|
||||||
return trySystemd()
|
return trySystemd()
|
||||||
}
|
}
|
||||||
file, err := os.Open(systemFile)
|
file, err := os.Open(systemFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(1).Infof("received error %v when opening file", err)
|
|
||||||
return trySystemd()
|
return trySystemd()
|
||||||
}
|
}
|
||||||
return &OomParser{
|
return &OomParser{
|
||||||
|
26
Godeps/_workspace/src/github.com/google/cadvisor/utils/oomparser/oomparser_test.go
generated
vendored
26
Godeps/_workspace/src/github.com/google/cadvisor/utils/oomparser/oomparser_test.go
generated
vendored
@ -17,13 +17,14 @@ package oomparser
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const startLine = "Jan 21 22:01:49 localhost kernel: [62278.816267] ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0"
|
const startLine = "Jan 21 22:01:49 localhost kernel: [62278.816267] ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0"
|
||||||
const endLine = "Jan 21 22:01:49 localhost kernel: [62279.421192] Killed process 19667 (evilprogram2) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB"
|
const endLine = "Jan 21 22:01:49 localhost kernel: [62279.421192] Killed process 19667 (evilprogram2) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB"
|
||||||
const containerLine = "Jan 26 14:10:07 kateknister0.mtv.corp.google.com kernel: [1814368.465205] Task in /mem2 killed as a result of limit of /mem2"
|
const containerLine = "Jan 26 14:10:07 kateknister0.mtv.corp.google.com kernel: [1814368.465205] Task in /mem2 killed as a result of limit of /mem3"
|
||||||
const containerLogFile = "containerOomExampleLog.txt"
|
const containerLogFile = "containerOomExampleLog.txt"
|
||||||
const systemLogFile = "systemOomExampleLog.txt"
|
const systemLogFile = "systemOomExampleLog.txt"
|
||||||
|
|
||||||
@ -35,10 +36,11 @@ func createExpectedContainerOomInstance(t *testing.T) *OomInstance {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &OomInstance{
|
return &OomInstance{
|
||||||
Pid: 13536,
|
Pid: 13536,
|
||||||
ProcessName: "memorymonster",
|
ProcessName: "memorymonster",
|
||||||
TimeOfDeath: deathTime,
|
TimeOfDeath: deathTime,
|
||||||
ContainerName: "/mem2",
|
ContainerName: "/mem2",
|
||||||
|
VictimContainerName: "/mem3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,10 +52,11 @@ func createExpectedSystemOomInstance(t *testing.T) *OomInstance {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &OomInstance{
|
return &OomInstance{
|
||||||
Pid: 1532,
|
Pid: 1532,
|
||||||
ProcessName: "badsysprogram",
|
ProcessName: "badsysprogram",
|
||||||
TimeOfDeath: deathTime,
|
TimeOfDeath: deathTime,
|
||||||
ContainerName: "/",
|
ContainerName: "/",
|
||||||
|
VictimContainerName: "/",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +76,9 @@ func TestGetContainerName(t *testing.T) {
|
|||||||
if currentOomInstance.ContainerName != "/mem2" {
|
if currentOomInstance.ContainerName != "/mem2" {
|
||||||
t.Errorf("getContainerName should have set containerName to /mem2, not %s", currentOomInstance.ContainerName)
|
t.Errorf("getContainerName should have set containerName to /mem2, not %s", currentOomInstance.ContainerName)
|
||||||
}
|
}
|
||||||
|
if currentOomInstance.VictimContainerName != "/mem3" {
|
||||||
|
t.Errorf("getContainerName should have set victimContainerName to /mem3, not %s", currentOomInstance.VictimContainerName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetProcessNamePid(t *testing.T) {
|
func TestGetProcessNamePid(t *testing.T) {
|
||||||
@ -139,7 +145,7 @@ func helpTestStreamOoms(oomCheckInstance *OomInstance, sysFile string, t *testin
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case oomInstance := <-outStream:
|
case oomInstance := <-outStream:
|
||||||
if *oomCheckInstance != *oomInstance {
|
if reflect.DeepEqual(*oomCheckInstance, *oomInstance) {
|
||||||
t.Errorf("wrong instance returned. Expected %v and got %v",
|
t.Errorf("wrong instance returned. Expected %v and got %v",
|
||||||
oomCheckInstance, oomInstance)
|
oomCheckInstance, oomInstance)
|
||||||
}
|
}
|
||||||
|
@ -12,48 +12,57 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package memory
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A circular buffer for ContainerStats.
|
// A time-based buffer for ContainerStats. Holds information for a specific time period.
|
||||||
type StatsBuffer struct {
|
type TimedStore struct {
|
||||||
buffer []*info.ContainerStats
|
buffer []timedStoreData
|
||||||
size int
|
age time.Duration
|
||||||
index int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a new thread-compatible StatsBuffer.
|
type timedStoreData struct {
|
||||||
func NewStatsBuffer(size int) *StatsBuffer {
|
timestamp time.Time
|
||||||
return &StatsBuffer{
|
data interface{}
|
||||||
buffer: make([]*info.ContainerStats, size),
|
}
|
||||||
size: 0,
|
|
||||||
index: size - 1,
|
// Returns a new thread-compatible TimedStore.
|
||||||
|
func NewTimedStore(age time.Duration) *TimedStore {
|
||||||
|
return &TimedStore{
|
||||||
|
buffer: make([]timedStoreData, 0),
|
||||||
|
age: age,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an element to the start of the buffer (removing one from the end if necessary).
|
// Adds an element to the start of the buffer (removing one from the end if necessary).
|
||||||
func (self *StatsBuffer) Add(item *info.ContainerStats) {
|
func (self *TimedStore) Add(timestamp time.Time, item interface{}) {
|
||||||
if self.size < len(self.buffer) {
|
// Remove any elements before the eviction time.
|
||||||
self.size++
|
evictTime := timestamp.Add(-self.age)
|
||||||
|
index := sort.Search(len(self.buffer), func(index int) bool {
|
||||||
|
return self.buffer[index].timestamp.After(evictTime)
|
||||||
|
})
|
||||||
|
if index < len(self.buffer) {
|
||||||
|
self.buffer = self.buffer[index:]
|
||||||
}
|
}
|
||||||
self.index = (self.index + 1) % len(self.buffer)
|
|
||||||
copied := *item
|
copied := item
|
||||||
self.buffer[self.index] = &copied
|
self.buffer = append(self.buffer, timedStoreData{
|
||||||
|
timestamp: timestamp,
|
||||||
|
data: copied,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns up to maxResult elements in the specified time period (inclusive).
|
// Returns up to maxResult elements in the specified time period (inclusive).
|
||||||
// Results are from first to last. maxResults of -1 means no limit. When first
|
// Results are from first to last. maxResults of -1 means no limit. When first
|
||||||
// and last are specified, maxResults is ignored.
|
// and last are specified, maxResults is ignored.
|
||||||
func (self *StatsBuffer) InTimeRange(start, end time.Time, maxResults int) []*info.ContainerStats {
|
func (self *TimedStore) InTimeRange(start, end time.Time, maxResults int) []interface{} {
|
||||||
// No stats, return empty.
|
// No stats, return empty.
|
||||||
if self.size == 0 {
|
if len(self.buffer) == 0 {
|
||||||
return []*info.ContainerStats{}
|
return []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return all results in a time range if specified.
|
// Return all results in a time range if specified.
|
||||||
@ -67,18 +76,18 @@ func (self *StatsBuffer) InTimeRange(start, end time.Time, maxResults int) []*in
|
|||||||
var startIndex int
|
var startIndex int
|
||||||
if start.IsZero() {
|
if start.IsZero() {
|
||||||
// None specified, start at the beginning.
|
// None specified, start at the beginning.
|
||||||
startIndex = self.size - 1
|
startIndex = len(self.buffer) - 1
|
||||||
} else {
|
} else {
|
||||||
// Start is the index before the elements smaller than it. We do this by
|
// Start is the index before the elements smaller than it. We do this by
|
||||||
// finding the first element smaller than start and taking the index
|
// finding the first element smaller than start and taking the index
|
||||||
// before that element
|
// before that element
|
||||||
startIndex = sort.Search(self.size, func(index int) bool {
|
startIndex = sort.Search(len(self.buffer), func(index int) bool {
|
||||||
// buffer[index] < start
|
// buffer[index] < start
|
||||||
return self.Get(index).Timestamp.Before(start)
|
return self.getData(index).timestamp.Before(start)
|
||||||
}) - 1
|
}) - 1
|
||||||
// Check if start is after all the data we have.
|
// Check if start is after all the data we have.
|
||||||
if startIndex < 0 {
|
if startIndex < 0 {
|
||||||
return []*info.ContainerStats{}
|
return []interface{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,13 +97,13 @@ func (self *StatsBuffer) InTimeRange(start, end time.Time, maxResults int) []*in
|
|||||||
endIndex = 0
|
endIndex = 0
|
||||||
} else {
|
} else {
|
||||||
// End is the first index smaller than or equal to it (so, not larger).
|
// End is the first index smaller than or equal to it (so, not larger).
|
||||||
endIndex = sort.Search(self.size, func(index int) bool {
|
endIndex = sort.Search(len(self.buffer), func(index int) bool {
|
||||||
// buffer[index] <= t -> !(buffer[index] > t)
|
// buffer[index] <= t -> !(buffer[index] > t)
|
||||||
return !self.Get(index).Timestamp.After(end)
|
return !self.getData(index).timestamp.After(end)
|
||||||
})
|
})
|
||||||
// Check if end is before all the data we have.
|
// Check if end is before all the data we have.
|
||||||
if endIndex == self.size {
|
if endIndex == len(self.buffer) {
|
||||||
return []*info.ContainerStats{}
|
return []interface{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,46 +115,23 @@ func (self *StatsBuffer) InTimeRange(start, end time.Time, maxResults int) []*in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return in sorted timestamp order so from the "back" to "front".
|
// Return in sorted timestamp order so from the "back" to "front".
|
||||||
result := make([]*info.ContainerStats, numResults)
|
result := make([]interface{}, numResults)
|
||||||
for i := 0; i < numResults; i++ {
|
for i := 0; i < numResults; i++ {
|
||||||
result[i] = self.Get(startIndex - i)
|
result[i] = self.Get(startIndex - i)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(vmarmol): Remove this function as it will no longer be neededt.
|
// Gets the element at the specified index. Note that elements are output in LIFO order.
|
||||||
// Returns the first N elements in the buffer. If N > size of buffer, size of buffer elements are returned.
|
func (self *TimedStore) Get(index int) interface{} {
|
||||||
// Returns the elements in ascending timestamp order.
|
return self.getData(index).data
|
||||||
func (self *StatsBuffer) FirstN(n int) []*info.ContainerStats {
|
|
||||||
// Cap n at the number of elements we have.
|
|
||||||
if n > self.size {
|
|
||||||
n = self.size
|
|
||||||
}
|
|
||||||
|
|
||||||
// index points to the latest element, get n before that one (keeping in mind we may have gone through 0).
|
|
||||||
start := self.index - (n - 1)
|
|
||||||
if start < 0 {
|
|
||||||
start += len(self.buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the elements.
|
|
||||||
res := make([]*info.ContainerStats, n)
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
index := (start + i) % len(self.buffer)
|
|
||||||
res[i] = self.buffer[index]
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the element at the specified index. Note that elements are stored in LIFO order.
|
// Gets the data at the specified index. Note that elements are output in LIFO order.
|
||||||
func (self *StatsBuffer) Get(index int) *info.ContainerStats {
|
func (self *TimedStore) getData(index int) timedStoreData {
|
||||||
calculatedIndex := self.index - index
|
return self.buffer[len(self.buffer)-index-1]
|
||||||
if calculatedIndex < 0 {
|
|
||||||
calculatedIndex += len(self.buffer)
|
|
||||||
}
|
|
||||||
return self.buffer[calculatedIndex]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StatsBuffer) Size() int {
|
func (self *TimedStore) Size() int {
|
||||||
return self.size
|
return len(self.buffer)
|
||||||
}
|
}
|
@ -12,15 +12,12 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package memory
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,92 +26,78 @@ func createTime(id int) time.Time {
|
|||||||
return zero.Add(time.Duration(id+1) * time.Second)
|
return zero.Add(time.Duration(id+1) * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createStats(id int32) *info.ContainerStats {
|
func expectSize(t *testing.T, sb *TimedStore, expectedSize int) {
|
||||||
return &info.ContainerStats{
|
|
||||||
Timestamp: createTime(int(id)),
|
|
||||||
Cpu: info.CpuStats{
|
|
||||||
LoadAverage: id,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func expectSize(t *testing.T, sb *StatsBuffer, expectedSize int) {
|
|
||||||
if sb.Size() != expectedSize {
|
if sb.Size() != expectedSize {
|
||||||
t.Errorf("Expected size %v, got %v", expectedSize, sb.Size())
|
t.Errorf("Expected size %v, got %v", expectedSize, sb.Size())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectFirstN(t *testing.T, sb *StatsBuffer, expected []int32) {
|
func expectAllElements(t *testing.T, sb *TimedStore, expected []int) {
|
||||||
expectElements(t, sb.FirstN(sb.Size()), expected)
|
size := sb.Size()
|
||||||
|
els := make([]interface{}, size)
|
||||||
|
for i := 0; i < size; i++ {
|
||||||
|
els[i] = sb.Get(size - i - 1)
|
||||||
|
}
|
||||||
|
expectElements(t, []interface{}(els), expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectElements(t *testing.T, actual []*info.ContainerStats, expected []int32) {
|
func expectElements(t *testing.T, actual []interface{}, expected []int) {
|
||||||
if len(actual) != len(expected) {
|
if len(actual) != len(expected) {
|
||||||
t.Errorf("Expected elements %v, got %v", expected, actual)
|
t.Errorf("Expected elements %v, got %v", expected, actual)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i, el := range actual {
|
for i, el := range actual {
|
||||||
if el.Cpu.LoadAverage != expected[i] {
|
if el.(int) != expected[i] {
|
||||||
actualElements := make([]string, len(actual))
|
t.Errorf("Expected elements %v, got %v", expected, actual)
|
||||||
for i, element := range actual {
|
|
||||||
actualElements[i] = strconv.Itoa(int(element.Cpu.LoadAverage))
|
|
||||||
}
|
|
||||||
t.Errorf("Expected elements %v, got %v", expected, strings.Join(actualElements, ","))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectElement(t *testing.T, stat *info.ContainerStats, expected int32) {
|
func TestAdd(t *testing.T) {
|
||||||
if stat.Cpu.LoadAverage != expected {
|
sb := NewTimedStore(5 * time.Second)
|
||||||
t.Errorf("Expected %d, but received %d", expected, stat.Cpu.LoadAverage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAddAndFirstN(t *testing.T) {
|
|
||||||
sb := NewStatsBuffer(5)
|
|
||||||
|
|
||||||
// Add 1.
|
// Add 1.
|
||||||
sb.Add(createStats(1))
|
sb.Add(createTime(0), 0)
|
||||||
expectSize(t, sb, 1)
|
expectSize(t, sb, 1)
|
||||||
expectFirstN(t, sb, []int32{1})
|
expectAllElements(t, sb, []int{0})
|
||||||
|
|
||||||
// Fill the buffer.
|
// Fill the buffer.
|
||||||
for i := 1; i <= 5; i++ {
|
for i := 1; i <= 5; i++ {
|
||||||
expectSize(t, sb, i)
|
expectSize(t, sb, i)
|
||||||
sb.Add(createStats(int32(i)))
|
sb.Add(createTime(i), i)
|
||||||
}
|
}
|
||||||
expectSize(t, sb, 5)
|
expectSize(t, sb, 5)
|
||||||
expectFirstN(t, sb, []int32{1, 2, 3, 4, 5})
|
expectAllElements(t, sb, []int{1, 2, 3, 4, 5})
|
||||||
|
|
||||||
// Add more than is available in the buffer
|
// Add more than is available in the buffer
|
||||||
sb.Add(createStats(6))
|
sb.Add(createTime(6), 6)
|
||||||
expectSize(t, sb, 5)
|
expectSize(t, sb, 5)
|
||||||
expectFirstN(t, sb, []int32{2, 3, 4, 5, 6})
|
expectAllElements(t, sb, []int{2, 3, 4, 5, 6})
|
||||||
|
|
||||||
// Replace all elements.
|
// Replace all elements.
|
||||||
for i := 7; i <= 10; i++ {
|
for i := 7; i <= 10; i++ {
|
||||||
sb.Add(createStats(int32(i)))
|
sb.Add(createTime(i), i)
|
||||||
}
|
}
|
||||||
expectSize(t, sb, 5)
|
expectSize(t, sb, 5)
|
||||||
expectFirstN(t, sb, []int32{6, 7, 8, 9, 10})
|
expectAllElements(t, sb, []int{6, 7, 8, 9, 10})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
sb := NewStatsBuffer(5)
|
sb := NewTimedStore(5 * time.Second)
|
||||||
sb.Add(createStats(1))
|
sb.Add(createTime(1), 1)
|
||||||
sb.Add(createStats(2))
|
sb.Add(createTime(2), 2)
|
||||||
sb.Add(createStats(3))
|
sb.Add(createTime(3), 3)
|
||||||
expectSize(t, sb, 3)
|
expectSize(t, sb, 3)
|
||||||
expectFirstN(t, sb, []int32{1, 2, 3})
|
|
||||||
|
|
||||||
expectElement(t, sb.Get(0), 3)
|
assert := assert.New(t)
|
||||||
expectElement(t, sb.Get(1), 2)
|
assert.Equal(sb.Get(0).(int), 3)
|
||||||
expectElement(t, sb.Get(2), 1)
|
assert.Equal(sb.Get(1).(int), 2)
|
||||||
|
assert.Equal(sb.Get(2).(int), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInTimeRange(t *testing.T) {
|
func TestInTimeRange(t *testing.T) {
|
||||||
sb := NewStatsBuffer(5)
|
sb := NewTimedStore(5 * time.Second)
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
var empty time.Time
|
var empty time.Time
|
||||||
@ -126,60 +109,60 @@ func TestInTimeRange(t *testing.T) {
|
|||||||
assert.Empty(sb.InTimeRange(empty, empty, 10))
|
assert.Empty(sb.InTimeRange(empty, empty, 10))
|
||||||
|
|
||||||
// One element.
|
// One element.
|
||||||
sb.Add(createStats(1))
|
sb.Add(createTime(1), 1)
|
||||||
expectSize(t, sb, 1)
|
expectSize(t, sb, 1)
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int32{1})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int{1})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 10), []int32{1})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 10), []int{1})
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(1), 10), []int32{1})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(1), 10), []int{1})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(1), 10), []int32{1})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(1), 10), []int{1})
|
||||||
assert.Empty(sb.InTimeRange(createTime(2), createTime(5), 10))
|
assert.Empty(sb.InTimeRange(createTime(2), createTime(5), 10))
|
||||||
|
|
||||||
// Two element.
|
// Two element.
|
||||||
sb.Add(createStats(2))
|
sb.Add(createTime(2), 2)
|
||||||
expectSize(t, sb, 2)
|
expectSize(t, sb, 2)
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(2), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(2), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(2), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(2), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(1), 10), []int32{1})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(1), 10), []int{1})
|
||||||
expectElements(t, sb.InTimeRange(createTime(2), createTime(2), 10), []int32{2})
|
expectElements(t, sb.InTimeRange(createTime(2), createTime(2), 10), []int{2})
|
||||||
assert.Empty(sb.InTimeRange(createTime(3), createTime(5), 10))
|
assert.Empty(sb.InTimeRange(createTime(3), createTime(5), 10))
|
||||||
|
|
||||||
// Many elements.
|
// Many elements.
|
||||||
sb.Add(createStats(3))
|
sb.Add(createTime(3), 3)
|
||||||
sb.Add(createStats(4))
|
sb.Add(createTime(4), 4)
|
||||||
expectSize(t, sb, 4)
|
expectSize(t, sb, 4)
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(5), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(4), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(4), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(4), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(4), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), createTime(2), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(createTime(0), createTime(2), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(2), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(2), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(createTime(2), createTime(3), 10), []int32{2, 3})
|
expectElements(t, sb.InTimeRange(createTime(2), createTime(3), 10), []int{2, 3})
|
||||||
expectElements(t, sb.InTimeRange(createTime(3), createTime(4), 10), []int32{3, 4})
|
expectElements(t, sb.InTimeRange(createTime(3), createTime(4), 10), []int{3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(3), createTime(5), 10), []int32{3, 4})
|
expectElements(t, sb.InTimeRange(createTime(3), createTime(5), 10), []int{3, 4})
|
||||||
assert.Empty(sb.InTimeRange(createTime(5), createTime(5), 10))
|
assert.Empty(sb.InTimeRange(createTime(5), createTime(5), 10))
|
||||||
|
|
||||||
// Start and end time ignores maxResults.
|
// Start and end time ignores maxResults.
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 1), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 1), []int{1, 2, 3, 4})
|
||||||
|
|
||||||
// No start time.
|
// No start time.
|
||||||
expectElements(t, sb.InTimeRange(empty, createTime(5), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(empty, createTime(5), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(empty, createTime(4), 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(empty, createTime(4), 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(empty, createTime(3), 10), []int32{1, 2, 3})
|
expectElements(t, sb.InTimeRange(empty, createTime(3), 10), []int{1, 2, 3})
|
||||||
expectElements(t, sb.InTimeRange(empty, createTime(2), 10), []int32{1, 2})
|
expectElements(t, sb.InTimeRange(empty, createTime(2), 10), []int{1, 2})
|
||||||
expectElements(t, sb.InTimeRange(empty, createTime(1), 10), []int32{1})
|
expectElements(t, sb.InTimeRange(empty, createTime(1), 10), []int{1})
|
||||||
|
|
||||||
// No end time.
|
// No end time.
|
||||||
expectElements(t, sb.InTimeRange(createTime(0), empty, 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(0), empty, 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(1), empty, 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(1), empty, 10), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(2), empty, 10), []int32{2, 3, 4})
|
expectElements(t, sb.InTimeRange(createTime(2), empty, 10), []int{2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(3), empty, 10), []int32{3, 4})
|
expectElements(t, sb.InTimeRange(createTime(3), empty, 10), []int{3, 4})
|
||||||
expectElements(t, sb.InTimeRange(createTime(4), empty, 10), []int32{4})
|
expectElements(t, sb.InTimeRange(createTime(4), empty, 10), []int{4})
|
||||||
|
|
||||||
// No start or end time.
|
// No start or end time.
|
||||||
expectElements(t, sb.InTimeRange(empty, empty, 10), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(empty, empty, 10), []int{1, 2, 3, 4})
|
||||||
|
|
||||||
// Start after data.
|
// Start after data.
|
||||||
assert.Empty(sb.InTimeRange(createTime(5), createTime(5), 10))
|
assert.Empty(sb.InTimeRange(createTime(5), createTime(5), 10))
|
||||||
@ -191,19 +174,19 @@ func TestInTimeRange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInTimeRangeWithLimit(t *testing.T) {
|
func TestInTimeRangeWithLimit(t *testing.T) {
|
||||||
sb := NewStatsBuffer(5)
|
sb := NewTimedStore(5 * time.Second)
|
||||||
sb.Add(createStats(1))
|
sb.Add(createTime(1), 1)
|
||||||
sb.Add(createStats(2))
|
sb.Add(createTime(2), 2)
|
||||||
sb.Add(createStats(3))
|
sb.Add(createTime(3), 3)
|
||||||
sb.Add(createStats(4))
|
sb.Add(createTime(4), 4)
|
||||||
expectSize(t, sb, 4)
|
expectSize(t, sb, 4)
|
||||||
|
|
||||||
var empty time.Time
|
var empty time.Time
|
||||||
|
|
||||||
// Limit cuts off from latest timestamp.
|
// Limit cuts off from latest timestamp.
|
||||||
expectElements(t, sb.InTimeRange(empty, empty, 4), []int32{1, 2, 3, 4})
|
expectElements(t, sb.InTimeRange(empty, empty, 4), []int{1, 2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(empty, empty, 3), []int32{2, 3, 4})
|
expectElements(t, sb.InTimeRange(empty, empty, 3), []int{2, 3, 4})
|
||||||
expectElements(t, sb.InTimeRange(empty, empty, 2), []int32{3, 4})
|
expectElements(t, sb.InTimeRange(empty, empty, 2), []int{3, 4})
|
||||||
expectElements(t, sb.InTimeRange(empty, empty, 1), []int32{4})
|
expectElements(t, sb.InTimeRange(empty, empty, 1), []int{4})
|
||||||
assert.Empty(t, sb.InTimeRange(empty, empty, 0))
|
assert.Empty(t, sb.InTimeRange(empty, empty, 0))
|
||||||
}
|
}
|
2
Godeps/_workspace/src/github.com/google/cadvisor/version/version.go
generated
vendored
2
Godeps/_workspace/src/github.com/google/cadvisor/version/version.go
generated
vendored
@ -15,4 +15,4 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
// Version of cAdvisor.
|
// Version of cAdvisor.
|
||||||
const VERSION = "0.11.0"
|
const VERSION = "0.12.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user