Skip to content

Commit c6bac65

Browse files
authored
Out of the box support for enabling profiling via Grafana (#460)
* add support for supplementary env vars * reorder * fix spaces * use grafana naming conventions
1 parent a62a98d commit c6bac65

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

backend/setup.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import (
77
"os"
88
)
99

10-
const (
11-
// PluginProfilerEnv is a constant for the GF_PLUGINS_PROFILER environment variable used to enable pprof.
12-
PluginProfilerEnv = "GF_PLUGINS_PROFILER"
10+
var (
11+
// PluginProfilerEnvDeprecated is a deprecated constant for the GF_PLUGINS_PROFILER environment variable used to enable pprof.
12+
PluginProfilerEnvDeprecated = "GF_PLUGINS_PROFILER"
13+
// PluginProfilingEnabledEnv is a constant for the GF_PLUGIN_PROFILING_ENABLED environment variable used to enable pprof.
14+
PluginProfilingEnabledEnv = "GF_PLUGIN_PROFILING_ENABLED"
1315

14-
// PluginProfilerPortEnv is a constant for the GF_PLUGINS_PROFILER_PORT environment variable use to specify a pprof port (default 6060).
15-
PluginProfilerPortEnv = "GF_PLUGINS_PROFILER_PORT"
16+
// PluginProfilerPortEnvDeprecated is a constant for the GF_PLUGINS_PROFILER_PORT environment variable use to specify a pprof port (default 6060).
17+
PluginProfilerPortEnvDeprecated = "GF_PLUGINS_PROFILER_PORT"
18+
// PluginProfilingPortEnv is a constant for the GF_PLUGIN_PROFILING_PORT environment variable use to specify a pprof port (default 6060).
19+
PluginProfilingPortEnv = "GF_PLUGIN_PROFILING_PORT"
1620
)
1721

1822
// SetupPluginEnvironment will read the environment variables and apply the
@@ -24,19 +28,26 @@ const (
2428
func SetupPluginEnvironment(pluginID string) {
2529
// Enable profiler
2630
profilerEnabled := false
27-
if value, ok := os.LookupEnv(PluginProfilerEnv); ok {
31+
if value, ok := os.LookupEnv(PluginProfilerEnvDeprecated); ok {
2832
// compare value to plugin name
2933
if value == pluginID {
3034
profilerEnabled = true
3135
}
36+
} else if value, ok = os.LookupEnv(PluginProfilingEnabledEnv); ok {
37+
if value == "true" {
38+
profilerEnabled = true
39+
}
3240
}
41+
3342
Logger.Info("Profiler", "enabled", profilerEnabled)
3443
if profilerEnabled {
3544
profilerPort := "6060"
36-
if value, ok := os.LookupEnv(PluginProfilerPortEnv); ok {
37-
profilerPort = value
45+
for _, env := range []string{PluginProfilerPortEnvDeprecated, PluginProfilingPortEnv} {
46+
if value, ok := os.LookupEnv(env); ok {
47+
profilerPort = value
48+
break
49+
}
3850
}
39-
4051
Logger.Info("Profiler", "port", profilerPort)
4152
portConfig := fmt.Sprintf(":%s", profilerPort)
4253

0 commit comments

Comments
 (0)