def get_service_and_method_from_url(method_url):
    """Extract service and method names from the method url string.

    Returns strings that are applicable as prometheus metrics and/or labels.

    Args:
        method_url: string

    Returns:
        tuple(service_name, method_name)
    """
    name_parts = method_url.split("/")
    if len(name_parts) != 3 or name_parts[0] != "" or name_parts[1] == "" or name_parts[2] == "":
        raise AssertionError("Invalid method name: {}".format(method_url))

    return (name_parts[1].replace(".", "_"), name_parts[2].replace(".", "_"))