Merge pull request #16558 from wbh1/fix/GOGC-ENV-VAR
buf.build / lint and publish (push) Has been cancelled Details
CI / Go tests (push) Has been cancelled Details
CI / More Go tests (push) Has been cancelled Details
CI / Go tests with previous Go version (push) Has been cancelled Details
CI / UI tests (push) Has been cancelled Details
CI / Go tests on Windows (push) Has been cancelled Details
CI / Mixins tests (push) Has been cancelled Details
CI / Build Prometheus for common architectures (0) (push) Has been cancelled Details
CI / Build Prometheus for common architectures (1) (push) Has been cancelled Details
CI / Build Prometheus for common architectures (2) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (0) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (1) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (10) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (11) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (2) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (3) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (4) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (5) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (6) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (7) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (8) (push) Has been cancelled Details
CI / Build Prometheus for all architectures (9) (push) Has been cancelled Details
CI / Check generated parser (push) Has been cancelled Details
CI / golangci-lint (push) Has been cancelled Details
CI / fuzzing (push) Has been cancelled Details
CI / codeql (push) Has been cancelled Details
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled Details
CI / Report status of build Prometheus for all architectures (push) Has been cancelled Details
CI / Publish main branch artifacts (push) Has been cancelled Details
CI / Publish release artefacts (push) Has been cancelled Details
CI / Publish UI on npm Registry (push) Has been cancelled Details

fix(config): respect GOGC environment variable if no "runtime" block exists
This commit is contained in:
Ayoub Mrini 2025-05-13 23:34:08 +02:00 committed by GitHub
commit 2690761582
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 17 deletions

View File

@ -685,12 +685,11 @@ func TestRuntimeGOGCConfig(t *testing.T) {
name: "empty config file",
expectedGOGC: 75,
},
// the GOGC env var is ignored in this case, see https://github.com/prometheus/prometheus/issues/16334
/* {
{
name: "empty config file with GOGC env var set",
gogcEnvVar: "66",
expectedGOGC: 66,
}, */
},
{
name: "gogc set through config",
config: `
@ -719,15 +718,14 @@ runtime:`,
gogcEnvVar: "88",
expectedGOGC: 88,
},
// the GOGC env var is ignored in this case, see https://github.com/prometheus/prometheus/issues/16334
/* {
name: "unrelated config and GOGC env var set",
config: `
global:
scrape_interval: 500ms`,
gogcEnvVar: "80",
expectedGOGC: 80,
}, */
{
name: "unrelated config and GOGC env var set",
config: `
global:
scrape_interval: 500ms`,
gogcEnvVar: "80",
expectedGOGC: 80,
},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

View File

@ -175,7 +175,7 @@ var (
DefaultRuntimeConfig = RuntimeConfig{
// Go runtime tuning.
GoGC: 75,
GoGC: getGoGC(),
}
// DefaultScrapeConfig is the default scrape configuration.
@ -385,8 +385,6 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// We have to restore it here.
if c.Runtime.isZero() {
c.Runtime = DefaultRuntimeConfig
// Use the GOGC env var value if the runtime section is empty.
c.Runtime.GoGC = getGoGCEnv()
}
for _, rf := range c.RuleFiles {
@ -652,6 +650,8 @@ func (c *GlobalConfig) isZero() bool {
!c.AlwaysScrapeClassicHistograms
}
const DefaultGoGCPercentage = 75
// RuntimeConfig configures the values for the process behavior.
type RuntimeConfig struct {
// The Go garbage collection target percentage.
@ -1494,7 +1494,7 @@ func fileErr(filename string, err error) error {
return fmt.Errorf("%q: %w", filePath(filename), err)
}
func getGoGCEnv() int {
func getGoGC() int {
goGCEnv := os.Getenv("GOGC")
// If the GOGC env var is set, use the same logic as upstream Go.
if goGCEnv != "" {
@ -1507,7 +1507,7 @@ func getGoGCEnv() int {
return i
}
}
return DefaultRuntimeConfig.GoGC
return DefaultGoGCPercentage
}
type translationStrategyOption string