FrontendService: Add tracing to frontend service (#107236)

* FrontendService: Add tracing to frontend service

* wire gen

* fix test
pull/107901/head^2
Josh Hunt 2 weeks ago committed by GitHub
parent 9aaaa87bcf
commit 37bfea8685
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      pkg/server/module_server.go
  2. 5
      pkg/server/search_server_distributor_test.go
  3. 10
      pkg/server/wire_gen.go
  4. 5
      pkg/server/wireexts_oss.go
  5. 3
      pkg/services/frontend/frontend_service.go
  6. 3
      pkg/services/frontend/index.go

@ -19,6 +19,7 @@ import (
"github.com/grafana/grafana/pkg/api"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/modules"
"github.com/grafana/grafana/pkg/services/authz"
"github.com/grafana/grafana/pkg/services/featuremgmt"
@ -39,6 +40,7 @@ func NewModule(opts Options,
indexMetrics *resource.BleveIndexMetrics,
reg prometheus.Registerer,
promGatherer prometheus.Gatherer,
tracer tracing.Tracer, // Ensures tracing is initialized
license licensing.Licensing,
) (*ModuleServer, error) {
s, err := newModuleServer(opts, apiOpts, features, cfg, storageMetrics, indexMetrics, reg, promGatherer, license)

@ -15,6 +15,7 @@ import (
claims "github.com/grafana/authlib/types"
"github.com/grafana/grafana/pkg/api"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/modules"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/sqlstore/sqlutil"
@ -321,7 +322,9 @@ func initModuleServerForTest(
opts Options,
apiOpts api.ServerOptions,
) testModuleServer {
ms, err := NewModule(opts, apiOpts, featuremgmt.WithFeatures(featuremgmt.FlagUnifiedStorageSearch), cfg, nil, nil, prometheus.NewRegistry(), prometheus.DefaultGatherer, nil)
tracer := tracing.InitializeTracerForTest()
ms, err := NewModule(opts, apiOpts, featuremgmt.WithFeatures(featuremgmt.FlagUnifiedStorageSearch), cfg, nil, nil, prometheus.NewRegistry(), prometheus.DefaultGatherer, tracer, nil)
require.NoError(t, err)
conn, err := grpc.NewClient(cfg.GRPCServer.Address,

@ -1379,9 +1379,17 @@ func InitializeModuleServer(cfg *setting.Cfg, opts Options, apiOpts api.ServerOp
storageMetrics := resource.ProvideStorageMetrics(registerer)
bleveIndexMetrics := resource.ProvideIndexMetrics(registerer)
gatherer := metrics.ProvideGatherer()
tracingConfig, err := tracing.ProvideTracingConfig(cfg)
if err != nil {
return nil, err
}
tracingService, err := tracing.ProvideService(tracingConfig)
if err != nil {
return nil, err
}
hooksService := hooks.ProvideService()
ossLicensingService := licensing.ProvideService(cfg, hooksService)
moduleServer, err := NewModule(opts, apiOpts, featureToggles, cfg, storageMetrics, bleveIndexMetrics, registerer, gatherer, ossLicensingService)
moduleServer, err := NewModule(opts, apiOpts, featureToggles, cfg, storageMetrics, bleveIndexMetrics, registerer, gatherer, tracingService, ossLicensingService)
if err != nil {
return nil, err
}

@ -8,6 +8,7 @@ import (
"github.com/google/wire"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/manager"
"github.com/grafana/grafana/pkg/registry"
@ -165,6 +166,10 @@ var wireExtsBaseCLISet = wire.NewSet(
var wireExtsModuleServerSet = wire.NewSet(
NewModule,
wireExtsBaseCLISet,
// Tracing
tracing.ProvideTracingConfig,
tracing.ProvideService,
wire.Bind(new(tracing.Tracer), new(*tracing.TracingService)),
// Unified storage
resource.ProvideStorageMetrics,
resource.ProvideIndexMetrics,

@ -8,6 +8,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel"
"github.com/grafana/dskit/services"
"github.com/grafana/grafana/pkg/infra/log"
@ -15,6 +16,8 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
var tracer = otel.Tracer("github.com/grafana/grafana/pkg/services/frontend")
type frontendService struct {
*services.BasicService
cfg *setting.Cfg

@ -79,6 +79,9 @@ func NewIndexProvider(cfg *setting.Cfg, license licensing.Licensing) (*IndexProv
}
func (p *IndexProvider) HandleRequest(writer http.ResponseWriter, request *http.Request) {
_, span := tracer.Start(request.Context(), "frontend.index.HandleRequest")
defer span.End()
if request.Method != "GET" {
writer.WriteHeader(http.StatusMethodNotAllowed)
return

Loading…
Cancel
Save