Skip to content

Commit

Permalink
Set the otel feature gates in Flow mode earlier (#5293)
Browse files Browse the repository at this point in the history
* Set the otel feature gates earlier.
The feature gates should be set during the creation of the otel service.
  • Loading branch information
ptodev authored Sep 25, 2023
1 parent 1fd623e commit 8dfb3a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion cmd/internal/flowmode/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ func (fr *flowRun) Run(configPath string) error {
Cluster: clusterService.Data().(cluster.Cluster),
})

otelService := otel_service.New()
otelService := otel_service.New(l)
if otelService == nil {
return fmt.Errorf("failed to create otel service")
}

f := flow.New(flow.Options{
Logger: l,
Expand Down
25 changes: 18 additions & 7 deletions service/otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"

"github.com/go-kit/log"
"github.com/grafana/agent/pkg/util"
"github.com/grafana/agent/service"
)
Expand All @@ -18,7 +19,22 @@ type Service struct{}

var _ service.Service = (*Service)(nil)

func New() *Service {
func New(logger log.Logger) *Service {
if logger == nil {
logger = log.NewNopLogger()
}

// The feature gates should be set in New() instead of Run().
// Otel checks the feature gate very early, during the creation of
// an Otel component. If we set the feature gates in Run(), it will
// be too late - Otel would have already checked the feature gate by then.
// This is because the services are not started prior to the graph evaluation.
err := util.SetupFlowModeOtelFeatureGates()
if err != nil {
logger.Log("msg", "failed to set up Otel feature gates", "err", err)
return nil
}

return &Service{}
}

Expand All @@ -38,12 +54,7 @@ func (*Service) Definition() service.Definition {
}

// Run implements service.Service.
func (*Service) Run(ctx context.Context, host service.Host) error {
err := util.SetupFlowModeOtelFeatureGates()
if err != nil {
return err
}

func (s *Service) Run(ctx context.Context, host service.Host) error {
<-ctx.Done()
return nil
}
Expand Down

0 comments on commit 8dfb3a2

Please sign in to comment.