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, ...@@ -42,6 +42,7 @@ setup(name=name,
'croniter', # needed to know cron schedule 'croniter', # needed to know cron schedule
'pytz', # needed to manipulate timezone 'pytz', # needed to manipulate timezone
'tzlocal', # needed to manipulate timezone 'tzlocal', # needed to manipulate timezone
'backports.lzma',
'passlib', 'passlib',
'netifaces', 'netifaces',
'erp5.util', 'erp5.util',
......
...@@ -13,6 +13,7 @@ import sys ...@@ -13,6 +13,7 @@ import sys
import time import time
import datetime import datetime
import argparse import argparse
from backports import lzma
def checkMariadbDigestResult(mariadbdex_path, mariadbdex_report_status_file, def checkMariadbDigestResult(mariadbdex_path, mariadbdex_report_status_file,
max_query_threshold, slowest_query_threshold): max_query_threshold, slowest_query_threshold):
...@@ -28,8 +29,8 @@ def checkMariadbDigestResult(mariadbdex_path, mariadbdex_report_status_file, ...@@ -28,8 +29,8 @@ def checkMariadbDigestResult(mariadbdex_path, mariadbdex_report_status_file,
return 0, "Instance has been just deployed. Skipping check.." return 0, "Instance has been just deployed. Skipping check.."
else: else:
for date in today_or_yesterday: for date in today_or_yesterday:
if mariadbdex_file == date.strftime('slowquery_digest.txt-%Y-%m-%d'): if mariadbdex_file == date.strftime('slowquery_digest.txt-%Y-%m-%d.xz'):
with open(os.path.join(mariadbdex_path, mariadbdex_file)) as f: with lzma.open(os.path.join(mariadbdex_path, mariadbdex_file), 'rt') as f:
content = f.read() content = f.read()
if content: if content:
# XXX: if not a lot of usage, skip this # XXX: if not a lot of usage, skip this
......
...@@ -24,13 +24,15 @@ ...@@ -24,13 +24,15 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from __future__ import unicode_literals
import unittest import unittest
import os import os
import time import time
import tempfile import tempfile
import datetime import datetime
import shutil import shutil
import codecs
from backports import lzma
from . import data from . import data
from slapos.promise.check_slow_queries_digest_result import checkMariadbDigestResult from slapos.promise.check_slow_queries_digest_result import checkMariadbDigestResult
...@@ -42,17 +44,17 @@ class TestCheckSlowQueriesDigestResult(unittest.TestCase): ...@@ -42,17 +44,17 @@ class TestCheckSlowQueriesDigestResult(unittest.TestCase):
def _create_file(self, date, with_content): def _create_file(self, date, with_content):
content = '' content = ''
if with_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() 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 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) the_file.write(content)
os.utime(self.base_dir+name, ( oldtime , oldtime )) os.utime(self.base_dir+name, ( oldtime , oldtime ))
def _remove_file(self, date): 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) os.remove(self.base_dir+name)
def setUp(self): 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