Skip to content

Commit

Permalink
run_test.py: Implement --minify-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ypid-geberit committed Jun 25, 2020
1 parent 0c48062 commit d7f1b62
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Alerting/Sample Watches/run_test.py
Expand Up @@ -34,6 +34,12 @@ def load_file(serialized_file):
parser.add_argument('--protocol', help='protocol')
parser.add_argument('--cacert', help='CA certificate to trust for HTTPS')
parser.add_argument('--test_file', help='test file')
parser.add_argument(
'--minify-scripts',
help='Minify script source code as workaround for' +
' "Scripts may be no longer than 16384 characters." for ES > 6.6.',
action='store_true')
# Ref: https://github.com/elastic/elasticsearch/pull/35184
parser.add_argument('--keep-index', help='Keep the index where test documents have been loaded to after the test', action='store_true')
parser.add_argument('--metadata-git-commit', help='Include the git commit hash in the metadata field of the watcher', action='store_true')
parser.add_argument('--modify-watch-by-eval', help='Python code to modify the watch before loading it into Elastic')
Expand Down Expand Up @@ -84,7 +90,12 @@ def load_file(serialized_file):
# Load Scripts
if 'scripts' in test:
for script in test['scripts']:
es.put_script(id=script["name"], body=load_file(script['path']))
script_content = load_file(script['path'])
if args.minify_scripts:
# https://stackoverflow.com/questions/30795954/how-to-uglify-or-minify-c-code
p = subprocess.Popen(['gcc', '-fpreprocessed', '-dD', '-E', '-P', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
script_content['script']['source'] = p.communicate(input=script_content['script']['source'].encode('utf-8'))[0].decode('utf-8')
es.put_script(id=script["name"], body=script_content)

# Load Watch and Execute
watch = load_file(test['watch_file'])
Expand Down

0 comments on commit d7f1b62

Please sign in to comment.