From 724cf40c0edaa4ae1477f91a67644b500f6cb209 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 24 Nov 2022 12:32:55 +0100 Subject: [PATCH] Add traces to search + indexer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Duffeck --- changelog/unreleased/add-tracing-to-serach.md | 6 ++++++ services/search/pkg/search/index/index.go | 6 ++++++ services/search/pkg/search/provider/searchprovider.go | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 changelog/unreleased/add-tracing-to-serach.md diff --git a/changelog/unreleased/add-tracing-to-serach.md b/changelog/unreleased/add-tracing-to-serach.md new file mode 100644 index 000000000..28ce57fe0 --- /dev/null +++ b/changelog/unreleased/add-tracing-to-serach.md @@ -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 \ No newline at end of file diff --git a/services/search/pkg/search/index/index.go b/services/search/pkg/search/index/index.go index 3e6842766..92ff8ec91 100644 --- a/services/search/pkg/search/index/index.go +++ b/services/search/pkg/search/index/index.go @@ -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" @@ -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, diff --git a/services/search/pkg/search/provider/searchprovider.go b/services/search/pkg/search/provider/searchprovider.go index f20a3116d..915513da4 100644 --- a/services/search/pkg/search/provider/searchprovider.go +++ b/services/search/pkg/search/provider/searchprovider.go @@ -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" @@ -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" @@ -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") } @@ -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 @@ -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, @@ -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")