Skip to content

Commit 1b601c7

Browse files
committed
Tolerate missing deps in get-stats.py
In order to run on systems where not all requirements are present, we should be tolerant of missing external dependencies, such as psutil and pymysql. Print a warning (to stderr) and just leave out those stats in that case. Also make running the stats collector use ignore_errors:yes to avoid failures in the future. I think the stats is not critical enough to fail a job for bugs like this. Related-Bug: #1970195 Change-Id: I132b0e1f5033c4f109a8b8cc776c0877574c4a49
1 parent 76c519b commit 1b601c7

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

roles/capture-performance-data/tasks/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
{% for i in debian_suse_apache_deref_logs.results | default([]) + redhat_apache_deref_logs.results | default([]) %}
1414
--apache-log="{{ i.stat.path }}"
1515
{% endfor %}
16+
ignore_errors: yes

tools/get-stats.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@
66
import itertools
77
import json
88
import os
9-
import psutil
109
import re
1110
import socket
1211
import subprocess
1312
import sys
14-
import pymysql
13+
14+
try:
15+
import psutil
16+
except ImportError:
17+
psutil = None
18+
print('No psutil, process information will not be included',
19+
file=sys.stderr)
20+
21+
try:
22+
import pymysql
23+
except ImportError:
24+
pymysql = None
25+
print('No pymysql, database information will not be included',
26+
file=sys.stderr)
1527

1628
# https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion
1729

@@ -144,10 +156,10 @@ def get_report_info():
144156

145157
data = {
146158
'services': get_services_stats(),
147-
'db': args.db_pass and get_db_stats(args.db_host,
148-
args.db_user,
149-
args.db_pass) or [],
150-
'processes': get_processes_stats(args.process),
159+
'db': pymysql and args.db_pass and get_db_stats(args.db_host,
160+
args.db_user,
161+
args.db_pass) or [],
162+
'processes': psutil and get_processes_stats(args.process) or [],
151163
'api': get_http_stats(args.apache_log),
152164
'report': get_report_info(),
153165
}

0 commit comments

Comments
 (0)