Skip to content

Commit

Permalink
Fix web app serviceLogs for raw deployment (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: lubingtan <lubingtan@bilibili.com>
Co-authored-by: lubingtan <lubingtan@bilibili.com>
  • Loading branch information
LuBingtan and lubingtan committed Mar 6, 2023
1 parent 4dc5b12 commit 50cc493
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/apps/common/routes/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def get_inference_service_logs(svc):
log.info(components)

# dictionary{component: [pod-names]}
component_pods_dict = utils.get_inference_service_pods(svc, components)
if svc["metadata"]["annotations"].get("serving.kubeflow.org/raw", "false") == "true":
component_pods_dict = utils.get_raw_inference_service_pods(svc, components)
else:
component_pods_dict = utils.get_inference_service_pods(svc, components)

if len(component_pods_dict.keys()) == 0:
return {}
Expand Down
25 changes: 25 additions & 0 deletions backend/apps/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ def load_inference_service_template(**kwargs):
"""
return helpers.load_param_yaml(INFERENCESERVICE_TEMPLATE_YAML, **kwargs)

# helper functions for accessing the logs of an InferenceService in raw kubernetes mode
def get_raw_inference_service_pods(svc, components=[]):
"""
Return a dictionary with (endpoint, component) keys
i.e. ("default", "predictor") and a list of pod names as values
"""
namespace = svc["metadata"]["namespace"]
svc_name = svc["metadata"]["name"]
label_selector = "serving.kubeflow.org/inferenceservice={}".format(svc_name)
pods = api.v1_core.list_namespaced_pod(namespace, label_selector=label_selector).items
component_pods_dict = {}
for pod in pods:
component = pod.metadata.labels.get("component", "")
if component not in components:
continue

curr_pod_names = component_pods_dict.get(component, [])
curr_pod_names.append(pod.metadata.name)
component_pods_dict[component] = curr_pod_names

if len(component_pods_dict.keys()) == 0:
log.info("No pods are found for inference service: %s",
svc["metadata"]["name"])

return component_pods_dict

# helper functions for accessing the logs of an InferenceService
def get_inference_service_pods(svc, components=[]):
Expand Down

0 comments on commit 50cc493

Please sign in to comment.