diff --git a/logs/api-logs.go b/logs/api-logs.go index 01900b2df0daf485ddacd613bf29c2d07f2a6263..abbad4581575ee0b33928ac5c86ba19dbfc8a36a 100644 --- a/logs/api-logs.go +++ b/logs/api-logs.go @@ -108,17 +108,17 @@ type ApiLog struct { StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` DurMs int64 `json:"duration_ms"` //duration in milliseconds - Method string `json:"method" search:"keyword"` + Method string `json:"method"` Address string `json:"address"` //server address for incoming and outgoing - Path string `json:"path" search:"keyword"` - ResponseCode int `json:"response_code" search:"keyword"` - RequestID string `json:"request_id" search:"keyword"` - InitialAuthUsername string `json:"initial_auth_username,omitempty" search:"keyword"` - InitialAuthType string `json:"initial_auth_type,omitempty" search:"keyword"` - AccountID int64 `json:"account_id,omitempty" search:"keyword"` - Username string `json:"username,omitempty" search:"keyword"` - SourceIP string `json:"source_ip,omitempty" search:"keyword"` //only logged for incoming API - UserAgent string `json:"user_agent,omitempty"` //only for incoming, indicate type of browser when UI + Path string `json:"path"` + ResponseCode int `json:"response_code"` + RequestID string `json:"request_id"` + InitialAuthUsername string `json:"initial_auth_username,omitempty"` + InitialAuthType string `json:"initial_auth_type,omitempty"` + AccountID int64 `json:"account_id,omitempty"` + Username string `json:"username,omitempty"` + SourceIP string `json:"source_ip,omitempty"` //only logged for incoming API + UserAgent string `json:"user_agent,omitempty"` //only for incoming, indicate type of browser when UI RelevantID string `json:"relevant_id,omitempty"` Request ApiLogRequest `json:"request"` Response ApiLogResponse `json:"response"` diff --git a/search/document_store.go b/search/document_store.go index 24e5fbd20ab59823f53811e4a97f046c118951aa..29cb32a79006449d673aa6c912da2c9a29cdf347 100644 --- a/search/document_store.go +++ b/search/document_store.go @@ -221,6 +221,7 @@ func (ds *documentStore) Search(query Query, limit int64) (ids []string, totalCo resBodyPtrValue := reflect.New(ds.searchResponseBodyType) // if err = json.NewDecoder(searchResponse.Body).Decode(resBodyPtrValue.Interface()); err != nil { if err = json.Unmarshal(bodyData, resBodyPtrValue.Interface()); err != nil { + logger.Errorf("search response body: %s", string(bodyData)) err = errors.Wrapf(err, "cannot decode search response body") return } diff --git a/search/search_test.go b/search/search_test.go index 2dec817e2c7f351579cbd5c1438ccd0f60690890..8a03042b26c6f4cc9b6a3d4c94f5c9e8e019cd8b 100644 --- a/search/search_test.go +++ b/search/search_test.go @@ -134,3 +134,7 @@ func TestOlderThan(t *testing.T) { t1 = t1.Add(-time.Hour * 24 * time.Duration(olderThanDays)) t.Logf("Threshold = %s", t1) } + +func TestTime(t *testing.T) { + t.Logf("Time: %s", time.Now().Format("2006-01-02T15:04:05Z07:00")) +} diff --git a/search/time_series.go b/search/time_series.go index f8674701d04b9259763f065e167ed25b4c1dcf15..423d22cbfe6595ce41814e3991be117aa89a9e3f 100644 --- a/search/time_series.go +++ b/search/time_series.go @@ -16,7 +16,7 @@ import ( "gitlab.com/uafrica/go-utils/reflection" ) -const TimeFormat = "2006-01-02T15:04:05+07:00" +const TimeFormat = "2006-01-02T15:04:05Z07:00" //embed this into your log struct type TimeSeriesHeader struct { @@ -384,6 +384,7 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC Query: query, } jsonBody, _ := json.Marshal(body) + logger.Debugf("Search: %s", string(jsonBody)) search := opensearchapi.SearchRequest{ Index: []string{ts.name + "-*"}, Body: bytes.NewReader(jsonBody), @@ -403,8 +404,13 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC return } + bodyData, _ := ioutil.ReadAll(searchResponse.Body) + logger.Debugf("Response Body: %s", string(bodyData)) + resBodyPtrValue := reflect.New(ts.searchResponseBodyType) - if err = json.NewDecoder(searchResponse.Body).Decode(resBodyPtrValue.Interface()); err != nil { + //if err = json.NewDecoder(searchResponse.Body).Decode(resBodyPtrValue.Interface()); err != nil { + if err = json.Unmarshal(bodyData, resBodyPtrValue.Interface()); err != nil { + logger.Errorf("search response body: %s", string(bodyData)) err = errors.Wrapf(err, "cannot decode search response body") return }