Skip to content

config: Remove validation GetScrapeConfigs; require using config.Load.#15637

Merged
bwplotka merged 3 commits intomainfrom
fix15538-2
Dec 12, 2024
Merged

config: Remove validation GetScrapeConfigs; require using config.Load.#15637
bwplotka merged 3 commits intomainfrom
fix15538-2

Conversation

@bwplotka
Copy link
Member

We should never modify (or even shallow copy) Config after config.Load; added comments and modified GetScrapeConfigs to do so. For GetScrapeConfigs the validation (even repeated) was likely doing writes (because global fields was 0). We GetScrapeConfigs concurrently in tests and ApplyConfig causing test races. In prod there were races but likelyt only to replace 0 with 0, so not too severe.

I removed validation since I don't see anyone using our config.Config without Load. I had to refactor one test that was doing it, all others use yaml config.

Fixes #15538
Previous attempt: #15634

We should never modify (or even shallow copy) Config after config.Load;
added comments and modified GetScrapeConfigs to do so. For GetScrapeConfigs
the validation (even repeated) was likely doing writes (because global fields was 0). We GetScrapeConfigs concurrently
in tests and ApplyConfig causing test races. In prod there were
races but likelyt only to replace 0 with 0, so not too severe.

I removed validation since I don't see anyone using our config.Config without Load.
I had to refactor one test that was doing it, all others use yaml config.

Fixes #15538
Previous attempt: #15634

Signed-off-by: bwplotka <bwplotka@gmail.com>
Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

overall LGTM, just some questions/comments

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.

lgtm as well, thanks for this.
(I'll look tomorrow at the tests changes when I have some time)

bwplotka and others added 2 commits December 12, 2024 10:06
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: bwplotka <bwplotka@gmail.com>
Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

LGTM

@juliusv
Copy link
Member

juliusv commented Dec 18, 2024

This was merged on Dec 12, but I just got the same error again on Dec 14 unfortunately.

sky333999 added a commit to aws/amazon-cloudwatch-agent that referenced this pull request Feb 12, 2026
Prometheus v0.308.1 added an internal 'loaded' boolean to promconfig.Config.
GetScrapeConfigs() now returns an error if the config was not loaded through
promconfig.Load() or Reload(). Our translator manually copies GlobalConfig,
ScrapeConfigs, and TracingConfig from a parsed PromConfig, bypassing Load(),
so the loaded flag was never set.

Added cfg.PrometheusConfig.Reload() after the manual field copy. Reload()
runs the config through Load() internally, setting the loaded flag and
populating new default fields like ScrapeFallbackProtocol.

Upstream PR: prometheus/prometheus#15637
sky333999 added a commit to aws/amazon-cloudwatch-agent that referenced this pull request Feb 15, 2026
Prometheus v0.308.1 added an internal 'loaded' boolean to promconfig.Config.
GetScrapeConfigs() now returns an error if the config was not loaded through
promconfig.Load() or Reload(). Our translator manually copies GlobalConfig,
ScrapeConfigs, and TracingConfig from a parsed PromConfig, bypassing Load(),
so the loaded flag was never set.

Added cfg.PrometheusConfig.Reload() after the manual field copy. Reload()
runs the config through Load() internally, setting the loaded flag and
populating new default fields like ScrapeFallbackProtocol.

Upstream PR: prometheus/prometheus#15637
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.

data race in TestOnlyProviderStaleTargetsAreDropped

4 participants