Chore: Remove unused dependenices in plugin client middlewares (#84624)

* Chore: Remove unused dependenices in plugin client middlewares

* refactor logger middleware to remove cfg dependency

* hack to make tracing work in api group builders
This commit is contained in:
Marcus Efraimsson
2024-03-22 12:54:35 +01:00
committed by GitHub
parent 41bf6a92fd
commit 488bbaacab
7 changed files with 54 additions and 34 deletions
+28 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/grafana/grafana/pkg/cmd/grafana-server/commands"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/apiserver/standalone"
)
@@ -47,8 +48,14 @@ func newCommandStartExampleAPIServer(o *APIServerOptions, stopCh <-chan struct{}
return err
}
// Currently TracingOptions.ApplyTo, which will configure/initialize tracing,
// happens after loadAPIGroupBuilders. Hack to workaround this for now to allow
// the tracer to be initialized at a later stage, when tracer is available.
// TODO: Fix so that TracingOptions.ApplyTo happens before or during loadAPIGroupBuilders.
tracer := newLateInitializedTracingService()
// Load each group from the args
if err := o.loadAPIGroupBuilders(apis); err != nil {
if err := o.loadAPIGroupBuilders(tracer, apis); err != nil {
return err
}
@@ -62,6 +69,10 @@ func newCommandStartExampleAPIServer(o *APIServerOptions, stopCh <-chan struct{}
return err
}
if o.Options.TracingOptions.TracingService != nil {
tracer.InitTracer(o.Options.TracingOptions.TracingService)
}
if err := o.RunAPIServer(config, stopCh); err != nil {
return err
}
@@ -87,3 +98,19 @@ func RunCLI(opts commands.ServerOptions) int {
return cli.Run(cmd)
}
type lateInitializedTracingService struct {
tracing.Tracer
}
func newLateInitializedTracingService() *lateInitializedTracingService {
return &lateInitializedTracingService{
Tracer: tracing.InitializeTracerForTest(),
}
}
func (s *lateInitializedTracingService) InitTracer(tracer tracing.Tracer) {
s.Tracer = tracer
}
var _ tracing.Tracer = &lateInitializedTracingService{}
+3 -2
View File
@@ -14,6 +14,7 @@ import (
"github.com/grafana/grafana/pkg/apiserver/builder"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
grafanaAPIServer "github.com/grafana/grafana/pkg/services/apiserver"
"github.com/grafana/grafana/pkg/services/apiserver/standalone"
standaloneoptions "github.com/grafana/grafana/pkg/services/apiserver/standalone/options"
@@ -50,10 +51,10 @@ func newAPIServerOptions(out, errOut io.Writer) *APIServerOptions {
}
}
func (o *APIServerOptions) loadAPIGroupBuilders(apis []schema.GroupVersion) error {
func (o *APIServerOptions) loadAPIGroupBuilders(tracer tracing.Tracer, apis []schema.GroupVersion) error {
o.builders = []builder.APIGroupBuilder{}
for _, gv := range apis {
api, err := o.factory.MakeAPIServer(gv)
api, err := o.factory.MakeAPIServer(tracer, gv)
if err != nil {
return err
}