From 446133b1eb140fbb6b271c9b8f7009bff4d77116 Mon Sep 17 00:00:00 2001 From: Daniel Baptista Dias Date: Mon, 4 Mar 2024 16:10:57 -0300 Subject: [PATCH] fix(server): fixing profiler config (#3705) * fix(server): fixing profiler config * fix: profiler startup --- server/cmd/serve.go | 2 +- server/config/exporters.go | 1 + server/config/validate.go | 1 - server/telemetry/profiler.go | 14 ++++++++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/cmd/serve.go b/server/cmd/serve.go index 37b1503e63..180dd5c1cb 100644 --- a/server/cmd/serve.go +++ b/server/cmd/serve.go @@ -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) diff --git a/server/config/exporters.go b/server/config/exporters.go index 5546835dc8..a6aa5d21a4 100644 --- a/server/config/exporters.go +++ b/server/config/exporters.go @@ -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"` } ) diff --git a/server/config/validate.go b/server/config/validate.go index 92b70f2916..dc32b7965c 100644 --- a/server/config/validate.go +++ b/server/config/validate.go @@ -37,7 +37,6 @@ func (c *AppConfig) Validate() error { err, fmt.Errorf("invalid config value for '%s': %s", opt.key, optErr.Error()), ) - } return err diff --git a/server/telemetry/profiler.go b/server/telemetry/profiler.go index 7141dee392..6a84b72593 100644 --- a/server/telemetry/profiler.go +++ b/server/telemetry/profiler.go @@ -1,6 +1,7 @@ package telemetry import ( + "fmt" "os" "runtime" @@ -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) @@ -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{