Commit d35cf4fc authored by Jérome Perrin's avatar Jérome Perrin

check_slow_queries_digest_result: expect xz compressed pt-query-digest reports

because pt-query-digest are text files that can be large, we should except that
the users have compressed them.
parent 95c3dc61
......@@ -42,6 +42,7 @@ setup(name=name,
'croniter', # needed to know cron schedule
'pytz', # needed to manipulate timezone
'tzlocal', # needed to manipulate timezone
'backports.lzma',
'passlib',
'netifaces',
'erp5.util',
......
......@@ -13,6 +13,7 @@ import sys
import time
import datetime
import argparse
from backports import lzma
def checkMariadbDigestResult(mariadbdex_path, mariadbdex_report_status_file,
max_query_threshold, slowest_query_threshold):
......@@ -28,8 +29,8 @@ def checkMariadbDigestResult(mariadbdex_path, mariadbdex_report_status_file,
return 0, "Instance has been just deployed. Skipping check.."
else:
for date in today_or_yesterday:
if mariadbdex_file == date.strftime('slowquery_digest.txt-%Y-%m-%d'):
with open(os.path.join(mariadbdex_path, mariadbdex_file)) as f:
if mariadbdex_file == date.strftime('slowquery_digest.txt-%Y-%m-%d.xz'):
with lzma.open(os.path.join(mariadbdex_path, mariadbdex_file), 'rt') as f:
content = f.read()
if content:
# XXX: if not a lot of usage, skip this
......
......@@ -24,13 +24,15 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from __future__ import unicode_literals
import unittest
import os
import time
import tempfile
import datetime
import shutil
import codecs
from backports import lzma
from . import data
from slapos.promise.check_slow_queries_digest_result import checkMariadbDigestResult
......@@ -42,17 +44,17 @@ class TestCheckSlowQueriesDigestResult(unittest.TestCase):
def _create_file(self, date, with_content):
content = ''
if with_content:
with open(self.base_path + "/ptdigest.html") as f:
with codecs.open(self.base_path + "/ptdigest.html", encoding='utf-8') as f:
content = f.read()
name = date.strftime('slowquery_digest.txt-%Y-%m-%d')
name = date.strftime('slowquery_digest.txt-%Y-%m-%d.xz')
oldtime = time.mktime(date.timetuple()) + 2000
with open( self.base_dir+name, 'a') as the_file:
with lzma.open( self.base_dir+name, 'at') as the_file:
the_file.write(content)
os.utime(self.base_dir+name, ( oldtime , oldtime ))
def _remove_file(self, date):
name = date.strftime('slowquery_digest.txt-%Y-%m-%d')
name = date.strftime('slowquery_digest.txt-%Y-%m-%d.xz')
os.remove(self.base_dir+name)
def setUp(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment