Skip to content

Commit

Permalink
Merge pull request #104 from buildearth/master
Browse files Browse the repository at this point in the history
add custom api for json backfill
  • Loading branch information
mikigo authored Sep 2, 2024
2 parents fc50953 + 01b88e8 commit 74a9d2b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/rtk/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Args(Enum):
json_backfill_task_id = "json_backfill_task_id"
json_backfill_user = "json_backfill_user"
json_backfill_password = "json_backfill_password"
json_backfill_custom_api = "json_backfill_custom_api"


def transform_app_name(app_name):
Expand Down
4 changes: 4 additions & 0 deletions src/rtk/_cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def remote_runner(parser, sub_parser_remote):
sub_parser_remote.add_argument(
"--json_backfill_password", default="", help="json报告回填的密码"
)
sub_parser_remote.add_argument(
"--json_backfill_custom_api", default="", help="json报告回填的自定义api,默认是/api/youqu/yqresult/"
)

local_kwargs, args = local_runner(parser, sub_parser_remote)
from src.rtk._base import Args
Expand All @@ -208,6 +211,7 @@ def remote_runner(parser, sub_parser_remote):
Args.json_backfill_task_id.value: args.json_backfill_task_id,
Args.json_backfill_user.value: args.json_backfill_user,
Args.json_backfill_password.value: args.json_backfill_password,
Args.json_backfill_custom_api.value: args.json_backfill_custom_api,
}
_remote_kwargs = {
"remote_kwargs": remote_kwargs,
Expand Down
8 changes: 5 additions & 3 deletions src/rtk/json_backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import json
import os
import re
from urllib.parse import urljoin

from setting import conf
from src.rtk.api_client import ApiClient
Expand All @@ -17,10 +18,11 @@
class JsonBackfill:
__author__ = "[email protected]"

def __init__(self, base_url, username, password):
def __init__(self, base_url, username, password, custom_api="api/youqu/yqresult/"):
self.base_url = base_url
self.username = username
self.password = password
self.custom_api = custom_api
self.api = ApiClient(
base_url=self.base_url,
username=self.username,
Expand Down Expand Up @@ -65,10 +67,10 @@ def remote_backfill(self, json_path, json_backfill_task_id):
tpl["longrepr"] = value.get("longrepr")
tpl["pm_ip"] = _ip
res = self.api.post(
url=f"{self.base_url}/api/youqu/yqresult/",
url=urljoin(self.base_url, self.custom_api),
json=tpl
)
print(res)
print(self.custom_api, res)


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion src/rtk/remote_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
Args.json_backfill_task_id.value: remote_kwargs.get("json_backfill_task_id"),
Args.json_backfill_user.value: remote_kwargs.get("json_backfill_user"),
Args.json_backfill_password.value: remote_kwargs.get("json_backfill_password"),
Args.json_backfill_custom_api.value: remote_kwargs.get("json_backfill_custom_api") or "api/youqu/yqresult/"
}
# 客户端地址
if "/home/" not in GlobalConfig.ROOT_DIR:
Expand Down Expand Up @@ -515,13 +516,15 @@ def get_report(self, client_list):
self.default.get(Args.json_backfill_base_url.value),
self.default.get(Args.json_backfill_task_id.value),
self.default.get(Args.json_backfill_user.value),
self.default.get(Args.json_backfill_password.value)
self.default.get(Args.json_backfill_password.value),
self.default.get(Args.json_backfill_custom_api.value)
]):
from src.rtk.json_backfill import JsonBackfill
JsonBackfill(
base_url=self.default.get(Args.json_backfill_base_url.value),
username=self.default.get(Args.json_backfill_user.value),
password=self.default.get(Args.json_backfill_password.value),
custom_api=self.default.get(Args.json_backfill_custom_api.value),
).remote_backfill(self.server_detail_json_path, self.default.get(Args.json_backfill_task_id.value))
# 分布式执行的情况下需要汇总结果
if not self.default.get(Args.parallel.value):
Expand Down

0 comments on commit 74a9d2b

Please sign in to comment.