mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add option to enable networkDB debug
Add a new configuration option to allow the enabling of the networkDB debug. The option is only parsed using the reload event. This will protect the daemon on start or restart if the option is left behind in the config file Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
parent
d9dbca2e19
commit
a97e45794e
4 changed files with 110 additions and 20 deletions
|
@ -59,6 +59,8 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
|
||||||
flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
|
flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
|
||||||
flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
|
flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
|
||||||
flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout")
|
flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout")
|
||||||
|
flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server")
|
||||||
|
flags.MarkHidden("network-diagnostic-port")
|
||||||
|
|
||||||
flags.StringVar(&conf.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
|
flags.StringVar(&conf.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
|
||||||
flags.BoolVar(&conf.Experimental, "experimental", false, "Enable experimental features")
|
flags.BoolVar(&conf.Experimental, "experimental", false, "Enable experimental features")
|
||||||
|
|
|
@ -98,6 +98,7 @@ type CommonConfig struct {
|
||||||
GraphOptions []string `json:"storage-opts,omitempty"`
|
GraphOptions []string `json:"storage-opts,omitempty"`
|
||||||
Labels []string `json:"labels,omitempty"`
|
Labels []string `json:"labels,omitempty"`
|
||||||
Mtu int `json:"mtu,omitempty"`
|
Mtu int `json:"mtu,omitempty"`
|
||||||
|
NetworkDiagnosticPort int `json:"network-diagnostic-port,omitempty"`
|
||||||
Pidfile string `json:"pidfile,omitempty"`
|
Pidfile string `json:"pidfile,omitempty"`
|
||||||
RawLogs bool `json:"raw-logs,omitempty"`
|
RawLogs bool `json:"raw-logs,omitempty"`
|
||||||
RootDeprecated string `json:"graph,omitempty"`
|
RootDeprecated string `json:"graph,omitempty"`
|
||||||
|
|
|
@ -61,6 +61,9 @@ func (daemon *Daemon) Reload(conf *config.Config) (err error) {
|
||||||
if err := daemon.reloadLiveRestore(conf, attributes); err != nil {
|
if err := daemon.reloadLiveRestore(conf, attributes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := daemon.reloadNetworkDiagnosticPort(conf, attributes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,3 +311,18 @@ func (daemon *Daemon) reloadLiveRestore(conf *config.Config, attributes map[stri
|
||||||
attributes["live-restore"] = fmt.Sprintf("%t", daemon.configStore.LiveRestoreEnabled)
|
attributes["live-restore"] = fmt.Sprintf("%t", daemon.configStore.LiveRestoreEnabled)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reloadNetworkDiagnosticPort updates the network controller starting the diagnose mode if the config is valid
|
||||||
|
func (daemon *Daemon) reloadNetworkDiagnosticPort(conf *config.Config, attributes map[string]string) error {
|
||||||
|
if conf == nil || daemon.netController == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Enable the network diagnose if the flag is set with a valid port withing the range
|
||||||
|
if conf.IsValueSet("network-diagnostic-port") && conf.NetworkDiagnosticPort > 0 && conf.NetworkDiagnosticPort < 65536 {
|
||||||
|
logrus.Warnf("Calling the diagnostic start with %d", conf.NetworkDiagnosticPort)
|
||||||
|
daemon.netController.StartDiagnose(conf.NetworkDiagnosticPort)
|
||||||
|
} else {
|
||||||
|
daemon.netController.StopDiagnose()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/docker/docker/pkg/discovery"
|
"github.com/docker/docker/pkg/discovery"
|
||||||
_ "github.com/docker/docker/pkg/discovery/memory"
|
_ "github.com/docker/docker/pkg/discovery/memory"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
|
"github.com/docker/libnetwork"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -479,3 +480,71 @@ func TestDaemonDiscoveryReloadOnlyClusterAdvertise(t *testing.T) {
|
||||||
t.Fatal(e)
|
t.Fatal(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) {
|
||||||
|
daemon := &Daemon{}
|
||||||
|
daemon.configStore = &config.Config{}
|
||||||
|
|
||||||
|
valuesSet := make(map[string]interface{})
|
||||||
|
valuesSet["network-diagnostic-port"] = 2000
|
||||||
|
enableConfig := &config.Config{
|
||||||
|
CommonConfig: config.CommonConfig{
|
||||||
|
NetworkDiagnosticPort: 2000,
|
||||||
|
ValuesSet: valuesSet,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
disableConfig := &config.Config{
|
||||||
|
CommonConfig: config.CommonConfig{},
|
||||||
|
}
|
||||||
|
|
||||||
|
netOptions, err := daemon.networkOptions(enableConfig, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
controller, err := libnetwork.New(netOptions...)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
daemon.netController = controller
|
||||||
|
|
||||||
|
// Enable/Disable the server for some iterations
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
enableConfig.CommonConfig.NetworkDiagnosticPort++
|
||||||
|
if err := daemon.Reload(enableConfig); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Check that the diagnose is enabled
|
||||||
|
if !daemon.netController.IsDiagnoseEnabled() {
|
||||||
|
t.Fatalf("diagnosed should be enable")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload
|
||||||
|
if err := daemon.Reload(disableConfig); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Check that the diagnose is disabled
|
||||||
|
if daemon.netController.IsDiagnoseEnabled() {
|
||||||
|
t.Fatalf("diagnosed should be disable")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enableConfig.CommonConfig.NetworkDiagnosticPort++
|
||||||
|
// 2 times the enable should not create problems
|
||||||
|
if err := daemon.Reload(enableConfig); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Check that the diagnose is enabled
|
||||||
|
if !daemon.netController.IsDiagnoseEnabled() {
|
||||||
|
t.Fatalf("diagnosed should be enable")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that another reload does not cause issues
|
||||||
|
if err := daemon.Reload(enableConfig); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Check that the diagnose is enable
|
||||||
|
if !daemon.netController.IsDiagnoseEnabled() {
|
||||||
|
t.Fatalf("diagnosed should be enable")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue