From 1b601c7b1e8a3ec4816cb827ccd8bf909a05debb Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 25 Apr 2022 07:47:56 -0700 Subject: [PATCH] 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 --- .../capture-performance-data/tasks/main.yaml | 1 + tools/get-stats.py | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/roles/capture-performance-data/tasks/main.yaml b/roles/capture-performance-data/tasks/main.yaml index 2d2cfe4b8b..f9bb0f7851 100644 --- a/roles/capture-performance-data/tasks/main.yaml +++ b/roles/capture-performance-data/tasks/main.yaml @@ -13,3 +13,4 @@ {% for i in debian_suse_apache_deref_logs.results | default([]) + redhat_apache_deref_logs.results | default([]) %} --apache-log="{{ i.stat.path }}" {% endfor %} + ignore_errors: yes diff --git a/tools/get-stats.py b/tools/get-stats.py index dc0bd0f9e5..2418c851f9 100755 --- a/tools/get-stats.py +++ b/tools/get-stats.py @@ -6,12 +6,24 @@ import glob import itertools import json import os -import psutil import re import socket import subprocess import sys -import pymysql + +try: + import psutil +except ImportError: + psutil = None + print('No psutil, process information will not be included', + file=sys.stderr) + +try: + import pymysql +except ImportError: + pymysql = None + print('No pymysql, database information will not be included', + file=sys.stderr) # https://www.elastic.co/blog/found-crash-elasticsearch#mapping-explosion @@ -144,10 +156,10 @@ if __name__ == '__main__': data = { 'services': get_services_stats(), - 'db': args.db_pass and get_db_stats(args.db_host, - args.db_user, - args.db_pass) or [], - 'processes': get_processes_stats(args.process), + 'db': pymysql and args.db_pass and get_db_stats(args.db_host, + args.db_user, + args.db_pass) or [], + 'processes': psutil and get_processes_stats(args.process) or [], 'api': get_http_stats(args.apache_log), 'report': get_report_info(), }