Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracing to search + indexer #5113

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/add-tracing-to-serach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add tracing to search

We added tracing to search and its indexer

https://github.com/owncloud/ocis/pull/5113
https://github.com/owncloud/ocis/issues/5063
6 changes: 6 additions & 0 deletions services/search/pkg/search/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/blevesearch/bleve/v2/mapping"
"github.com/blevesearch/bleve/v2/search"
"github.com/cs3org/reva/v2/pkg/storagespace"
searchTracing "github.com/owncloud/ocis/v2/services/search/pkg/tracing"
"go.opentelemetry.io/otel/attribute"
"google.golang.org/protobuf/types/known/timestamppb"

sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -218,12 +220,16 @@ func (i *Index) Move(id, newParentID *sprovider.ResourceId, fullPath string) err

// Search searches the index according to the criteria specified in the given SearchIndexRequest
func (i *Index) Search(ctx context.Context, req *searchsvc.SearchIndexRequest) (*searchsvc.SearchIndexResponse, error) {
_, span := searchTracing.TraceProvider.Tracer("search").Start(ctx, "search index")
defer span.End()
deletedQuery := bleve.NewBoolFieldQuery(false)
deletedQuery.SetField("Deleted")
query := bleve.NewConjunctionQuery(
bleve.NewQueryStringQuery(req.Query),
deletedQuery, // Skip documents that have been marked as deleted
)
span.SetAttributes(attribute.String("query", req.GetQuery()))
span.SetAttributes(attribute.String("reference", req.GetRef().String()))
if req.Ref != nil {
query = bleve.NewConjunctionQuery(
query,
Expand Down
1 change: 1 addition & 0 deletions services/search/pkg/search/index/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var _ = Describe("Index", func() {
)

BeforeEach(func() {
ctx = context.Background()
filename = "Foo.pdf"

mapping, err := index.BuildMapping()
Expand Down
11 changes: 11 additions & 0 deletions services/search/pkg/search/provider/searchprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"go.opentelemetry.io/otel/attribute"
"google.golang.org/grpc/metadata"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/search/pkg/search"
searchTracing "github.com/owncloud/ocis/v2/services/search/pkg/tracing"

searchmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/search/v0"
searchsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0"
Expand Down Expand Up @@ -115,6 +117,9 @@ func NewWithDebouncer(gwClient gateway.GatewayAPIClient, indexClient search.Inde
}

func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*searchsvc.SearchResponse, error) {
ctx, span := searchTracing.TraceProvider.Tracer("search").Start(ctx, "search")
defer span.End()
span.SetAttributes(attribute.String("query", req.GetQuery()))
if req.Query == "" {
return nil, errtypes.BadRequest("empty query provided")
}
Expand Down Expand Up @@ -244,6 +249,8 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s

// compile one sorted list of matches from all spaces and apply the limit if needed
sort.Sort(matches)
span.SetAttributes(attribute.Int("num_matches", len(matches)))
span.SetAttributes(attribute.Int("total_matches", int(total)))
limit := req.PageSize
if limit == 0 {
limit = 200
Expand All @@ -267,6 +274,8 @@ func (p *Provider) IndexSpace(ctx context.Context, req *searchsvc.IndexSpaceRequ
}

func (p *Provider) doIndexSpace(ctx context.Context, spaceID *provider.StorageSpaceId, userID *user.UserId) error {
ctx, span := searchTracing.TraceProvider.Tracer("search").Start(ctx, "index space")
defer span.End()
authRes, err := p.gwClient.Authenticate(ctx, &gateway.AuthenticateRequest{
Type: "machine",
ClientId: "userid:" + userID.OpaqueId,
Expand All @@ -275,6 +284,8 @@ func (p *Provider) doIndexSpace(ctx context.Context, spaceID *provider.StorageSp
if err != nil || authRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
return err
}
span.SetAttributes(attribute.String("user_id", userID.GetOpaqueId()))
span.SetAttributes(attribute.String("space_id", spaceID.GetOpaqueId()))

if authRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
return fmt.Errorf("could not get authenticated context for user")
Expand Down