def __get_timer_unit()

in lib/src/klio/transforms/decorators.py [0:0]


def __get_timer_unit(metrics_conf):
    default_unit = "s"  # seconds

    # Maybe if someone set `metrics: False` - but not sure if that'd happen?
    if not isinstance(metrics_conf, dict):
        return default_unit

    logger_unit, native_unit, shumway_unit = None, None, None

    timer_unit = metrics_conf.get("timer_unit")

    logger_conf = metrics_conf.get("logger", {})
    if isinstance(logger_conf, dict):
        logger_unit = logger_conf.get("timer_unit")
    native_conf = metrics_conf.get("native", {})
    if isinstance(native_conf, dict):
        native_unit = native_conf.get("timer_unit")
    shumway_conf = metrics_conf.get("shumway", {})
    if isinstance(shumway_conf, dict):
        shumway_unit = shumway_conf.get("timer_unit")

    timer_unit = (
        timer_unit
        or native_unit
        or shumway_unit
        or logger_unit
        or default_unit
    )
    return timer_unit