Skip to content

Commit f8dc09a

Browse files
author
Flavio Crisciani
committed
Change diagnose module name to diagnostic
Align it to the moby/moby external api Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
1 parent 862df3a commit f8dc09a

9 files changed

Lines changed: 158 additions & 148 deletions

File tree

agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
297297
return err
298298
}
299299

300-
// Register the diagnose handlers
301-
c.DiagnoseServer.RegisterHandler(nDB, networkdb.NetDbPaths2Func)
300+
// Register the diagnostic handlers
301+
c.DiagnosticServer.RegisterHandler(nDB, networkdb.NetDbPaths2Func)
302302

303303
var cancelList []func()
304304
ch, cancel := nDB.Watch(libnetworkEPTable, "", "")

controller.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import (
6161
"github.com/docker/libnetwork/cluster"
6262
"github.com/docker/libnetwork/config"
6363
"github.com/docker/libnetwork/datastore"
64-
"github.com/docker/libnetwork/diagnose"
64+
"github.com/docker/libnetwork/diagnostic"
6565
"github.com/docker/libnetwork/discoverapi"
6666
"github.com/docker/libnetwork/driverapi"
6767
"github.com/docker/libnetwork/drvregistry"
@@ -136,12 +136,12 @@ type NetworkController interface {
136136
// SetKeys configures the encryption key for gossip and overlay data path
137137
SetKeys(keys []*types.EncryptionKey) error
138138

139-
// StartDiagnose start the network diagnose mode
140-
StartDiagnose(port int)
141-
// StopDiagnose start the network diagnose mode
142-
StopDiagnose()
143-
// IsDiagnoseEnabled returns true if the diagnose is enabled
144-
IsDiagnoseEnabled() bool
139+
// StartDiagnostic start the network diagnostic mode
140+
StartDiagnostic(port int)
141+
// StopDiagnostic start the network diagnostic mode
142+
StopDiagnostic()
143+
// IsDiagnosticEnabled returns true if the diagnostic is enabled
144+
IsDiagnosticEnabled() bool
145145
}
146146

147147
// NetworkWalker is a client provided function which will be used to walk the Networks.
@@ -176,7 +176,7 @@ type controller struct {
176176
agentStopDone chan struct{}
177177
keys []*types.EncryptionKey
178178
clusterConfigAvailable bool
179-
DiagnoseServer *diagnose.Server
179+
DiagnosticServer *diagnostic.Server
180180
sync.Mutex
181181
}
182182

@@ -188,16 +188,16 @@ type initializer struct {
188188
// New creates a new instance of network controller.
189189
func New(cfgOptions ...config.Option) (NetworkController, error) {
190190
c := &controller{
191-
id: stringid.GenerateRandomID(),
192-
cfg: config.ParseConfigOptions(cfgOptions...),
193-
sandboxes: sandboxTable{},
194-
svcRecords: make(map[string]svcInfo),
195-
serviceBindings: make(map[serviceKey]*service),
196-
agentInitDone: make(chan struct{}),
197-
networkLocker: locker.New(),
198-
DiagnoseServer: diagnose.New(),
191+
id: stringid.GenerateRandomID(),
192+
cfg: config.ParseConfigOptions(cfgOptions...),
193+
sandboxes: sandboxTable{},
194+
svcRecords: make(map[string]svcInfo),
195+
serviceBindings: make(map[serviceKey]*service),
196+
agentInitDone: make(chan struct{}),
197+
networkLocker: locker.New(),
198+
DiagnosticServer: diagnostic.New(),
199199
}
200-
c.DiagnoseServer.Init()
200+
c.DiagnosticServer.Init()
201201

202202
if err := c.initStores(); err != nil {
203203
return nil, err
@@ -1307,27 +1307,27 @@ func (c *controller) Stop() {
13071307
osl.GC()
13081308
}
13091309

1310-
// StartDiagnose start the network diagnose mode
1311-
func (c *controller) StartDiagnose(port int) {
1310+
// StartDiagnostic start the network dias mode
1311+
func (c *controller) StartDiagnostic(port int) {
13121312
c.Lock()
1313-
if !c.DiagnoseServer.IsDebugEnable() {
1314-
c.DiagnoseServer.EnableDebug("127.0.0.1", port)
1313+
if !c.DiagnosticServer.IsDiagnosticEnabled() {
1314+
c.DiagnosticServer.EnableDiagnostic("127.0.0.1", port)
13151315
}
13161316
c.Unlock()
13171317
}
13181318

1319-
// StopDiagnose start the network diagnose mode
1320-
func (c *controller) StopDiagnose() {
1319+
// StopDiagnostic start the network dias mode
1320+
func (c *controller) StopDiagnostic() {
13211321
c.Lock()
1322-
if c.DiagnoseServer.IsDebugEnable() {
1323-
c.DiagnoseServer.DisableDebug()
1322+
if c.DiagnosticServer.IsDiagnosticEnabled() {
1323+
c.DiagnosticServer.DisableDiagnostic()
13241324
}
13251325
c.Unlock()
13261326
}
13271327

1328-
// IsDiagnoseEnabled returns true if the diagnose is enabled
1329-
func (c *controller) IsDiagnoseEnabled() bool {
1328+
// IsDiagnosticEnabled returns true if the dias is enabled
1329+
func (c *controller) IsDiagnosticEnabled() bool {
13301330
c.Lock()
13311331
defer c.Unlock()
1332-
return c.DiagnoseServer.IsDebugEnable()
1332+
return c.DiagnosticServer.IsDiagnosticEnabled()
13331333
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package diagnose
1+
package diagnostic
22

33
import (
44
"context"
@@ -44,7 +44,7 @@ type Server struct {
4444
sync.Mutex
4545
}
4646

47-
// New creates a new diagnose server
47+
// New creates a new diagnostic server
4848
func New() *Server {
4949
return &Server{
5050
registeredHanders: make(map[string]bool),
@@ -78,8 +78,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7878
s.mux.ServeHTTP(w, r)
7979
}
8080

81-
// EnableDebug opens a TCP socket to debug the passed network DB
82-
func (s *Server) EnableDebug(ip string, port int) {
81+
// EnableDiagnostic opens a TCP socket to debug the passed network DB
82+
func (s *Server) EnableDiagnostic(ip string, port int) {
8383
s.Lock()
8484
defer s.Unlock()
8585

@@ -90,7 +90,7 @@ func (s *Server) EnableDebug(ip string, port int) {
9090
return
9191
}
9292

93-
logrus.Infof("Starting the diagnose server listening on %d for commands", port)
93+
logrus.Infof("Starting the diagnostic server listening on %d for commands", port)
9494
srv := &http.Server{Addr: fmt.Sprintf("%s:%d", ip, port), Handler: s}
9595
s.srv = srv
9696
s.enable = 1
@@ -103,19 +103,19 @@ func (s *Server) EnableDebug(ip string, port int) {
103103
}(s)
104104
}
105105

106-
// DisableDebug stop the dubug and closes the tcp socket
107-
func (s *Server) DisableDebug() {
106+
// DisableDiagnostic stop the dubug and closes the tcp socket
107+
func (s *Server) DisableDiagnostic() {
108108
s.Lock()
109109
defer s.Unlock()
110110

111111
s.srv.Shutdown(context.Background())
112112
s.srv = nil
113113
s.enable = 0
114-
logrus.Info("Disabling the diagnose server")
114+
logrus.Info("Disabling the diagnostic server")
115115
}
116116

117-
// IsDebugEnable returns true when the debug is enabled
118-
func (s *Server) IsDebugEnable() bool {
117+
// IsDiagnosticEnabled returns true when the debug is enabled
118+
func (s *Server) IsDiagnosticEnabled() bool {
119119
s.Lock()
120120
defer s.Unlock()
121121
return s.enable == 1
@@ -127,7 +127,7 @@ func notImplemented(ctx interface{}, w http.ResponseWriter, r *http.Request) {
127127
rsp := WrongCommand("not implemented", fmt.Sprintf("URL path: %s no method implemented check /help\n", r.URL.Path))
128128

129129
// audit logs
130-
log := logrus.WithFields(logrus.Fields{"component": "diagnose", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
130+
log := logrus.WithFields(logrus.Fields{"component": "diagnostic", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
131131
log.Info("command not implemented done")
132132

133133
HTTPReply(w, rsp, json)
@@ -138,7 +138,7 @@ func help(ctx interface{}, w http.ResponseWriter, r *http.Request) {
138138
_, json := ParseHTTPFormOptions(r)
139139

140140
// audit logs
141-
log := logrus.WithFields(logrus.Fields{"component": "diagnose", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
141+
log := logrus.WithFields(logrus.Fields{"component": "diagnostic", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
142142
log.Info("help done")
143143

144144
n, ok := ctx.(*Server)
@@ -156,7 +156,7 @@ func ready(ctx interface{}, w http.ResponseWriter, r *http.Request) {
156156
_, json := ParseHTTPFormOptions(r)
157157

158158
// audit logs
159-
log := logrus.WithFields(logrus.Fields{"component": "diagnose", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
159+
log := logrus.WithFields(logrus.Fields{"component": "diagnostic", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
160160
log.Info("ready done")
161161
HTTPReply(w, CommandSucceed(&StringCmd{Info: "OK"}), json)
162162
}
@@ -166,7 +166,7 @@ func stackTrace(ctx interface{}, w http.ResponseWriter, r *http.Request) {
166166
_, json := ParseHTTPFormOptions(r)
167167

168168
// audit logs
169-
log := logrus.WithFields(logrus.Fields{"component": "diagnose", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
169+
log := logrus.WithFields(logrus.Fields{"component": "diagnostic", "remoteIP": r.RemoteAddr, "method": common.CallerName(0), "url": r.URL.String()})
170170
log.Info("stack trace")
171171

172172
path, err := stackdump.DumpStacks("/tmp/")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package diagnose
1+
package diagnostic
22

33
import "fmt"
44

@@ -31,7 +31,7 @@ func WrongCommand(message, usage string) *HTTPResult {
3131
}
3232
}
3333

34-
// HTTPResult Diagnose Server HTTP result operation
34+
// HTTPResult Diagnostic Server HTTP result operation
3535
type HTTPResult struct {
3636
Message string `json:"message"`
3737
Details StringInterface `json:"details"`

networkdb/networkdb.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ func (nDB *NetworkDB) GetEntry(tname, nid, key string) ([]byte, error) {
328328
if err != nil {
329329
return nil, err
330330
}
331+
if entry != nil && entry.deleting {
332+
return nil, types.NotFoundErrorf("entry in table %s network id %s and key %s deleted and pending garbage collection", tname, nid, key)
333+
}
331334

332335
return entry.value, nil
333336
}

networkdb/networkdb_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net"
99
"os"
10+
"strings"
1011
"sync/atomic"
1112
"testing"
1213
"time"
@@ -446,6 +447,12 @@ func TestNetworkDBCRUDMediumCluster(t *testing.T) {
446447
dbs[i].verifyEntryExistence(t, "test_table", "network1", "test_key", "", false)
447448
}
448449

450+
for i := 1; i < n; i++ {
451+
_, err = dbs[i].GetEntry("test_table", "network1", "test_key")
452+
assert.Error(t, err)
453+
assert.True(t, strings.Contains(err.Error(), "deleted and pending garbage collection"))
454+
}
455+
449456
closeNetworkDBInstances(dbs)
450457
}
451458

0 commit comments

Comments
 (0)