VictoriaMetrics/lib/promscrape/discovery/kubernetes
Zakhar Bessarab b3b29ba6ac
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-03 10:01:43 +02:00
..
testdata lib/promscrape/discovery/kubernetes: follow-up after 0b5c874911 (#2672) 2022-06-01 20:44:45 +02:00
api.go lib/promscrape/discovery/kubernetes: propagate possible errors at newAPIWatcher() to the caller 2023-10-27 20:24:46 +02:00
api_watcher.go lib/{promauth,promscrape}: automatically refresh root CA certificates after changes on disk (#5725) 2024-04-03 10:01:43 +02:00
api_watcher_test.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:00 -08:00
common_types.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:00 -08:00
endpoints.go lib/promscrape/discovery/kubernetes: do not generate targets for already terminated pods and containers 2024-01-24 14:57:53 +02:00
endpoints_test.go lib/promscrape/discovery/kubernetes: follow-up for d5e94721db (#4255) 2023-05-05 14:41:17 +02:00
endpointslice.go lib/promscrape/discovery/kubernetes: do not generate targets for already terminated pods and containers 2024-01-24 14:57:53 +02:00
endpointslice_test.go lib/promscrape/discovery/kubernetes: follow-up for d5e94721db (#4255) 2023-05-05 14:41:17 +02:00
ingress.go Makefile: update golangci-lint from v1.51.2 to v1.54.2 2023-09-01 10:16:42 +02:00
ingress_test.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:00 -08:00
kubeconfig.go all: allow dynamically reading *AuthKey flag values from files and urls 2024-01-21 22:03:38 +02:00
kubeconfig_test.go lib/promscrape/discovery/kubernetes/kubeconfig_test.go: make TestParseKubeConfigSuccess test code easier to follow 2023-10-25 23:17:18 +02:00
kubernetes.go lib/promscrape/discovery/kubernetes: add -promscrape.kubernetes.attachNodeMetadataAll command-line flag 2024-01-21 03:13:56 +02:00
node.go Makefile: update golangci-lint from v1.51.2 to v1.54.2 2023-09-01 10:16:42 +02:00
node_test.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:00 -08:00
pod.go lib/promscrape/discovery/kubernetes: typo fix in the comment for ContainerStateTerminated struct 2024-01-24 15:06:46 +02:00
pod_test.go lib/promscrape/discovery/kubernetes: do not generate targets for already terminated pods and containers 2024-01-24 14:57:53 +02:00
pod_timing_test.go all: consistently use %w instead of %s in when error is passed to fmt.Errorf() 2023-10-25 21:24:03 +02:00
service.go Makefile: update golangci-lint from v1.51.2 to v1.54.2 2023-09-01 10:16:42 +02:00
service_test.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:00 -08:00