-def check_configuration_equal(a_config, b_config):
- if a_config is None and b_config is None:
- return True
- if a_config is None or b_config is None:
- return False
- if not "scrape_configs" in a_config and not "scrape_configs" in b_config:
- return True
- if not "scrape_configs" in a_config or not "scrape_configs" in b_config:
- return False
- a_jobs = [j["job_name"] for j in a_config["scrape_configs"]]
- b_jobs = [j["job_name"] for j in b_config["scrape_configs"]]
-
- return a_jobs == b_jobs
-
-async def validate_configuration(the_prometheus_url, new_config):
- async with aiohttp.ClientSession() as session:
- # If prometheus does not admit this configuration, remains with the old one
- # Then, to check if the configuration has been accepted, get the configuration from prometheus
- # and compares with the inserted one
- async with session.get(the_prometheus_url + "/api/v1/status/config") as resp:
- if resp.status > 204:
- print(f"Error while updating prometheus config : {resp.text()}")
- return False
- current_config = await resp.json()
- return check_configuration_equal(yaml.load(current_config["data"]["yaml"], yaml.FullLoader), new_config)