Profiling: Enhance configuration and docs (#90048)

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
Marcus Efraimsson
2024-07-09 17:48:16 +02:00
committed by GitHub
co-authored by Dave Henderson
parent 8a6e92c0c9
commit fc8a5cf468
9 changed files with 160 additions and 51 deletions
@@ -9,17 +9,21 @@ import (
func TestProfilingDiagnostics(t *testing.T) {
tcs := []struct {
defaults *profilingDiagnostics
enabledEnv string
addrEnv string
portEnv string
expected *profilingDiagnostics
defaults *profilingDiagnostics
enabledEnv string
addrEnv string
portEnv string
blockRateEnv string
mutexRateEnv string
expected *profilingDiagnostics
}{
{defaults: newProfilingDiagnostics(false, "localhost", 6060), enabledEnv: "", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(false, "localhost", 6060)},
{defaults: newProfilingDiagnostics(true, "0.0.0.0", 8080), enabledEnv: "", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(true, "0.0.0.0", 8080)},
{defaults: newProfilingDiagnostics(false, "", 6060), enabledEnv: "false", addrEnv: "", portEnv: "8080", expected: newProfilingDiagnostics(false, "", 8080)},
{defaults: newProfilingDiagnostics(false, "localhost", 6060), enabledEnv: "true", addrEnv: "0.0.0.0", portEnv: "8080", expected: newProfilingDiagnostics(true, "0.0.0.0", 8080)},
{defaults: newProfilingDiagnostics(false, "127.0.0.1", 6060), enabledEnv: "true", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(true, "127.0.0.1", 6060)},
{defaults: newProfilingDiagnostics(false, "localhost", 6060, 0, 0), enabledEnv: "", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(false, "localhost", 6060, 0, 0)},
{defaults: newProfilingDiagnostics(true, "0.0.0.0", 8080, 0, 0), enabledEnv: "", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(true, "0.0.0.0", 8080, 0, 0)},
{defaults: newProfilingDiagnostics(false, "", 6060, 0, 0), enabledEnv: "false", addrEnv: "", portEnv: "8080", expected: newProfilingDiagnostics(false, "", 8080, 0, 0)},
{defaults: newProfilingDiagnostics(false, "localhost", 6060, 0, 0), enabledEnv: "true", addrEnv: "0.0.0.0", portEnv: "8080", expected: newProfilingDiagnostics(true, "0.0.0.0", 8080, 0, 0)},
{defaults: newProfilingDiagnostics(false, "127.0.0.1", 6060, 0, 0), enabledEnv: "true", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(true, "127.0.0.1", 6060, 0, 0)},
{defaults: newProfilingDiagnostics(true, "localhost", 6060, 0, 0), enabledEnv: "", addrEnv: "", portEnv: "", blockRateEnv: "3", mutexRateEnv: "4", expected: newProfilingDiagnostics(true, "localhost", 6060, 3, 4)},
{defaults: newProfilingDiagnostics(true, "localhost", 6060, 0, 0), enabledEnv: "", addrEnv: "", portEnv: "", expected: newProfilingDiagnostics(true, "localhost", 6060, 0, 0)},
}
for i, tc := range tcs {
@@ -33,6 +37,12 @@ func TestProfilingDiagnostics(t *testing.T) {
if tc.portEnv != "" {
t.Setenv(profilingPortEnvName, tc.portEnv)
}
if tc.blockRateEnv != "" {
t.Setenv(profilingBlockRateEnvName, tc.blockRateEnv)
}
if tc.mutexRateEnv != "" {
t.Setenv(profilingMutexRateEnvName, tc.mutexRateEnv)
}
err := tc.defaults.overrideWithEnv()
assert.NoError(t, err)
assert.Exactly(t, tc.expected, tc.defaults)