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