Skip to content

Conversation

eskandaridanial
Copy link
Contributor

This PR resolves the issue where running Prometheus with an empty config body results in GoGC being set to 0. The fix ensures that the default value of GoGC is properly set in DefaultConfig.

Fixes #16029

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Copy link
Member

@machine424 machine424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

This should address the empty config filecase raised in the issue, but empty config file with GOGC env var set still needs a fix. That will require moving some parts, we can take care of that in a another PR if you want.
(we can also add more tests to this gogc part)

…nfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
@eskandaridanial eskandaridanial force-pushed the fix/gogc_default_value_on_empty_config_body branch from ab90765 to fe55698 Compare February 21, 2025 17:31
…plicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Copy link
Member

@machine424 machine424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this.
lgtm.
ok, let's have the other change in a follow-up and let's have more tests as well. Again you can fix/adjust and make use of the tests I have here #15238 if needed.

@machine424 machine424 merged commit 5efaa84 into prometheus:main Feb 27, 2025
27 checks passed
machine424 pushed a commit to machine424/prometheus that referenced this pull request Feb 28, 2025
…16052)

* fix: set gogc default value when config body is empty

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: explicitly check value 75 in `TestGoGCDefaultValueOnEmptyConfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: remove `TestGoGCDefaultValueOnEmptyConfigBody` to reduce duplicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

---------

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
machine424 pushed a commit to machine424/prometheus that referenced this pull request Feb 28, 2025
…16052)

* fix: set gogc default value when config body is empty

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: explicitly check value 75 in `TestGoGCDefaultValueOnEmptyConfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: remove `TestGoGCDefaultValueOnEmptyConfigBody` to reduce duplicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

---------

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
machine424 pushed a commit to machine424/prometheus that referenced this pull request Mar 5, 2025
…16052)

* fix: set gogc default value when config body is empty

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: explicitly check value 75 in `TestGoGCDefaultValueOnEmptyConfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: remove `TestGoGCDefaultValueOnEmptyConfigBody` to reduce duplicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

---------

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
machine424 pushed a commit to machine424/prometheus that referenced this pull request Mar 5, 2025
…16052)

* fix: set gogc default value when config body is empty

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: explicitly check value 75 in `TestGoGCDefaultValueOnEmptyConfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: remove `TestGoGCDefaultValueOnEmptyConfigBody` to reduce duplicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

---------

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
machine424 pushed a commit to machine424/prometheus that referenced this pull request Mar 5, 2025
…16052)

* fix: set gogc default value when config body is empty

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: explicitly check value 75 in `TestGoGCDefaultValueOnEmptyConfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: remove `TestGoGCDefaultValueOnEmptyConfigBody` to reduce duplicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

---------

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
machine424 pushed a commit to machine424/prometheus that referenced this pull request Mar 5, 2025
…16052)

* fix: set gogc default value when config body is empty

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: explicitly check value 75 in `TestGoGCDefaultValueOnEmptyConfigBody`

add GoGC assertion in `TestEmptyConfig`, also removed the no longer needed runtime config assignment in `TestEmptyGlobalBlock`

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

* refactor: remove `TestGoGCDefaultValueOnEmptyConfigBody` to reduce duplicate assertions

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>

---------

Signed-off-by: Danial Eskandari <doneskandari@gmail.com>
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
krajorama added a commit that referenced this pull request Mar 11, 2025
backport[2.53]: config: set gogc default value when config body is empty (#16052)
mrnonz added a commit to mrnonz/prometheus that referenced this pull request Mar 18, 2025
…16052)

Signed-off-by: Nontawat Numor <nontawat39@gmail.com>
mrnonz added a commit to mrnonz/prometheus that referenced this pull request Mar 18, 2025
…16052)

Signed-off-by: Nontawat Numor <nontawat39@gmail.com>
wbh1 added a commit to wbh1/prometheus that referenced this pull request May 5, 2025
…exists

Fixes: prometheus#16334
Related to:
- prometheus#15238
- prometheus#16052

Currently, when the GOGC environment variable is set -- and no `runtime`
block is set in the Prometheus config file -- it is ignored and the
default value of 75% is always used.

However, if there is an empty runtime block (e.g. `runtime: {}`), _then_
the GOGC environment variable is checked.

This PR changes this behavior to consistently check and use the GOGC
environment variable when it is set (unless the `gogc` field is set in
the `runtime` block of the loaded config file, in which case it still
gives that precedence).

Co-authored-by: Adam Rambo <arambo@protonmail.com>
Signed-off-by: Will Hegedus <whegedus@akamai.com>
wbh1 added a commit to wbh1/prometheus that referenced this pull request May 12, 2025
…exists

Fixes: prometheus#16334
Related to:
- prometheus#15238
- prometheus#16052

Currently, when the GOGC environment variable is set -- and no `runtime`
block is set in the Prometheus config file -- it is ignored and the
default value of 75% is always used.

However, if there is an empty runtime block (e.g. `runtime: {}`), _then_
the GOGC environment variable is checked.

This PR changes this behavior to consistently check and use the GOGC
environment variable when it is set (unless the `gogc` field is set in
the `runtime` block of the loaded config file, in which case it still
gives that precedence).

Co-authored-by: Adam Rambo <arambo@protonmail.com>
Signed-off-by: Will Hegedus <whegedus@akamai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gogc is being set to 0 when installed with empty prometheus.yml file resulting high cpu usage
2 participants