import jmespath


def fetch_metric(metrics, mapping):
    """
    Given a dictionary of metrics and a single mapping, fetch the required metric
    from the dictionary. Return a key-value tuple. Return None for the value if the
    metric cannot be found.
    """
    key = mapping["key"]

    if "path" in mapping:
        raw_value = jmespath.compile(mapping['path']).search(metrics)
    elif key in metrics:
        raw_value = metrics[key]
    else:
        raw_value = None

    return (key, raw_value)