Skip to content
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

Add error log sending to master template and add provisioning configuration #3138

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nvflare/lighter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PropKey:
OVERSEER_END_POINT = "overseer_end_point"
ADMIN_PORT = "admin_port"
FED_LEARN_PORT = "fed_learn_port"
ALLOW_ERROR_SENDING = "allow_error_sending"


class CtxKey(WorkDir, PropKey):
Expand Down
27 changes: 26 additions & 1 deletion nvflare/lighter/ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,33 @@ def yaml_load_template_section(self, section_key: str):
def json_load_template_section(self, section_key: str):
return json.loads(self.get_template_section(section_key))

def build_from_template(self, dest_dir: str, temp_section: str, file_name, replacement=None, mode="t", exe=False):
def build_from_template(
self,
dest_dir: str,
temp_section: str,
file_name,
replacement=None,
mode="t",
exe=False,
content_modify_cb=None,
**cb_kwargs,
):
"""Build a file from a template section and writes it to the specified location.
Args:
dest_dir: destination directory
temp_section: template section key
file_name: file name
replacement: replacement dict
mode: file mode
exe: executable
content_modify_cb: content modification callback, can be included to take the section content as the first argument and return the modified content
cb_kwargs: additional keyword arguments for the callback
"""
section = self.get_template_section(temp_section)
if replacement:
section = utils.sh_replace(section, replacement)
if content_modify_cb:
section = content_modify_cb(section, **cb_kwargs)
nvkevlu marked this conversation as resolved.
Show resolved Hide resolved
nvkevlu marked this conversation as resolved.
Show resolved Hide resolved
utils.write(os.path.join(dest_dir, file_name), section, mode, exe=exe)
18 changes: 17 additions & 1 deletion nvflare/lighter/impl/static_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ def _build_client(self, client, ctx):
ctx.build_from_template(dest_dir, TemplateSectionKey.LOG_CONFIG, ProvFileName.LOG_CONFIG_DEFAULT)

ctx.build_from_template(
dest_dir, TemplateSectionKey.LOCAL_CLIENT_RESOURCES, ProvFileName.RESOURCES_JSON_DEFAULT
dest_dir,
TemplateSectionKey.LOCAL_CLIENT_RESOURCES,
ProvFileName.RESOURCES_JSON_DEFAULT,
content_modify_cb=self._modify_error_sender,
client=client,
)

ctx.build_from_template(
Expand All @@ -233,6 +237,18 @@ def _build_client(self, client, ctx):
dest_dir = ctx.get_ws_dir(client)
ctx.build_from_template(dest_dir, TemplateSectionKey.CLIENT_README, ProvFileName.README_TXT)

def _modify_error_sender(self, section: dict, client: Participant):
allow = client.get_prop_fb(PropKey.ALLOW_ERROR_SENDING, False)
if not allow:
components = section.get("components")
assert isinstance(components, list)
for c in components:
if c["id"] == "error_log_sender":
components.remove(c)
break

return section

@staticmethod
def _check_host_name(host_name: str, server: Participant) -> str:
if host_name == server.get_default_host():
Expand Down
14 changes: 12 additions & 2 deletions nvflare/lighter/templates/master_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ local_client_resources: |
"id": "process_launcher",
"path": "nvflare.app_common.job_launcher.client_process_launcher.ClientProcessJobLauncher",
"args": {}
}
},
{
"id": "error_log_sender",
"path": "nvflare.app_common.logging.log_sender.ErrorLogSender",
"args": {}
},
]
}

Expand Down Expand Up @@ -226,7 +231,12 @@ local_server_resources: |
"id": "process_launcher",
"path": "nvflare.app_common.job_launcher.server_process_launcher.ServerProcessJobLauncher",
"args": {}
}
},
{
"id": "log_receiver",
"path": "nvflare.app_common.logging.log_receiver.LogReceiver",
"args": {}
},
]
}

Expand Down
Loading