Skip to content

Commit

Permalink
more debug info added
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Nov 28, 2017
1 parent b0c0ac7 commit b31393c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,20 @@ func testHttp(t *testing.T, tests []tykHttpTest, separateControlPort bool) {
apiSpecsLen(),
apisByIDLen(),
)
currApiSpecs := getApiSpecs()
currApiByID := getApisByID()
t.Logf("testHttp [%d]%s%s %s apiSpecs:", ti, tPrefix, tc.method, tc.path)
for _, val := range currApiSpecs {
t.Logf("%v", *val)
}
t.Logf("testHttp [%d]%s%s %s apisByID:", ti, tPrefix, tc.method, tc.path)
for key, val := range currApiByID {
if val != nil {
t.Logf("key=%s val=%v", key, *val)
} else {
t.Logf("key=%s val=nil", key)
}
}

if resp.StatusCode != tc.code {
t.Errorf("[%d]%s%s %s Status %d, want %d", ti, tPrefix, tc.method, tc.path, resp.StatusCode, tc.code)
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ func getApiSpec(apiID string) *APISpec {
return apisByID[apiID]
}

func getApisByID() map[string]*APISpec {
apisMu.RLock()
defer apisMu.RUnlock()
apisByIDTmp := map[string]*APISpec{}
for key, val := range apisByID {
apisByIDTmp[key] = val
}
return apisByIDTmp
}

func getApiSpecs() []*APISpec {
apisMu.RLock()
defer apisMu.RUnlock()
Expand Down Expand Up @@ -648,9 +658,15 @@ func doReload() {
syncPolicies()
// load the specs
count := syncAPISpecs()
apisByIDCount := apisByIDLen()
// skip re-loading only if dashboard service reported 0 APIs
// and current registry had 0 APIs
if count == 0 && apisByIDLen() == 0 {
log.WithFields(logrus.Fields{
"prefix": "main",
"apisCount": count,
"apisByIDCount": apisByIDCount,
}).Info("API specs loaded, about to re-load...")
if count == 0 && apisByIDCount == 0 {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Warning("No API Definitions found, not reloading")
Expand Down

0 comments on commit b31393c

Please sign in to comment.