Skip to content

Commit

Permalink
fix: stats come first (#3159)
Browse files Browse the repository at this point in the history
  • Loading branch information
fracasula committed Apr 4, 2023
1 parent d7ac3a8 commit c7210fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
10 changes: 5 additions & 5 deletions regulation-worker/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func main() {
func Run(ctx context.Context) error {
config.Set("Diagnostics.enableDiagnostics", false)

admin.Init()
misc.Init()
diagnostics.Init()
backendconfig.Init()

stats.Default = stats.NewStats(config.Default, logger.Default, svcMetric.Instance,
stats.WithServiceName("regulation-worker"),
)
Expand All @@ -62,6 +57,11 @@ func Run(ctx context.Context) error {
}
defer stats.Default.Stop()

admin.Init()
misc.Init()
diagnostics.Init()
backendconfig.Init()

if err := backendconfig.Setup(nil); err != nil {
return fmt.Errorf("setting up backend config: %w", err)
}
Expand Down
47 changes: 23 additions & 24 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
"strings"
"time"

"github.com/bugsnag/bugsnag-go/v2"
_ "go.uber.org/automaxprocs"
"golang.org/x/sync/errgroup"

"github.com/bugsnag/bugsnag-go/v2"

"github.com/rudderlabs/rudder-go-kit/config"
"github.com/rudderlabs/rudder-go-kit/logger"
"github.com/rudderlabs/rudder-go-kit/stats"
Expand Down Expand Up @@ -133,6 +132,28 @@ func New(releaseInfo ReleaseInfo) *Runner {

// Run runs the application and returns the exit code
func (r *Runner) Run(ctx context.Context, args []string) int {
// Start stats
deploymentType, err := deployment.GetFromEnv()
if err != nil {
r.logger.Errorf("failed to get deployment type: %v", err)
return 1
}

// TODO: remove as soon as we update the configuration with statsExcludedTags where necessary
if !config.IsSet("statsExcludedTags") && deploymentType == deployment.MultiTenantType &&
(!config.IsSet("WORKSPACE_NAMESPACE") || strings.Contains(config.GetString("WORKSPACE_NAMESPACE", ""), "free")) {
config.Set("statsExcludedTags", []string{"workspaceId", "sourceID", "destId"})
}
stats.Default = stats.NewStats(config.Default, logger.Default, svcMetric.Instance,
stats.WithServiceName(r.appType),
stats.WithServiceVersion(r.releaseInfo.Version),
stats.WithDefaultHistogramBuckets(defaultHistogramBuckets),
)
if err := stats.Default.Start(ctx, rruntime.GoRoutineFactory); err != nil {
r.logger.Errorf("Failed to start stats: %v", err)
return 1
}

runAllInit()

options := app.LoadOptions(args)
Expand All @@ -148,7 +169,6 @@ func (r *Runner) Run(ctx context.Context, args []string) int {
// application & backend setup should be done before starting any new goroutines.
r.application.Setup()

var err error
r.appHandler, err = apphandlers.GetAppHandler(r.application, r.appType, r.versionHandler)
if err != nil {
r.logger.Errorf("Failed to get app handler: %v", err)
Expand All @@ -169,27 +189,6 @@ func (r *Runner) Run(ctx context.Context, args []string) int {
ctx = bugsnag.StartSession(ctx)
defer misc.BugsnagNotify(ctx, "Core")()

deploymentType, err := deployment.GetFromEnv()
if err != nil {
r.logger.Errorf("failed to get deployment type: %v", err)
return 1
}

// Start stats
// TODO: remove as soon as we update the configuration with statsExcludedTags where necessary
if !config.IsSet("statsExcludedTags") && deploymentType == deployment.MultiTenantType &&
(!config.IsSet("WORKSPACE_NAMESPACE") || strings.Contains(config.GetString("WORKSPACE_NAMESPACE", ""), "free")) {
config.Set("statsExcludedTags", []string{"workspaceId", "sourceID", "destId"})
}
stats.Default = stats.NewStats(config.Default, logger.Default, svcMetric.Instance,
stats.WithServiceName(r.appType),
stats.WithServiceVersion(r.releaseInfo.Version),
stats.WithDefaultHistogramBuckets(defaultHistogramBuckets),
)
if err := stats.Default.Start(ctx, rruntime.GoRoutineFactory); err != nil {
r.logger.Errorf("Failed to start stats: %v", err)
return 1
}
stats.Default.NewTaggedStat("rudder_server_config",
stats.GaugeType,
stats.Tags{
Expand Down

0 comments on commit c7210fa

Please sign in to comment.