예제 #1
0
def test_kpi_basic():
    test_cycle = _get_curr_test_cycle()
    print("KPI-TEST: {}".format(test_cycle))
    sec_now = int(time.time())
    sec_4h_ago = sec_now - (3600 * 4)
    kpi_window_start = sec_4h_ago
    val = 3.56
    nr_kpi_point = 10
    kpi_name = "test-kpi-1"
    kpi_window_end = kpi_window_start
    for i in range(nr_kpi_point):
        mlops.set_kpi(kpi_name, val, kpi_window_end, KpiValue.TIME_SEC)
        kpi_window_end += 1
        val += 1

    time.sleep(10)

    kpi_datetime_start = datetime.utcfromtimestamp(kpi_window_start)
    kpi_datetime_end = datetime.utcfromtimestamp(kpi_window_end)

    print("datetime start: {}".format(kpi_datetime_start))
    print("datetime end:   {}".format(kpi_datetime_end))

    df = mlops.get_kpi(name=kpi_name,
                       start_time=kpi_datetime_start,
                       end_time=kpi_datetime_end)
    print(df)
    if len(df) != nr_kpi_point:
        raise Exception("Got: {} kpi points, expecting: {}".format(
            len(df), nr_kpi_point))
예제 #2
0
def process_kpi_line(kpi_line):
    parts = re.split("\s*,\s*", kpi_line)
    if len(parts) < 3:
        raise Exception(
            "KPI line is expected to have at least 3 parts: name, timestamp, value"
        )

    kpi_name = parts[0]
    kpi_ts = parts[1]
    kpi_value = parts[2]
    try:
        kpi_value = float(kpi_value)
    except Exception as e:
        print("Error converting kpi_value to float")
        raise e

    print("detected KPI: name: [{}] timestamp: [{}] value: [{}]".format(
        kpi_name, kpi_ts, kpi_value))
    pm.set_kpi(kpi_name, kpi_value, kpi_ts, KpiValue.TIME_SEC)
예제 #3
0
def test_kpi_api():
    pm.init(ctx=None, mlops_mode=MLOpsMode.STAND_ALONE)
    pm._set_api_test_mode()

    with pytest.raises(MLOpsException):
        ts = time.time()
        pm.set_kpi(None, 5.5, ts, KpiValue.TIME_NSEC)

    with pytest.raises(MLOpsException):
        ts = time.time()
        pm.set_kpi("user-kpi-1", ["1"], ts, KpiValue.TIME_SEC)

    with pytest.raises(MLOpsException):
        ts = time.time()
        pm.set_kpi("user-kpi-1", 5.5, ts, "no-such-time-unit")

    with pytest.raises(MLOpsException):
        pm.get_kpi("user-kpi-1", None, None)

    now = datetime.utcnow()
    last_hour = (now - timedelta(hours=1))

    pm.get_kpi("user-kpi-1", last_hour, now)
    pm.done()