Exemplo n.º 1
0
def test_ion_structure():

    print("MyION = {}".format(mlops.get_mlapp_id()))
    print("Nodes:")
    for n in mlops.get_nodes():
        print(n)
    print("\n\n")
    # Getting the ION component object

    curr_node = mlops.get_current_node()
    curr_node_2 = mlops.get_node(curr_node.name)
    if curr_node_2 is None:
        raise Exception("Expecting {} node to exist in this ION".format(
            curr_node.name))
    print("C0:\n{}".format(curr_node))

    assert curr_node.name == curr_node_2.name

    # Getting the first agent of ion component "0"
    print("Getting node {} agents type of arg:{}".format(
        curr_node.name, type(curr_node.name)))

    agent_list = mlops.get_agents(curr_node.name)

    if len(agent_list) == 0:
        print("Error - must have agents this ion node is running on")
        raise Exception("Agent list is empty")

    for agent in agent_list:
        if agent is None:
            raise Exception("Agent object obtained is None")
        print("Agent: {}".format(agent))
Exemplo n.º 2
0
def test_mlops_structure_api():
    ion_instance_id = ION1.ION_INSTANCE_ID
    ion_node_id = ION1.NODE_1_ID
    token = ION1.TOKEN

    set_mlops_env(ion_id=ion_instance_id,
                  ion_node_id=ion_node_id,
                  token=token,
                  model_id=ION1.MODEL_ID)
    rest_helper = MlOpsRestFactory().get_rest_helper(MLOpsMode.AGENT,
                                                     mlops_server="localhost",
                                                     mlops_port="3456",
                                                     token=token)

    rest_helper.set_prefix(Constants.URL_MLOPS_PREFIX)
    with requests_mock.mock() as m:
        m.get(rest_helper.url_get_workflow_instance(ion_instance_id),
              json=test_workflow_instances)
        m.get(rest_helper.url_get_ees(), json=test_ee_info)
        m.get(rest_helper.url_get_agents(), json=test_agents_info)
        m.get(rest_helper.url_get_model_list(), json=test_models_info)
        m.get(rest_helper.url_get_health_thresholds(ion_instance_id),
              json=test_health_info)
        m.get(rest_helper.url_get_model_stats(ION1.MODEL_ID),
              json=test_model_stats)
        m.get(rest_helper.url_get_uuid("model"),
              json={"id": "model_5906255e-0a3d-4fef-8653-8d41911264fb"})

        pm.init(ctx=None, mlops_mode=MLOpsMode.AGENT)
        assert pm.get_mlapp_id() == ION1.ION_ID
        assert pm.get_mlapp_name() == ION1.ION_NAME

        curr_node = pm.get_current_node()
        assert curr_node.id == ion_node_id

        nodes = pm.get_nodes()
        assert len(nodes) == 2

        node0 = pm.get_node('1')
        assert node0 is not None
        assert node0.pipeline_pattern_id == ION1.PIPELINE_PATTERN_ID_1
        assert node0.pipeline_instance_id == ION1.PIPELINE_INST_ID_1

        node0_agents = pm.get_agents('1')
        assert len(node0_agents) == 1
        assert node0_agents[0].id == ION1.AGENT_ID_0
        assert node0_agents[0].hostname == 'localhost'

        agent = pm.get_agent('1', ION1.AGENT_ID_0)
        assert agent.id == ION1.AGENT_ID_0
        assert agent.hostname == 'localhost'

        model = pm.current_model()
        assert model is not None
        assert model.metadata.modelId == ION1.MODEL_ID

        pm.done()
