Skip to content

Commit

Permalink
add spans to search v2 (grafana#92223)
Browse files Browse the repository at this point in the history
add tracing spans to search v2 service
  • Loading branch information
mildwonkey authored Aug 21, 2024
1 parent aa913b5 commit 2d0350e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkg/services/searchV2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"io"
"net/http"

"github.com/prometheus/client_golang/prometheus"

"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/prometheus/client_golang/prometheus"

"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/api/routing"
Expand All @@ -34,7 +33,9 @@ func (s *searchHTTPService) RegisterHTTPRoutes(storageRoute routing.RouteRegiste
}

func (s *searchHTTPService) doQuery(c *contextmodel.ReqContext) response.Response {
searchReadinessCheckResp := s.search.IsReady(c.Req.Context(), c.SignedInUser.GetOrgID())
ctx, span := tracer.Start(c.Req.Context(), "searchV2.doQuery")
defer span.End()
searchReadinessCheckResp := s.search.IsReady(ctx, c.SignedInUser.GetOrgID())
if !searchReadinessCheckResp.IsReady {
dashboardSearchNotServedRequestsCounter.With(prometheus.Labels{
"reason": searchReadinessCheckResp.Reason,
Expand All @@ -59,7 +60,7 @@ func (s *searchHTTPService) doQuery(c *contextmodel.ReqContext) response.Respons
return response.Error(http.StatusBadRequest, "error parsing body", err)
}

resp := s.search.doDashboardQuery(c.Req.Context(), c.SignedInUser, c.SignedInUser.GetOrgID(), *query)
resp := s.search.doDashboardQuery(ctx, c.SignedInUser, c.SignedInUser.GetOrgID(), *query)

if resp.Error != nil {
return response.Error(http.StatusInternalServerError, "error handling search request", resp.Error)
Expand Down
10 changes: 10 additions & 0 deletions pkg/services/searchV2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"go.opentelemetry.io/otel"

"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
Expand Down Expand Up @@ -58,6 +59,7 @@ var (
Namespace: namespace,
Subsystem: subsystem,
})
tracer = otel.Tracer("github.com/grafana/grafana/pkg/services/searchv2")
)

type StandardSearchService struct {
Expand Down Expand Up @@ -120,6 +122,8 @@ func (s *StandardSearchService) IsDisabled() bool {
}

func (s *StandardSearchService) Run(ctx context.Context) error {
ctx, span := tracer.Start(ctx, "searchv2.Run")
defer span.End()
orgQuery := &org.SearchOrgsQuery{}
result, err := s.orgService.Search(ctx, orgQuery)
if err != nil {
Expand All @@ -146,6 +150,8 @@ func (s *StandardSearchService) RegisterDashboardIndexExtender(ext DashboardInde
}

func (s *StandardSearchService) getUser(ctx context.Context, backendUser *backend.User, orgId int64) (*user.SignedInUser, error) {
ctx, span := tracer.Start(ctx, "searchv2.getUser")
defer span.End()
// TODO: get user & user's permissions from the request context

var usr *user.SignedInUser
Expand Down Expand Up @@ -204,6 +210,8 @@ func (s *StandardSearchService) getUser(ctx context.Context, backendUser *backen
}

func (s *StandardSearchService) DoDashboardQuery(ctx context.Context, user *backend.User, orgID int64, q DashboardQuery) *backend.DataResponse {
ctx, span := tracer.Start(ctx, "searchv2.DoDashboardQuery")
defer span.End()
start := time.Now()

signedInUser, err := s.getUser(ctx, user, orgID)
Expand Down Expand Up @@ -232,6 +240,8 @@ func (s *StandardSearchService) DoDashboardQuery(ctx context.Context, user *back
}

func (s *StandardSearchService) doDashboardQuery(ctx context.Context, signedInUser *user.SignedInUser, orgID int64, q DashboardQuery) *backend.DataResponse {
ctx, span := tracer.Start(ctx, "searchv2.doDashboardQuery")
defer span.End()
rsp := &backend.DataResponse{}

filter, err := s.auth.GetDashboardReadFilter(ctx, orgID, signedInUser)
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/searchV2/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
)

func updateUsageStats(ctx context.Context, reader *bluge.Reader, logger log.Logger, tracer tracing.Tracer) {
ctx, span := tracer.Start(ctx, "searchV2 updateUsageStats")
ctx, span := tracer.Start(ctx, "searchV2.updateUsageStats")
defer span.End()
req := bluge.NewAllMatches(bluge.NewTermQuery("panel").SetField(documentFieldKind))
for _, usage := range panelUsage {
Expand Down

0 comments on commit 2d0350e

Please sign in to comment.