src/watchdog/src/watchdog.py
def parse_pod_item(pod, pai_pod_gauge, pai_container_gauge, pai_job_pod_gauge, pods_info):
    """ add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod.
    Because we are parsing json outputed by k8s, its format is subjected to change,
    we should test if field exists before accessing it to avoid KeyError """

    pod_name = pod["metadata"]["name"]
    namespace = walk_json_field_safe(pod, "metadata", "namespace") or "default"
    host_ip = walk_json_field_safe(pod, "status", "hostIP") or "unscheduled"
    status = pod["status"]
    containers = walk_json_field_safe(pod, "spec", "containers")
    labels = pod["metadata"].get("labels")
    node_name = walk_json_field_safe(pod, "spec", "nodeName")

    service_name = walk_json_field_safe(labels, "app")
    job_name = walk_json_field_safe(labels, "jobName")
    if service_name is None and job_name is None:
        logger.info("unknown pod %s", pod_name)
        return None

    generate_pods_info(pod_name, containers, host_ip, pods_info)
    generate_pod_metrics(pai_pod_gauge, pai_job_pod_gauge, service_name,
                         job_name, pod_name, node_name, host_ip, status, namespace)

    # generate pai_containers
    if service_name is not None and status.get("containerStatuses") is not None:
        container_statuses = status["containerStatuses"]
        generate_container_metrics(
            pai_container_gauge, service_name, pod_name, container_statuses, namespace, host_ip)
 add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod.
    Because we are parsing json outputed by k8s, its format is subjected to change,
    we should test if field exists before accessing it to avoid KeyError 
add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod.
Because we are parsing json outputed by k8s, its format is subjected to change,
we should test if field exists before accessing it to avoid KeyError
add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod . Because we are parsing json outputed by k8s its format is subjected to change we should test if field exists before accessing it to avoid KeyError
def parse_pod_item(pod, pai_pod_gauge, pai_container_gauge, pai_job_pod_gauge, pods_info):
    pod_name = pod["metadata"]["name"]
    namespace = walk_json_field_safe(pod, "metadata", "namespace") or "default"
    host_ip = walk_json_field_safe(pod, "status", "hostIP") or "unscheduled"
    status = pod["status"]
    containers = walk_json_field_safe(pod, "spec", "containers")
    labels = pod["metadata"].get("labels")
    node_name = walk_json_field_safe(pod, "spec", "nodeName")
    service_name = walk_json_field_safe(labels, "app")
    job_name = walk_json_field_safe(labels, "jobName")
    if service_name is None and job_name is None:
        logger.info("unknown pod %s", pod_name)
        return None
    generate_pods_info(pod_name, containers, host_ip, pods_info)
    generate_pod_metrics(pai_pod_gauge, pai_job_pod_gauge, service_name,
                         job_name, pod_name, node_name, host_ip, status, namespace)
    if service_name is not None and status.get("containerStatuses") is not None:
        container_statuses = status["containerStatuses"]
        generate_container_metrics(
            pai_container_gauge, service_name, pod_name, container_statuses, namespace, host_ip)
def parse_pod_item ( pod , pai_pod_gauge , pai_container_gauge , pai_job_pod_gauge , pods_info ) : pod_name = pod [ "metadata" ] [ "name" ] namespace = walk_json_field_safe ( pod , "metadata" , "namespace" ) or "default" host_ip = walk_json_field_safe ( pod , "status" , "hostIP" ) or "unscheduled" status = pod [ "status" ] containers = walk_json_field_safe ( pod , "spec" , "containers" ) labels = pod [ "metadata" ] . get ( "labels" ) node_name = walk_json_field_safe ( pod , "spec" , "nodeName" ) service_name = walk_json_field_safe ( labels , "app" ) job_name = walk_json_field_safe ( labels , "jobName" ) if service_name is None and job_name is None : logger . info ( "unknown pod %s" , pod_name ) return None generate_pods_info ( pod_name , containers , host_ip , pods_info ) generate_pod_metrics ( pai_pod_gauge , pai_job_pod_gauge , service_name , job_name , pod_name , node_name , host_ip , status , namespace ) if service_name is not None and status . get ( "containerStatuses" ) is not None : container_statuses = status [ "containerStatuses" ] generate_container_metrics ( pai_container_gauge , service_name , pod_name , container_statuses , namespace , host_ip )
add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod.
add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod .
""" add metrics to pai_pod_gauge or pai_container_gauge if successfully parse pod.
    Because we are parsing json outputed by k8s, its format is subjected to change,
    we should test if field exists before accessing it to avoid KeyError """ # generate pai_containers
pod
pai_pod_gauge
pai_container_gauge
pai_job_pod_gauge
pods_info