Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
fd8b9b20
Commit
fd8b9b20
authored
3 years ago
by
Jan Semmelink
Browse files
Options
Downloads
Patches
Plain Diff
Update structs for search on api-logs
parent
3a2e23b8
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
logs/api-logs.go
+10
-10
10 additions, 10 deletions
logs/api-logs.go
search/document_store.go
+1
-0
1 addition, 0 deletions
search/document_store.go
search/search_test.go
+4
-0
4 additions, 0 deletions
search/search_test.go
search/time_series.go
+8
-2
8 additions, 2 deletions
search/time_series.go
with
23 additions
and
12 deletions
logs/api-logs.go
+
10
−
10
View file @
fd8b9b20
...
...
@@ -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"`
...
...
This diff is collapsed.
Click to expand it.
search/document_store.go
+
1
−
0
View file @
fd8b9b20
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
search/search_test.go
+
4
−
0
View file @
fd8b9b20
...
...
@@ -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"
))
}
This diff is collapsed.
Click to expand it.
search/time_series.go
+
8
−
2
View file @
fd8b9b20
...
...
@@ -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:05
Z
07: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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment