charmed-lma / charm-k8s-prometheus

Kubernetes Operator for Prometheus
Apache License 2.0
4 stars 2 forks source link

domain.check_config_propagation() will always return False #24

Open relaxdiego opened 4 years ago

relaxdiego commented 4 years ago

Because domain.check_config_propagation() uses the Prometheus API to get the current config:

https://github.com/charmed-lma/charm-k8s-prometheus/blob/f23289f99a00439162ebaf5f9daaf03b457722fe/src/domain.py#L426-L429

current_config will actually be the effective configuration as loaded in memory. This effective configuration will be equal to expected_config plus some optional configuration options that Prometheus will have set to their default values. Thus the following line will always return False

https://github.com/charmed-lma/charm-k8s-prometheus/blob/f23289f99a00439162ebaf5f9daaf03b457722fe/src/domain.py#L443

relaxdiego commented 4 years ago

Further investigation shows that the most effective way is to get the current config on disk mounted on /etc/prometheus/prometheus.yaml in the prometheus container. However, this requires opening a websocket connection to the k8s APIServer in the path /api/v1/namespaces/{namespace}/pods/{pod_name}/exec. Python's httplib does not natively support websockets.

relaxdiego commented 4 years ago

Another option is to set the config template such that it explicitly sets the optional configuration values. However, this will only work for as long as Prometheus doesn't change its config schema.