Skip to content

Commit

Permalink
fix(server): fixing profiler config (#3705)
Browse files Browse the repository at this point in the history
* fix(server): fixing profiler config

* fix: profiler startup
  • Loading branch information
danielbdias authored Mar 4, 2024
1 parent 235fad1 commit 446133b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var serveCmd = &cobra.Command{

profilerConfig := cfg.ApplicationProfiler()
if profilerConfig.Enabled {
telemetry.StartProfiler(profilerConfig.Name, profilerConfig.Endpoint, profilerConfig.SamplingRate)
telemetry.StartProfiler(profilerConfig.Name, profilerConfig.Environment, profilerConfig.Endpoint, profilerConfig.SamplingRate)
}

wg.Add(1)
Expand Down
1 change: 1 addition & 0 deletions server/config/exporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type (
Enabled bool `yaml:",omitempty" mapstructure:"enabled"`
Endpoint string `yaml:",omitempty" mapstructure:"endpoint"`
SamplingRate int `yaml:",omitempty" mapstructure:"samplingRate"`
Environment string `yaml:",omitempty" mapstructure:"environment"`
}
)

Expand Down
1 change: 0 additions & 1 deletion server/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (c *AppConfig) Validate() error {
err,
fmt.Errorf("invalid config value for '%s': %s", opt.key, optErr.Error()),
)

}

return err
Expand Down
14 changes: 10 additions & 4 deletions server/telemetry/profiler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package telemetry

import (
"fmt"
"os"
"runtime"

Expand All @@ -12,7 +13,10 @@ const (
BlockProfileFractionRate = 5
)

func StartProfiler(applicationName, telemetryServer string, samplingPercentage int) {
func StartProfiler(applicationName, applicationEnvironment, telemetryServerAddress string, samplingPercentage int) {
fmt.Printf("Starting profiler for environment [%s] with sampling [%d]. Telemetry server address: %s\n",
applicationEnvironment, samplingPercentage, telemetryServerAddress)

samplingRate := 100 / samplingPercentage

runtime.SetMutexProfileFraction(samplingRate)
Expand All @@ -22,14 +26,16 @@ func StartProfiler(applicationName, telemetryServer string, samplingPercentage i
ApplicationName: applicationName,

// replace this with the address of pyroscope server
ServerAddress: telemetryServer,
ServerAddress: telemetryServerAddress,

// you can disable logging by setting this to nil
Logger: pyroscope.StandardLogger,
// Logger: pyroscope.StandardLogger,
Logger: nil,

// you can provide static tags via a map:
Tags: map[string]string{
"hostname": os.Getenv("HOSTNAME"),
"hostname": os.Getenv("HOSTNAME"),
"environment": applicationEnvironment,
},

ProfileTypes: []pyroscope.ProfileType{
Expand Down

0 comments on commit 446133b

Please sign in to comment.