Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COS testing fix #1263

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions zaza/openstack/charm_tests/ceph/mon/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,27 @@ def application_present(name):

def get_up_osd_count(prometheus_url):
"""Get the number of up OSDs from prometheus."""
query = 'ceph_osd_up'
response = requests.get(f'{prometheus_url}/query', params={'query': query})
query = "ceph_osd_up"
response = requests.get(
f"{prometheus_url}/query", params={"query": query}, verify=False
)
data = response.json()
if data['status'] != 'success':
if data["status"] != "success":
raise Exception(f"Query failed: {data.get('error', 'Unknown error')}")

results = data['data']['result']
up_osd_count = sum(int(result['value'][1]) for result in results)
results = data["data"]["result"]
up_osd_count = sum(int(result["value"][1]) for result in results)
return up_osd_count


def extract_pool_names(prometheus_url):
"""Extract pool names from prometheus."""
query = 'ceph_pool_metadata'
response = requests.get(f'{prometheus_url}/query', params={'query': query})
query = "ceph_pool_metadata"
response = requests.get(
f"{prometheus_url}/query", params={"query": query}, verify=False
)
data = response.json()
if data['status'] != 'success':
if data["status"] != "success":
raise Exception(f"Query failed: {data.get('error', 'Unknown error')}")

pool_names = []
Expand All @@ -95,42 +99,45 @@ def extract_pool_names(prometheus_url):

def get_alert_rules(prometheus_url):
"""Get the alert rules from prometheus."""
response = requests.get(f'{prometheus_url}/rules')
response = requests.get(f"{prometheus_url}/rules", verify=False)
data = response.json()
if data['status'] != 'success':
if data["status"] != "success":
raise Exception(f"Query failed: {data.get('error', 'Unknown error')}")

alert_names = set()
for obj in data['data']['groups']:
rules = obj.get('rules', [])
for obj in data["data"]["groups"]:
rules = obj.get("rules", [])
for rule in rules:
name = rule.get('name')
name = rule.get("name")
if name:
alert_names.add(name)
return alert_names


@tenacity.retry(wait=tenacity.wait_fixed(5),
stop=tenacity.stop_after_delay(180))
@tenacity.retry(
wait=tenacity.wait_fixed(5), stop=tenacity.stop_after_delay(180)
)
def get_prom_api_url(grafana_agent):
"""Get the prometheus API URL from the grafana-agent config."""
ga_yaml = zaza.model.file_contents(
f"{grafana_agent}/leader", "/etc/grafana-agent.yaml"
)
ga = yaml.safe_load(ga_yaml)
url = ga['integrations']['prometheus_remote_write'][0]['url']
url = ga["integrations"]["prometheus_remote_write"][0]["url"]
if url.endswith("/write"):
url = url[:-6] # lob off the /write
return url


@tenacity.retry(wait=tenacity.wait_fixed(5),
stop=tenacity.stop_after_delay(180))
@tenacity.retry(
wait=tenacity.wait_fixed(5), stop=tenacity.stop_after_delay(180)
)
def get_dashboards(url, user, passwd):
"""Retrieve a list of dashboards from Grafana."""
response = requests.get(
f"{url}/api/search?type=dash-db",
auth=(user, passwd)
auth=(user, passwd),
verify=False,
)
if response.status_code != 200:
raise Exception(f"Failed to retrieve dashboards: {response}")
Expand Down
Loading