Log search durations
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
_spaceStateTrashed = "trashed"
|
_spaceStateTrashed = "trashed"
|
||||||
|
_slowQueryDuration = 500 * time.Millisecond
|
||||||
)
|
)
|
||||||
|
|
||||||
// Searcher is the interface to the SearchService
|
// Searcher is the interface to the SearchService
|
||||||
@@ -255,19 +256,26 @@ func (s *Service) searchIndex(ctx context.Context, req *searchsvc.SearchRequest,
|
|||||||
permissions = space.GetRootInfo().GetPermissionSet()
|
permissions = space.GetRootInfo().GetPermissionSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.engine.Search(ctx, &searchsvc.SearchIndexRequest{
|
searchRequest := &searchsvc.SearchIndexRequest{
|
||||||
Query: req.Query,
|
Query: req.Query,
|
||||||
Ref: &searchmsg.Reference{
|
Ref: &searchmsg.Reference{
|
||||||
ResourceId: searchRootID,
|
ResourceId: searchRootID,
|
||||||
Path: mountpointPrefix,
|
Path: mountpointPrefix,
|
||||||
},
|
},
|
||||||
PageSize: req.PageSize,
|
PageSize: req.PageSize,
|
||||||
})
|
}
|
||||||
|
start := time.Now()
|
||||||
|
res, err := s.engine.Search(ctx, searchRequest)
|
||||||
|
duration := time.Since(start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error().Err(err).Str("space", space.Id.OpaqueId).Msg("failed to search the index")
|
s.logger.Error().Err(err).Str("duration", fmt.Sprint(duration)).Str("space", space.Id.OpaqueId).Msg("failed to search the index")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.logger.Debug().Str("space", space.Id.OpaqueId).Int("hits", len(res.Matches)).Msg("space search done")
|
if duration > _slowQueryDuration {
|
||||||
|
s.logger.Info().Interface("searchRequest", searchRequest).Str("duration", fmt.Sprint(duration)).Str("space", space.Id.OpaqueId).Int("hits", len(res.Matches)).Msg("slow space search")
|
||||||
|
} else {
|
||||||
|
s.logger.Debug().Interface("searchRequest", searchRequest).Str("duration", fmt.Sprint(duration)).Str("space", space.Id.OpaqueId).Int("hits", len(res.Matches)).Msg("space search done")
|
||||||
|
}
|
||||||
|
|
||||||
for _, match := range res.Matches {
|
for _, match := range res.Matches {
|
||||||
if mountpointPrefix != "" {
|
if mountpointPrefix != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user