VictoriaMetrics/lib/promscrape
Zakhar Bessarab da4352fe7b
lib/{promauth,promscrape}: automatically refresh root CA certificates after changes on disk (#5725)
* lib/{promauth,promscrape}: automatically refresh root CA certificates after changes on disk

Added a custom `http.RoundTripper` implementation which checks for root CA content changes and updates `tls.Config` used by `http.RoundTripper` after detecting CA change.

Client certificate changes are not tracked by this implementation since `tls.Config` already supports passing certificate dynamically by overriding `tls.Config.GetClientCertificate`.

This change implements dynamic reload of root CA only for streaming client used for scraping. Blocking client (`fasthttp.HostClient`) does not support using custom transport so can't use this implementation.

See: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5526

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

* lib/promauth/config: update NewRoundTripper API

Update API to allow user to update only parameters required for transport.

Add warning log when reloading Root CA failed.

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

* lib/promauth/config: fix mutex acquire logic

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

* lib/promauth/config: replace RWMutex with regular mutex to simplify the code

- remove additional mutex used for getRootCABytes - require callee to use mutex
- replace RWMutex with regular mutex

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

* lib/promauth/config: refactor

- hold the mutex lock to avoid round tripper being re-created twice
- move recreation logic into separate func to simplify the code

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

---------

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
Co-authored-by: Nikolay <nik@victoriametrics.com>
2024-04-04 00:34:43 +03:00
..
discovery lib/{promauth,promscrape}: automatically refresh root CA certificates after changes on disk (#5725) 2024-04-04 00:34:43 +03:00
discoveryutils lib/{promauth,promscrape}: automatically refresh root CA certificates after changes on disk (#5725) 2024-04-04 00:34:43 +03:00
testdata lib/promscrape: disable support for service discovery and metrics scrape via http2 2023-07-06 16:04:31 -07:00
client.go lib/{promauth,promscrape}: automatically refresh root CA certificates after changes on disk (#5725) 2024-04-04 00:34:43 +03:00
config_test.go lib/promscrape: add support for enable_compression option in the same way as Prometheus does 2024-02-18 19:42:09 +02:00
config_timing_test.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:23 -08:00
config.go lib/promscrape: add support for enable_compression option in the same way as Prometheus does 2024-02-18 19:42:09 +02:00
relabel_debug.go app/vmselect: small cleanup after 4f3f9950d0 2023-05-09 22:45:02 -07:00
scraper.go all: fix golangci-lint(revive) warnings after 0c0ed61ce7 2024-04-03 03:00:45 +03:00
scrapework_test.go all: fix golangci-lint(revive) warnings after 0c0ed61ce7 2024-04-03 03:00:45 +03:00
scrapework_timing_test.go all: fix golangci-lint(revive) warnings after 0c0ed61ce7 2024-04-03 03:00:45 +03:00
scrapework.go app/{vminsert,vmagent}: allow using -streamAggr.dedupInterval without -streamAggr.config 2024-03-05 00:47:23 +02:00
statconn_test.go lib/promscrape: do not add a suggestion for enabling TCP6 in error message when the dial address is TCPv4 2023-10-27 14:06:49 +02:00
statconn.go lib: consistently use atomic.* types instead of atomic.* functions 2024-02-24 02:10:04 +02:00
targetstatus.go lib/promscrape: add a wraning when the /service-discovery page contains incomplete list of dropped targets 2023-12-08 19:04:29 +02:00
targetstatus.qtpl lib/promscrape: comsetic changes after e373bb84d5 2023-12-12 13:45:34 +01:00
targetstatus.qtpl.go lib/promscrape: comsetic changes after e373bb84d5 2023-12-12 13:45:34 +01:00