Exemplo n.º 3
0
def test_attach():

    mlapp_id = "144a045d-c927-4afb-a85c-5224bd68f1bb"

    ion_instance_id = ION1.ION_INSTANCE_ID
    ion_node_id = ION1.NODE_1_ID
    token = ION1.TOKEN

    set_mlops_env(ion_id=ion_instance_id,
                  ion_node_id=ion_node_id,
                  token=token,
                  model_id=ION1.MODEL_ID)
    rest_helper = MlOpsRestFactory().get_rest_helper(MLOpsMode.AGENT,
                                                     mlops_server="localhost",
                                                     mlops_port="3456",
                                                     token=token)

    with requests_mock.mock() as m:
        m.get(rest_helper.url_get_workflow_instance(ion_instance_id),
              json=test_workflow_instances)
        m.get(rest_helper.url_get_ees(), json=test_ee_info)
        m.get(rest_helper.url_get_agents(), json=test_agents_info)
        m.get(rest_helper.url_get_model_list(), json=test_models_info)
        m.get(rest_helper.url_get_health_thresholds(ion_instance_id),
              json=test_health_info)
        m.get(rest_helper.url_get_model_stats(ION1.MODEL_ID),
              json=test_model_stats)
        m.get(rest_helper.url_get_uuid("model"),
              json={"id": "model_5906255e-0a3d-4fef-8653-8d41911264fb"})
        m.post(rest_helper.url_login(), json={"token": token})

        pm.attach(mlapp_id=ION1.ION_INSTANCE_ID,
                  mlops_server="localhost",
                  mlops_port=3456,
                  password="******")
        mlapp_id_ret = pm.get_mlapp_id()
        assert (mlapp_id_ret == ION1.ION_ID)

        mlapp_policy_ret = pm.get_mlapp_policy()
        assert (str(mlapp_policy_ret) ==
                "Policy:\nhealthThreshold: 0.2\ncanaryThreshold: 0.5\n")
        pm.done()
Exemplo n.º 4
0
def test_stats_basic():
    now = datetime.utcnow()
    last_hour = (now - timedelta(hours=1))

    df = mlops.get_stats("non-existing-stat__AAA",
                         mlapp_node=None,
                         agent=None,
                         start_time=last_hour,
                         end_time=now)

    assert len(df) == 0

    # Adding multiple points (to see a graph in the ui), expecting each run to generate 8 points
    mlops.set_stat("stat1", 1.0)
    mlops.set_stat("stat1", 3.0)
    mlops.set_stat("stat1", 4.0)
    mlops.set_stat("stat1", 5.0)
    mlops.set_stat("stat1", 6.0)
    mlops.set_stat("stat1", 2.0)
    mlops.set_stat("stat1", 7.0)
    mlops.set_stat("stat1", 8.0)

    print("Done reporting statistics")
    time.sleep(10)

    print("MyION = {}".format(mlops.get_mlapp_id()))

    print("Hour before: {}".format(last_hour))
    print("Now:         {}".format(now))

    agent_list = _get_my_agents()

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

    # A test for a big time window
    df = mlops.get_stats(name="stat1",
                         mlapp_node=mlops.get_current_node().name,
                         agent=agent_list[0].id,
                         start_time=last_day,
                         end_time=now)

    assert len(df) >= 8, "Got: {} lines in df, expecting at least: {}".format(
        len(df), 8)

    df = mlops.get_stats(name="stat1",
                         mlapp_node=mlops.get_current_node().name,
                         agent=agent_list[0].id,
                         start_time=last_hour,
                         end_time=now)

    assert len(df) >= 8, "Got: {} lines in df, expecting at least: {}".format(
        len(df), 8)
    print("Got stat1 statistic\n", df)

    # Another check with the agent object
    df = mlops.get_stats(name="stat1",
                         mlapp_node=mlops.get_current_node().name,
                         agent=agent_list[0],
                         start_time=last_hour,
                         end_time=now)
    print("Got stat1 statistic_2\n", df)

    # Another with node equal to none and agent equal to none
    df = mlops.get_stats(name="stat1",
                         mlapp_node=None,
                         agent=None,
                         start_time=last_hour,
                         end_time=now)
    print("Got stat1 statistic_3\n", df)
    nodes_in_stats = df["node"].tolist()
    if len(nodes_in_stats) > 8:
        print("case_with_stats_from_2_nodes")
        set_nodes = set(nodes_in_stats)
        assert len(set_nodes) > 1