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
4a4d4a2b
Commit
4a4d4a2b
authored
2 years ago
by
Francé Wilke
Browse files
Options
Downloads
Patches
Plain Diff
OpenSearch - let's close some bodies
parent
4585632c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
search/document_store.go
+5
-0
5 additions, 0 deletions
search/document_store.go
search/time_series.go
+15
-3
15 additions, 3 deletions
search/time_series.go
search/writer.go
+5
-0
5 additions, 0 deletions
search/writer.go
with
25 additions
and
3 deletions
search/document_store.go
+
5
−
0
View file @
4a4d4a2b
...
...
@@ -107,6 +107,11 @@ func (ds *DocumentStore) Write(id string, data interface{}) error {
indexName
,
// index name
indexName
,
// document id
strings
.
NewReader
(
string
(
ds
.
jsonSettings
)))
defer
func
()
{
if
res
!=
nil
{
res
.
Body
.
Close
()
}
}()
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to create index(%s)"
,
indexName
)
}
...
...
This diff is collapsed.
Click to expand it.
search/time_series.go
+
15
−
3
View file @
4a4d4a2b
...
...
@@ -37,8 +37,11 @@ type TimeSeries struct {
}
// NewTimeSeries purpose:
//
// create a time series to write e.g. api api_logs
//
// parameters:
//
// name must be the openSearch index name prefix without the date, e.g. "uafrica-v3-api-api_logs"
// the actual indices in openSearch will be called "<indexName>-<ccyymmdd>" e.g. "uafrica-v3-api-api_logs-20210102"
// tmpl must be your log data struct consisting of public fields as:
...
...
@@ -225,6 +228,11 @@ func (ts *TimeSeries) Write(startTime, endTime time.Time, data interface{}) erro
indexName
,
// index name also used for document id
strings
.
NewReader
(
string
(
ts
.
jsonSettings
)),
)
defer
func
()
{
if
res
!=
nil
{
res
.
Body
.
Close
()
}
}()
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to create index(%s)"
,
indexName
)
}
...
...
@@ -271,8 +279,11 @@ func (ts *TimeSeries) Write(startTime, endTime time.Time, data interface{}) erro
}
// DelOldTimeSeries parameters:
//
// indexName is index prefix before dash-date, e.g. "api-api_logs" then will look for "api-api_logs-<date>"
//
// returns
//
// list of indices to delete with err==nil if deleted successfully
func
(
ts
*
TimeSeries
)
DelOldTimeSeries
(
olderThanDays
int
)
([]
string
,
error
)
{
if
olderThanDays
<
0
{
...
...
@@ -349,6 +360,7 @@ type IndexSettings struct {
// Search returns docs indexed on OpenSearch document ID which cat be used in Get(id)
// The docs value type is the same as that of tmpl specified when you created the TimeSeries(..., tmpl)
// So you can safely type assert e.g.
//
// type myType struct {...}
// ts := search.TimeSeries(..., myType{})
// docs,totalCount,err := ts.Search(...)
...
...
This diff is collapsed.
Click to expand it.
search/writer.go
+
5
−
0
View file @
4a4d4a2b
...
...
@@ -76,6 +76,11 @@ func (writer Writer) Write(indexName string, id string, doc interface{}) (*Index
strings
.
NewReader
(
jsonDocStr
),
options
...
,
)
defer
func
()
{
if
indexResponse
!=
nil
{
indexResponse
.
Body
.
Close
()
}
}()
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"failed to index document"
)
}
...
...
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