From 51ade289548eb40365fb0944dd8eaf4509022bb6 Mon Sep 17 00:00:00 2001 From: "Harris.Chu" <1726587+HarrisChu@users.noreply.github.com> Date: Mon, 2 Aug 2021 10:55:43 +0800 Subject: [PATCH] offline package (#29) --- .gitignore | 5 +++- nebula-bench.spec | 43 ++++++++++++++++++++++++++++++ nebula_bench/scenarios/__init__.py | 2 ++ nebula_bench/setting.py | 2 +- nebula_bench/stress.py | 6 +++-- nebula_bench/utils.py | 22 ++++++--------- package.sh | 16 +++++++++++ requirements.txt | 10 +++---- requirements_dev.txt | 4 +-- run.py | 1 + scripts/env.sh | 0 scripts/generate-data.sh | 0 scripts/setup.sh | 0 scripts/split-data.sh | 0 14 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 nebula-bench.spec create mode 100644 nebula_bench/scenarios/__init__.py create mode 100755 package.sh mode change 100644 => 100755 scripts/env.sh mode change 100644 => 100755 scripts/generate-data.sh mode change 100644 => 100755 scripts/setup.sh mode change 100644 => 100755 scripts/split-data.sh diff --git a/.gitignore b/.gitignore index 5b96d91..81ab265 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,7 @@ nebula-bench.db output third/*/data scripts/k6 -scripts/nebula-importer \ No newline at end of file +scripts/nebula-importer + +dist +build \ No newline at end of file diff --git a/nebula-bench.spec b/nebula-bench.spec new file mode 100644 index 0000000..ae8d87d --- /dev/null +++ b/nebula-bench.spec @@ -0,0 +1,43 @@ +# -*- mode: python ; coding: utf-8 -*- + + +block_cipher = None +PATH = os.getcwd() + + +a = Analysis(['run.py'], + pathex=[PATH], + binaries=[], + datas=[ + (os.path.join(PATH, 'scripts'), 'scripts'), + (os.path.join(PATH, 'templates'), 'templates'), + (os.path.join(PATH, 'env'), '.'), + ], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + [], + exclude_binaries=True, + name='nebula-bench', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='nebula-bench') diff --git a/nebula_bench/scenarios/__init__.py b/nebula_bench/scenarios/__init__.py new file mode 100644 index 0000000..3b64d84 --- /dev/null +++ b/nebula_bench/scenarios/__init__.py @@ -0,0 +1,2 @@ +from nebula_bench.scenarios import go +from nebula_bench.scenarios import find_path diff --git a/nebula_bench/setting.py b/nebula_bench/setting.py index 088dc97..f763330 100644 --- a/nebula_bench/setting.py +++ b/nebula_bench/setting.py @@ -27,4 +27,4 @@ NEBULA_MAX_CONNECTION = 400 SQLALCHEMY_URI = os.environ.get("SQLALCHEMY_URI") or "sqlite:///./nebula-bench.db" -INFLUXDB_URL = os.environ.get("INFLUXDB_URL") or "http://127.0.0.1:8086/k6" +INFLUXDB_URL = os.environ.get("INFLUXDB_URL", None) diff --git a/nebula_bench/stress.py b/nebula_bench/stress.py index 857e54f..176c462 100644 --- a/nebula_bench/stress.py +++ b/nebula_bench/stress.py @@ -147,11 +147,13 @@ def run(self): "{}s".format(self.duration), "--summary-trend-stats", "min,avg,med,max,p(90),p(95),p(99)", - "--out", - "influxdb={}".format(setting.INFLUXDB_URL), "--summary-export", "{}/result_{}.json".format(self.output_folder, scenario.name), ] + if setting.INFLUXDB_URL is not None: + command.append("--out") + command.append("influxdb={}".format(setting.INFLUXDB_URL)) + click.echo("run command as below:") click.echo(" ".join(command)) if self.dry_run is not None and self.dry_run: diff --git a/nebula_bench/utils.py b/nebula_bench/utils.py index 7683a29..bd14bf6 100644 --- a/nebula_bench/utils.py +++ b/nebula_bench/utils.py @@ -1,16 +1,10 @@ # -*- coding: utf-8 -*- import os import subprocess +import inspect import importlib -from pathlib import Path import socket -import json import logging -import base64 -import hashlib -import hmac -import time -import urllib import jinja2 import click @@ -22,15 +16,15 @@ def load_class(package_name, load_all, base_class, class_name=None): r = [] if load_all: _package = importlib.import_module(package_name) - for namespace_p in _package.__path__: - p = Path(namespace_p) - break - for _module_path in p.iterdir(): - name = _module_path.name.rsplit(".", 1)[0] - _module = importlib.import_module(package_name + "." + name) + for attr in dir(_package): + _module = getattr(_package, attr) + if not inspect.ismodule(_module): + continue + + # _module = importlib.import_module(package_name + "." + name) for name in dir(_module): _class = getattr(_module, name) - if not isinstance(_class, type): + if not inspect.isclass(_class): continue if issubclass(_class, base_class) and _class.__name__ != base_class.__name__: r.append(_class) diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..0a081b2 --- /dev/null +++ b/package.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +set -e + +pip3 install --user -r requirements.txt +pip3 install --user -r requirements_dev.txt + +# compile go tools +/bin/bash scripts/setup.sh + +# package python code +pyinstaller -D nebula-bench.spec + +# tar +cd dist +tar zcvf nebula-bench.tgz nebula-bench/* \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 28368ee..0b7681a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -Jinja2 == 2.11.3 -click == 7.1.2 +Jinja2 +click nebula2-python == 2.0.0 -python-dotenv == 0.16.0 -locust -pymysql \ No newline at end of file +python-dotenv +pyinstaller +wheel \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt index 633f432..5883c3a 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,2 +1,2 @@ -pytest == 6.2.2 -black == 21.5b \ No newline at end of file +pytest +black == 21.5b diff --git a/run.py b/run.py index 77d8b16..d4d3ebe 100644 --- a/run.py +++ b/run.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from nebula_bench.scenarios import * from nebula_bench import cli if __name__ == "__main__": diff --git a/scripts/env.sh b/scripts/env.sh old mode 100644 new mode 100755 diff --git a/scripts/generate-data.sh b/scripts/generate-data.sh old mode 100644 new mode 100755 diff --git a/scripts/setup.sh b/scripts/setup.sh old mode 100644 new mode 100755 diff --git a/scripts/split-data.sh b/scripts/split-data.sh old mode 100644 new mode 100755