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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
d44d7f8d
Commit
d44d7f8d
authored
3 years ago
by
Jan Semmelink
Browse files
Options
Downloads
Patches
Plain Diff
Update search and reflection to return slice of user type docs
parent
934029e0
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!6
Search package improvements to retrieve documents with text searches from OpenSearch
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
reflection/type_clone.go
+8
-1
8 additions, 1 deletion
reflection/type_clone.go
search/search_test.go
+8
-1
8 additions, 1 deletion
search/search_test.go
search/time_series.go
+14
-8
14 additions, 8 deletions
search/time_series.go
with
30 additions
and
10 deletions
reflection/type_clone.go
+
8
−
1
View file @
d44d7f8d
...
...
@@ -46,7 +46,14 @@ import (
//than strings.HasPrefix() to check for delimiter/end of name to do full
//word matches, and we need to extend the test to illustrate this.
func
CloneType
(
t
reflect
.
Type
,
replace
map
[
string
]
reflect
.
Type
)
(
reflect
.
Type
,
error
)
{
return
clone
(
""
,
t
,
replace
)
cloned
,
err
:=
clone
(
""
,
t
,
replace
)
if
err
!=
nil
{
return
t
,
err
}
if
len
(
replace
)
>
0
{
return
t
,
errors
.
Errorf
(
"unknown replacements: %+v"
,
replace
)
}
return
cloned
,
nil
}
func
clone
(
name
string
,
t
reflect
.
Type
,
replace
map
[
string
]
reflect
.
Type
)
(
reflect
.
Type
,
error
)
{
...
...
This diff is collapsed.
Click to expand it.
search/search_test.go
+
8
−
1
View file @
d44d7f8d
...
...
@@ -71,7 +71,14 @@ func test(t *testing.T, c search.Config) {
if
err
!=
nil
{
t
.
Errorf
(
"failed to search: %+v"
,
err
)
}
else
{
t
.
Logf
(
"search: %d: %+v"
,
totalCount
,
docs
)
if
docsSlice
,
ok
:=
docs
.
([]
testStruct
);
ok
{
t
.
Logf
(
"search result total_count:%d with %d docs"
,
totalCount
,
len
(
docsSlice
))
if
len
(
docsSlice
)
>
10
{
t
.
Errorf
(
"got %d docs > max 10"
,
len
(
docsSlice
))
}
}
else
{
t
.
Errorf
(
"docs %T is not []testStruct!"
,
docs
)
}
}
oldList
,
err
:=
a
.
DelOldTimeSeries
(
indexName
,
2
)
...
...
This diff is collapsed.
Click to expand it.
search/time_series.go
+
14
−
8
View file @
d44d7f8d
...
...
@@ -24,7 +24,7 @@ type TimeSeriesHeader struct {
type
TimeSeries
interface
{
Write
(
StartTime
time
.
Time
,
EndTime
time
.
Time
,
data
interface
{})
error
Search
(
limit
int
)
(
docs
[]
interface
{},
totalCount
int
,
err
error
)
Search
(
limit
int
)
(
docs
interface
{},
totalCount
int
,
err
error
)
}
type
timeSeries
struct
{
...
...
@@ -167,9 +167,9 @@ func (w *writer) TimeSeries(name string, tmpl interface{}) (TimeSeries, error) {
//define search response type
//similar to SearchResponseBody
ts
.
searchResponseBodyType
,
err
=
reflection
.
CloneType
(
reflect
.
TypeOf
(
[]
reflect
.
StructField
{}),
reflect
.
TypeOf
(
SearchResponseBody
{}),
map
[
string
]
reflect
.
Type
{
".hits.hits[]._s
li
ce"
:
ts
.
dataType
,
".hits.hits[]._s
our
ce"
:
ts
.
dataType
,
})
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"failed to make search response type for time-series"
)
...
...
@@ -268,7 +268,7 @@ func (w *writer) DelOldTimeSeries(indexName string, olderThanDays int) ([]string
logger
.
Debugf
(
"Ignore index(%s) with invalid date(%s)"
,
dailyIndexName
,
dateStr
)
}
else
{
if
date
.
Before
(
timeThreshold
)
{
logger
.
Debugf
(
"Deleting index(%s).uuid(%s)
.docsCount(%d)
older than %s days..."
,
dailyIndexName
,
dailyIndexInfo
.
Settings
.
Index
.
UUID
,
dailyIndexInfo
.
Settings
.
Index
.
DocsCount
,
timeThreshold
)
logger
.
Debugf
(
"Deleting index(%s).uuid(%s) older than %s days..."
,
dailyIndexName
,
dailyIndexInfo
.
Settings
.
Index
.
UUID
,
timeThreshold
)
indicesToDelete
=
append
(
indicesToDelete
,
dailyIndexName
)
}
}
...
...
@@ -296,10 +296,16 @@ type IndexInfoSettings struct {
type
IndexSettings
struct
{
UUID
string
`json:"uuid"`
DocsCount
int64
`json:"docs.count"`
CreationDate
string
`json:"creation_date"`
NumberOfShards
string
`json:"number_of_shards"`
NumberOfReplicas
string
`json:"number_of_replicas"`
ProviderName
string
`json:"provided_name"`
//e.g. "go-utils-audit-test-20211103"
}
func
(
ts
*
timeSeries
)
Search
(
limit
int
)
(
docs
[]
interface
{},
totalCount
int
,
err
error
)
{
//Search
//Return:
// docs will be a slice of the TimeSeries data type
func
(
ts
*
timeSeries
)
Search
(
limit
int
)
(
docs
interface
{},
totalCount
int
,
err
error
)
{
if
limit
>
1000
{
err
=
errors
.
Errorf
(
"limit=%d > 1000"
,
limit
)
return
...
...
@@ -362,7 +368,7 @@ func (ts *timeSeries) Search(limit int) (docs []interface{}, totalCount int, err
err
=
errors
.
Wrapf
(
err
,
"cannot get search response documents"
)
return
}
return
items
.
Interface
()
.
([]
interface
{})
,
hitsTotalValue
.
Interface
()
.
(
int
),
nil
return
items
.
Interface
(),
hitsTotalValue
.
Interface
()
.
(
int
),
nil
}
type
SearchRequestBody
struct
{
...
...
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