From 0525d40a4a91dbe641898e4bddad3dc540918f14 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Thu, 21 May 2015 13:48:03 -0700 Subject: [PATCH] Add DebugInfo() API and put the information on /validate --- container/docker/factory.go | 4 ++++ container/factory.go | 17 +++++++++++++++++ container/factory_test.go | 4 ++++ manager/manager.go | 7 +++++++ validate/validate.go | 7 +++++++ 5 files changed, 39 insertions(+) diff --git a/container/docker/factory.go b/container/docker/factory.go index ec5c26e0..b8cd4ad2 100644 --- a/container/docker/factory.go +++ b/container/docker/factory.go @@ -149,6 +149,10 @@ func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) { return true, canAccept, nil } +func (self *dockerFactory) DebugInfo() map[string][]string { + return map[string][]string{} +} + func parseDockerVersion(full_version_string string) ([]int, error) { version_regexp_string := "(\\d+)\\.(\\d+)\\.(\\d+)" version_re := regexp.MustCompile(version_regexp_string) diff --git a/container/factory.go b/container/factory.go index 04a26b17..d5ab8290 100644 --- a/container/factory.go +++ b/container/factory.go @@ -30,6 +30,9 @@ type ContainerHandlerFactory interface { // Name of the factory. String() string + + // Returns debugging information. Map of lines per category. + DebugInfo() map[string][]string } // TODO(vmarmol): Consider not making this global. @@ -90,3 +93,17 @@ func ClearContainerHandlerFactories() { factories = make([]ContainerHandlerFactory, 0, 4) } + +func DebugInfo() map[string][]string { + factoriesLock.RLock() + defer factoriesLock.RUnlock() + + // Get debug information for all factories. + out := make(map[string][]string) + for _, factory := range factories { + for k, v := range factory.DebugInfo() { + out[k] = v + } + } + return out +} diff --git a/container/factory_test.go b/container/factory_test.go index 535fcb07..991c365a 100644 --- a/container/factory_test.go +++ b/container/factory_test.go @@ -31,6 +31,10 @@ func (self *mockContainerHandlerFactory) String() string { return self.Name } +func (self *mockContainerHandlerFactory) DebugInfo() map[string][]string { + return map[string][]string{} +} + func (self *mockContainerHandlerFactory) CanHandleAndAccept(name string) (bool, bool, error) { return self.CanHandleValue, self.CanAcceptValue, nil } diff --git a/manager/manager.go b/manager/manager.go index 6b9e3715..d06f8e80 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -107,6 +107,9 @@ type Manager interface { // Get details about interesting docker images. DockerImages() ([]DockerImage, error) + + // Returns debugging information. Map of lines per category. + DebugInfo() map[string][]string } // New takes a memory storage and returns a new manager. @@ -1131,3 +1134,7 @@ func (m *manager) DockerInfo() (DockerStatus, error) { } return out, nil } + +func (m *manager) DebugInfo() map[string][]string { + return container.DebugInfo() +} diff --git a/validate/validate.go b/validate/validate.go index 5534d0de..264b3444 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -313,6 +313,13 @@ func HandleRequest(w http.ResponseWriter, containerManager manager.Manager) erro ioSchedulerValidation, desc := validateIoScheduler(containerManager) out += fmt.Sprintf(OutputFormat, "Block device setup", ioSchedulerValidation, desc) + + // Output debug info. + debugInfo := containerManager.DebugInfo() + for category, lines := range debugInfo { + out += fmt.Sprintf(OutputFormat, category, "", strings.Join(lines, "\n\t")) + } + _, err = w.Write([]byte(out)) return err }