Skip to content

Commit 71e14dd

Browse files
committed
Remove always-on watch for networks and endpoints
Always on watching of networks and endpoints can affect scalability of the cluster beyond a few nodes. Remove pro active watching and watch only the objects you are interested in. Signed-off-by: Jana Radhakrishnan <[email protected]>
1 parent d74384b commit 71e14dd

18 files changed

Lines changed: 937 additions & 714 deletions

libnetwork/api/api_test.go

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/docker/docker/pkg/reexec"
1616
"github.com/docker/libnetwork"
17+
"github.com/docker/libnetwork/datastore"
1718
"github.com/docker/libnetwork/netlabel"
1819
"github.com/docker/libnetwork/options"
1920
"github.com/docker/libnetwork/testutils"
@@ -88,11 +89,13 @@ func i2sbL(i interface{}) []*sandboxResource {
8889
}
8990

9091
func createTestNetwork(t *testing.T, network string) (libnetwork.NetworkController, libnetwork.Network) {
92+
// Cleanup local datastore file
93+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
94+
9195
c, err := libnetwork.New()
9296
if err != nil {
9397
t.Fatal(err)
9498
}
95-
defer c.Stop()
9699

97100
netOption := options.Generic{
98101
netlabel.GenericData: options.Generic{
@@ -175,6 +178,9 @@ func TestJson(t *testing.T) {
175178
func TestCreateDeleteNetwork(t *testing.T) {
176179
defer testutils.SetupTestOSContext(t)()
177180

181+
// Cleanup local datastore file
182+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
183+
178184
c, err := libnetwork.New()
179185
if err != nil {
180186
t.Fatal(err)
@@ -249,6 +255,9 @@ func TestCreateDeleteNetwork(t *testing.T) {
249255
func TestGetNetworksAndEndpoints(t *testing.T) {
250256
defer testutils.SetupTestOSContext(t)()
251257

258+
// Cleanup local datastore file
259+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
260+
252261
c, err := libnetwork.New()
253262
if err != nil {
254263
t.Fatal(err)
@@ -518,6 +527,9 @@ func TestGetNetworksAndEndpoints(t *testing.T) {
518527
func TestProcGetServices(t *testing.T) {
519528
defer testutils.SetupTestOSContext(t)()
520529

530+
// Cleanup local datastore file
531+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
532+
521533
c, err := libnetwork.New()
522534
if err != nil {
523535
t.Fatal(err)
@@ -686,6 +698,7 @@ func TestProcGetService(t *testing.T) {
686698
defer testutils.SetupTestOSContext(t)()
687699

688700
c, nw := createTestNetwork(t, "network")
701+
defer c.Stop()
689702
ep1, err := nw.CreateEndpoint("db")
690703
if err != nil {
691704
t.Fatal(err)
@@ -738,6 +751,8 @@ func TestProcPublishUnpublishService(t *testing.T) {
738751
defer testutils.SetupTestOSContext(t)()
739752

740753
c, _ := createTestNetwork(t, "network")
754+
defer c.Stop()
755+
741756
vars := make(map[string]string)
742757

743758
vbad, err := json.Marshal("bad service create data")
@@ -870,6 +885,7 @@ func TestAttachDetachBackend(t *testing.T) {
870885
defer testutils.SetupTestOSContext(t)()
871886

872887
c, nw := createTestNetwork(t, "network")
888+
defer c.Stop()
873889
ep1, err := nw.CreateEndpoint("db")
874890
if err != nil {
875891
t.Fatal(err)
@@ -994,6 +1010,9 @@ func TestAttachDetachBackend(t *testing.T) {
9941010
}
9951011

9961012
func TestDetectGetNetworksInvalidQueryComposition(t *testing.T) {
1013+
// Cleanup local datastore file
1014+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
1015+
9971016
c, err := libnetwork.New()
9981017
if err != nil {
9991018
t.Fatal(err)
@@ -1011,6 +1030,7 @@ func TestDetectGetEndpointsInvalidQueryComposition(t *testing.T) {
10111030
defer testutils.SetupTestOSContext(t)()
10121031

10131032
c, _ := createTestNetwork(t, "network")
1033+
defer c.Stop()
10141034

10151035
vars := map[string]string{urlNwName: "network", urlEpName: "x", urlEpPID: "y"}
10161036
_, errRsp := procGetEndpoints(c, vars, nil)
@@ -1023,6 +1043,7 @@ func TestDetectGetServicesInvalidQueryComposition(t *testing.T) {
10231043
defer testutils.SetupTestOSContext(t)()
10241044

10251045
c, _ := createTestNetwork(t, "network")
1046+
defer c.Stop()
10261047

10271048
vars := map[string]string{urlNwName: "network", urlEpName: "x", urlEpPID: "y"}
10281049
_, errRsp := procGetServices(c, vars, nil)
@@ -1040,6 +1061,8 @@ func TestFindNetworkUtil(t *testing.T) {
10401061
defer testutils.SetupTestOSContext(t)()
10411062

10421063
c, nw := createTestNetwork(t, "network")
1064+
defer c.Stop()
1065+
10431066
nid := nw.ID()
10441067

10451068
_, errRsp := findNetwork(c, "", byName)
@@ -1102,6 +1125,9 @@ func TestFindNetworkUtil(t *testing.T) {
11021125
func TestCreateDeleteEndpoints(t *testing.T) {
11031126
defer testutils.SetupTestOSContext(t)()
11041127

1128+
// Cleanup local datastore file
1129+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
1130+
11051131
c, err := libnetwork.New()
11061132
if err != nil {
11071133
t.Fatal(err)
@@ -1225,6 +1251,9 @@ func TestCreateDeleteEndpoints(t *testing.T) {
12251251
func TestJoinLeave(t *testing.T) {
12261252
defer testutils.SetupTestOSContext(t)()
12271253

1254+
// Cleanup local datastore file
1255+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
1256+
12281257
c, err := libnetwork.New()
12291258
if err != nil {
12301259
t.Fatal(err)
@@ -1382,6 +1411,8 @@ func TestFindEndpointUtilPanic(t *testing.T) {
13821411
defer testutils.SetupTestOSContext(t)()
13831412
defer checkPanic(t)
13841413
c, nw := createTestNetwork(t, "network")
1414+
defer c.Stop()
1415+
13851416
nid := nw.ID()
13861417
findEndpoint(c, nid, "", byID, -1)
13871418
}
@@ -1390,13 +1421,17 @@ func TestFindServiceUtilPanic(t *testing.T) {
13901421
defer testutils.SetupTestOSContext(t)()
13911422
defer checkPanic(t)
13921423
c, _ := createTestNetwork(t, "network")
1424+
defer c.Stop()
1425+
13931426
findService(c, "random_service", -1)
13941427
}
13951428

13961429
func TestFindEndpointUtil(t *testing.T) {
13971430
defer testutils.SetupTestOSContext(t)()
13981431

13991432
c, nw := createTestNetwork(t, "network")
1433+
defer c.Stop()
1434+
14001435
nid := nw.ID()
14011436

14021437
ep, err := nw.CreateEndpoint("secondEp", nil)
@@ -1443,7 +1478,8 @@ func TestFindEndpointUtil(t *testing.T) {
14431478
t.Fatalf("Unexepected failure: %v", errRsp)
14441479
}
14451480

1446-
if ep0 != ep1 || ep0 != ep2 || ep0 != ep3 || ep0 != ep4 || ep0 != ep5 {
1481+
if ep0.ID() != ep1.ID() || ep0.ID() != ep2.ID() ||
1482+
ep0.ID() != ep3.ID() || ep0.ID() != ep4.ID() || ep0.ID() != ep5.ID() {
14471483
t.Fatalf("Diffenrent queries returned different endpoints")
14481484
}
14491485

@@ -1665,6 +1701,9 @@ func TestwriteJSON(t *testing.T) {
16651701
func TestHttpHandlerUninit(t *testing.T) {
16661702
defer testutils.SetupTestOSContext(t)()
16671703

1704+
// Cleanup local datastore file
1705+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
1706+
16681707
c, err := libnetwork.New()
16691708
if err != nil {
16701709
t.Fatal(err)
@@ -1732,6 +1771,9 @@ func TestHttpHandlerBadBody(t *testing.T) {
17321771

17331772
rsp := newWriter()
17341773

1774+
// Cleanup local datastore file
1775+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
1776+
17351777
c, err := libnetwork.New()
17361778
if err != nil {
17371779
t.Fatal(err)
@@ -1765,6 +1807,9 @@ func TestEndToEnd(t *testing.T) {
17651807

17661808
rsp := newWriter()
17671809

1810+
// Cleanup local datastore file
1811+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
1812+
17681813
c, err := libnetwork.New()
17691814
if err != nil {
17701815
t.Fatal(err)
@@ -2213,6 +2258,9 @@ func TestEndToEndErrorMessage(t *testing.T) {
22132258

22142259
rsp := newWriter()
22152260

2261+
// Cleanup local datastore file
2262+
os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
2263+
22162264
c, err := libnetwork.New()
22172265
if err != nil {
22182266
t.Fatal(err)

libnetwork/cmd/dnet/dnet.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import (
2222
"github.com/docker/docker/pkg/reexec"
2323

2424
"github.com/Sirupsen/logrus"
25+
psignal "github.com/docker/docker/pkg/signal"
2526
"github.com/docker/docker/pkg/term"
2627
"github.com/docker/libnetwork"
2728
"github.com/docker/libnetwork/api"
2829
"github.com/docker/libnetwork/config"
30+
"github.com/docker/libnetwork/datastore"
2931
"github.com/docker/libnetwork/driverapi"
3032
"github.com/docker/libnetwork/netlabel"
3133
"github.com/docker/libnetwork/options"
@@ -76,6 +78,7 @@ func processConfig(cfg *config.Config) []config.Option {
7678
if cfg == nil {
7779
return options
7880
}
81+
7982
dn := "bridge"
8083
if strings.TrimSpace(cfg.Daemon.DefaultNetwork) != "" {
8184
dn = cfg.Daemon.DefaultNetwork
@@ -91,12 +94,12 @@ func processConfig(cfg *config.Config) []config.Option {
9194
if cfg.Daemon.Labels != nil {
9295
options = append(options, config.OptionLabels(cfg.Daemon.Labels))
9396
}
94-
if strings.TrimSpace(cfg.GlobalStore.Client.Provider) != "" {
95-
options = append(options, config.OptionKVProvider(cfg.GlobalStore.Client.Provider))
96-
}
97-
if strings.TrimSpace(cfg.GlobalStore.Client.Address) != "" {
98-
options = append(options, config.OptionKVProviderURL(cfg.GlobalStore.Client.Address))
97+
98+
if dcfg, ok := cfg.Scopes[datastore.GlobalScope]; ok && dcfg.IsValid() {
99+
options = append(options, config.OptionKVProvider(dcfg.Client.Provider))
100+
options = append(options, config.OptionKVProviderURL(dcfg.Client.Address))
99101
}
102+
100103
dOptions, err := startDiscovery(&cfg.Cluster)
101104
if err != nil {
102105
logrus.Infof("Skipping discovery : %s", err.Error())
@@ -182,8 +185,9 @@ func createDefaultNetwork(c libnetwork.NetworkController) {
182185
genericOption[netlabel.GenericData] = map[string]interface{}{
183186
"BridgeName": nw,
184187
}
185-
networkOption := libnetwork.NetworkOptionGeneric(genericOption)
186-
createOptions = append(createOptions, networkOption)
188+
createOptions = append(createOptions,
189+
libnetwork.NetworkOptionGeneric(genericOption),
190+
libnetwork.NetworkOptionPersist(false))
187191
}
188192
_, err := c.NewNetwork(d, nw, createOptions...)
189193
if err != nil {
@@ -214,6 +218,7 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error {
214218
fmt.Println("Error starting dnetDaemon :", err)
215219
return err
216220
}
221+
217222
createDefaultNetwork(controller)
218223
httpHandler := api.NewHTTPHandler(controller)
219224
r := mux.NewRouter().StrictSlash(false)
@@ -231,10 +236,21 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error {
231236
post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
232237

233238
handleSignals(controller)
239+
setupDumpStackTrap()
234240

235241
return http.ListenAndServe(d.addr, r)
236242
}
237243

244+
func setupDumpStackTrap() {
245+
c := make(chan os.Signal, 1)
246+
signal.Notify(c, syscall.SIGUSR1)
247+
go func() {
248+
for range c {
249+
psignal.DumpStacks()
250+
}
251+
}()
252+
}
253+
238254
func handleSignals(controller libnetwork.NetworkController) {
239255
c := make(chan os.Signal, 1)
240256
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT}

0 commit comments

Comments
 (0)