From b31393ca521bdbf191a69f1883186b5225bc186e Mon Sep 17 00:00:00 2001 From: dencoded <33698537+dencoded@users.noreply.github.com> Date: Mon, 27 Nov 2017 23:06:25 -0500 Subject: [PATCH] more debug info added --- gateway_test.go | 14 ++++++++++++++ main.go | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gateway_test.go b/gateway_test.go index 9312d16528a..ed4b1ec609e 100644 --- a/gateway_test.go +++ b/gateway_test.go @@ -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) diff --git a/main.go b/main.go index 201495a61c8..5ee8a7e55dc 100644 --- a/main.go +++ b/main.go @@ -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() @@ -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")