-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
log-viewer-webui: Add server implementation for submitting IR extraction jobs and serving IR files; Don't copy unnecessary files when building component. #458
Changes from all commits
220aeb8
b6dcb54
77cd631
8664a31
b932901
c13d39d
f017d0b
4729971
7859aba
15b7459
0c99ef1
f090aff
7a892dc
eda691c
d3fe4a4
27b4d0d
ea337cc
ea3210a
a9e9cc7
cf60f36
f99a39e
a6a543f
be5a95f
469bf3a
ce6d76a
0112dc1
cf55e8c
8baf2da
fba76c3
1af7e05
8bb6af7
4cb16ad
e46f536
c6f3a87
094f330
ac01b8d
ae9d86c
c125729
36a4f51
9b19d8b
0501a61
299257f
c02c9ee
f0f05e2
06d4f84
89a7036
56791b5
bcb3554
4327c27
1e1a85a
85c2954
08cce9b
9339a3d
bd96c03
6a16fd8
10debf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ | |
validate_and_load_queue_credentials_file, | ||
validate_and_load_redis_credentials_file, | ||
validate_db_config, | ||
validate_log_viewer_config, | ||
validate_log_viewer_webui_config, | ||
validate_queue_config, | ||
validate_redis_config, | ||
validate_reducer_config, | ||
|
@@ -668,13 +668,13 @@ def generic_start_worker( | |
logger.info(f"Started {component_name}.") | ||
|
||
|
||
def update_meteor_settings( | ||
def update_settings_object( | ||
parent_key_prefix: str, | ||
settings: Dict[str, Any], | ||
updates: Dict[str, Any], | ||
): | ||
""" | ||
Recursively updates the given Meteor settings object with the values from `updates`. | ||
Recursively updates the given settings object with the values from `updates`. | ||
:param parent_key_prefix: The prefix for keys at this level in the settings dictionary. | ||
:param settings: The settings to update. | ||
|
@@ -686,11 +686,25 @@ def update_meteor_settings( | |
error_msg = f"{parent_key_prefix}{key} is not a valid configuration key for the webui." | ||
raise ValueError(error_msg) | ||
if isinstance(value, dict): | ||
update_meteor_settings(f"{parent_key_prefix}{key}.", settings[key], value) | ||
update_settings_object(f"{parent_key_prefix}{key}.", settings[key], value) | ||
else: | ||
settings[key] = updates[key] | ||
|
||
|
||
def read_and_update_settings_json(settings_file_path: pathlib.Path, updates: Dict[str, Any]): | ||
""" | ||
Reads and updates a settings JSON file. | ||
:param settings_file_path: | ||
:param updates: | ||
""" | ||
with open(settings_file_path, "r") as settings_json_file: | ||
settings_object = json.loads(settings_json_file.read()) | ||
update_settings_object("", settings_object, updates) | ||
|
||
return settings_object | ||
|
||
|
||
def start_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPDockerMounts): | ||
component_name = WEBUI_COMPONENT_NAME | ||
logger.info(f"Starting {component_name}...") | ||
|
@@ -710,8 +724,8 @@ def start_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPDockerMounts | |
webui_logs_dir.mkdir(exist_ok=True, parents=True) | ||
|
||
container_webui_logs_dir = pathlib.Path("/") / "var" / "log" / component_name | ||
with open(settings_json_path, "r") as settings_json_file: | ||
meteor_settings = json.loads(settings_json_file.read()) | ||
|
||
# Read and update settings.json | ||
meteor_settings_updates = { | ||
"private": { | ||
"SqlDbHost": clp_config.database.host, | ||
|
@@ -726,7 +740,7 @@ def start_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPDockerMounts | |
"ClpStorageEngine": clp_config.package.storage_engine, | ||
}, | ||
} | ||
update_meteor_settings("", meteor_settings, meteor_settings_updates) | ||
meteor_settings = read_and_update_settings_json(settings_json_path, meteor_settings_updates) | ||
|
||
# Start container | ||
# fmt: off | ||
|
@@ -769,24 +783,43 @@ def start_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPDockerMounts | |
logger.info(f"Started {component_name}.") | ||
|
||
|
||
def start_log_viewer_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPDockerMounts): | ||
def start_log_viewer_webui( | ||
instance_id: str, | ||
clp_config: CLPConfig, | ||
container_clp_config: CLPConfig, | ||
mounts: CLPDockerMounts, | ||
): | ||
component_name = LOG_VIEWER_WEBUI_COMPONENT_NAME | ||
logger.info(f"Starting {component_name}...") | ||
|
||
container_name = f"clp-{component_name}-{instance_id}" | ||
if container_exists(container_name): | ||
return | ||
|
||
log_viewer_webui_logs_dir = clp_config.logs_directory / component_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add |
||
container_log_viewer_dir = CONTAINER_CLP_HOME / "var" / "www" / "log_viewer" | ||
node_path = str(container_log_viewer_dir / "server" / "node_modules") | ||
|
||
validate_log_viewer_config(clp_config, log_viewer_webui_logs_dir) | ||
|
||
# Create directories | ||
log_viewer_webui_logs_dir.mkdir(exist_ok=True, parents=True) | ||
container_log_viewer_webui_dir = CONTAINER_CLP_HOME / "var" / "www" / "log_viewer_webui" | ||
node_path = str(container_log_viewer_webui_dir / "server" / "node_modules") | ||
settings_json_path = ( | ||
get_clp_home() / "var" / "www" / "log_viewer_webui" / "server" / "settings.json" | ||
) | ||
|
||
container_log_viewer_webui_logs_dir = pathlib.Path("/") / "var" / "log" / component_name | ||
validate_log_viewer_webui_config(clp_config, settings_json_path) | ||
|
||
# Read, update, and write back settings.json | ||
settings_json_updates = { | ||
"SqlDbHost": clp_config.database.host, | ||
kirkrodrigues marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"SqlDbPort": clp_config.database.port, | ||
"SqlDbName": clp_config.database.name, | ||
"SqlDbQueryJobsTableName": QUERY_JOBS_TABLE_NAME, | ||
"MongoDbHost": clp_config.results_cache.host, | ||
"MongoDbPort": clp_config.results_cache.port, | ||
"MongoDbName": clp_config.results_cache.db_name, | ||
"MongoDbIrFilesCollectionName": clp_config.results_cache.ir_collection_name, | ||
"ClientDir": str(container_log_viewer_webui_dir / "client"), | ||
"IrFilesDir": str(container_clp_config.ir_output.directory), | ||
} | ||
settings_json = read_and_update_settings_json(settings_json_path, settings_json_updates) | ||
with open(settings_json_path, "w") as settings_json_file: | ||
settings_json_file.write(json.dumps(settings_json)) | ||
|
||
# Start container | ||
# fmt: off | ||
|
@@ -797,19 +830,17 @@ def start_log_viewer_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPD | |
"--name", container_name, | ||
"--log-driver", "local", | ||
"-e", f"NODE_PATH={node_path}", | ||
"-e", f"CLIENT_DIR={container_log_viewer_dir}/client/dist", | ||
"-e", f"PORT={clp_config.log_viewer_webui.port}", | ||
kirkrodrigues marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"-e", f"HOST={clp_config.log_viewer_webui.host}", | ||
"-e", f"PORT={clp_config.log_viewer_webui.port}", | ||
"-e", f"CLP_DB_USER={clp_config.database.username}", | ||
"-e", f"CLP_DB_PASS={clp_config.database.password}", | ||
"-e", f"NODE_ENV=production", | ||
"-u", f"{os.getuid()}:{os.getgid()}", | ||
] | ||
# fmt: on | ||
necessary_mounts = [ | ||
mounts.clp_home, | ||
mounts.ir_output_dir, | ||
DockerMount( | ||
DockerMountType.BIND, log_viewer_webui_logs_dir, container_log_viewer_webui_logs_dir | ||
), | ||
] | ||
for mount in necessary_mounts: | ||
if mount: | ||
|
@@ -819,7 +850,7 @@ def start_log_viewer_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPD | |
|
||
node_cmd = [ | ||
str(CONTAINER_CLP_HOME / "bin" / "node-22"), | ||
str(container_log_viewer_dir / "server" / "src" / "main.js"), | ||
str(container_log_viewer_webui_dir / "server" / "src" / "main.js"), | ||
] | ||
cmd = container_cmd + node_cmd | ||
subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True) | ||
|
@@ -1046,7 +1077,7 @@ def main(argv): | |
if target in (ALL_TARGET_NAME, WEBUI_COMPONENT_NAME): | ||
start_webui(instance_id, clp_config, mounts) | ||
if target in (ALL_TARGET_NAME, LOG_VIEWER_WEBUI_COMPONENT_NAME): | ||
start_log_viewer_webui(instance_id, clp_config, mounts) | ||
start_log_viewer_webui(instance_id, clp_config, container_clp_config, mounts) | ||
|
||
except Exception as ex: | ||
if type(ex) == ValueError: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
CLIENT_DIR=../client/dist | ||
IR_DATA_DIR=../../../build/clp-package/var/data/ir | ||
LOG_VIEWER_DIR=../yscope-log-viewer/dist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Henry8192 Kindly update here once your |
||
|
||
HOST=localhost | ||
PORT=3000 | ||
CLP_DB_USER=clp-user | ||
CLP_DB_PASS= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Local development | ||
.env.local | ||
|
||
# Testing | ||
/.tap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wonder, will the code still work if we first run npm clean-install in another directory and copy what's built into var/www/log_viewer_webui?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. However sometimes within node_modules there're symbolic links created during the node dependencies installation, so it's less ideal to copy an initialized node_modules.