Skip to content
Snippets Groups Projects
Commit fd8b9b20 authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Update structs for search on api-logs

parent 3a2e23b8
No related branches found
No related tags found
No related merge requests found
......@@ -108,16 +108,16 @@ 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
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"`
......
......@@ -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
}
......
......@@ -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"))
}
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment