Commit 21f8bc4c authored by Jérome Perrin's avatar Jérome Perrin

Fix slow query promise

- from now on we want the reports as .xz
- fix type argument parsing which should make the promise effective now

See merge request !83
parents e6a80ee2 28453d17
...@@ -11,6 +11,8 @@ for f in sorted(glob.glob(os.path.join('slapos', 'README.*.rst'))): ...@@ -11,6 +11,8 @@ for f in sorted(glob.glob(os.path.join('slapos', 'README.*.rst'))):
long_description += open("CHANGES.txt").read() + "\n" long_description += open("CHANGES.txt").read() + "\n"
test_require = ['mock', 'cryptography',]
setup(name=name, setup(name=name,
version=version, version=version,
description="SlapOS toolbox.", description="SlapOS toolbox.",
...@@ -40,6 +42,7 @@ setup(name=name, ...@@ -40,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',
...@@ -56,11 +59,9 @@ setup(name=name, ...@@ -56,11 +59,9 @@ setup(name=name,
'lampconfigure': ["mysqlclient"], #needed for MySQL Database access 'lampconfigure': ["mysqlclient"], #needed for MySQL Database access
'zodbpack': ['ZODB3'], # needed to play with ZODB 'zodbpack': ['ZODB3'], # needed to play with ZODB
'flask_auth' : ["Flask-Auth"], 'flask_auth' : ["Flask-Auth"],
'test': test_require,
}, },
tests_require = [ tests_require=test_require,
'mock',
'cryptography',
],
zip_safe=False, # proxy depends on Flask, which has issues with zip_safe=False, # proxy depends on Flask, which has issues with
# accessing templates # accessing templates
entry_points={ entry_points={
......
...@@ -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
...@@ -70,8 +71,8 @@ def main(): ...@@ -70,8 +71,8 @@ def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--ptdigest_path", required=True) parser.add_argument("--ptdigest_path", required=True)
parser.add_argument("--status_file", required=True) parser.add_argument("--status_file", required=True)
parser.add_argument("--max_queries_threshold", required=True) parser.add_argument("--max_queries_threshold", required=True, type=float)
parser.add_argument("--slowest_query_threshold", required=True) parser.add_argument("--slowest_query_threshold", required=True, type=float)
args = parser.parse_args() args = parser.parse_args()
status, message = checkMariadbDigestResult(args.ptdigest_path, args.status_file, status, message = checkMariadbDigestResult(args.ptdigest_path, args.status_file,
......
...@@ -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(os.path.join(self.base_path, "ptdigest.txt"), 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