Esempio n. 1
0
def test_prometheus_data_load(basic_query_01, empty_result,
                              error_result) -> None:
    x = prometheus.PrometheusData(basic_query_01)
    assert x.is_success()
    assert len(x.raw['data']['result']) == 1
    assert len(x.raw['data']['result'][0]['values']) == 19
    assert x.raw['data']['result'][0]['metric']['__name__'] == 'cnt_cpu_perc'
    cnt_id = '93a02b23a465d63c3865ed421a437365c464b86e4018f229ee0f91602826b453'
    assert len(x.get_metric_values('cnt_cpu_perc', cnt_id)['values']) == 19
    assert len(x._by_id) == 1
    assert len(x._by_metric_name) == 1
    assert len(x._by_id[cnt_id]) == 1
    assert len(x._by_id[cnt_id][0]['values']) == 19
    v = x._by_id[cnt_id][0]['values'][0]
    assert type(v[1]) == float
    assert 'job' in x.get_metric_values('cnt_cpu_perc', cnt_id)['metric']
    assert 'name' not in x.get_metric_values('cnt_cpu_perc', cnt_id)['metric']
    x = prometheus.PrometheusData(empty_result)
    assert x.is_success()
    assert x.raw['data']['result'] == []
    assert len(x._by_id) == 0
    assert len(x._by_metric_name) == 0
    x = prometheus.PrometheusData(error_result)
    assert not x.is_success()
    assert len(x._by_id) == 0
    assert len(x._by_metric_name) == 0
Esempio n. 2
0
def test_prometheus_data_medium_emu_load(
        empty_vnf1_sonemu_rx_count_packets) -> None:
    x = prometheus.PrometheusData(empty_vnf1_sonemu_rx_count_packets)
    assert x.is_success()
    metrics = x._by_metric_name['sonemu_rx_count_packets']
    print(metrics)
    assert(len(metrics['empty_vnf1']['values']) == 10800)
def test_add_metric_entry(basic_query_01) -> None:
    x = prometheus.PrometheusData(basic_query_01)
    base_entry = x.raw['data']['result'][0]
    new_entry = copy.deepcopy(base_entry)
    new_entry['metric']['__name__'] = 'foobar'
    x.add_entry(new_entry)
    assert len(x.raw['data']['result']) == 2
    assert x.raw['data']['result'][0]['metric']['__name__'] == 'cnt_cpu_perc'
    assert x.raw['data']['result'][1]['metric']['__name__'] == 'foobar'
Esempio n. 4
0
def test_prometheus_data_medium_cnt_load(
        mn_empty_vnf1_container_memory_usage_bytes) -> None:
    x = prometheus.PrometheusData(mn_empty_vnf1_container_memory_usage_bytes)
    assert x.is_success()
    metrics = x.get_metric_values('container_memory_usage_bytes',
                                  ('/docker/e03820a994ddb0322d1'
                                   '8f1e5bac2a84bb56de08559492a'
                                   '7858332f0386193766'))
    assert metrics['metric']['name'] == 'mn.empty_vnf1'
    assert metrics['metric']['vnf_name'] == 'empty_vnf1'
    assert(len(metrics['values']) == 10800)
def test_build_sonata_df(basic_query_01):
    x = prometheus.PrometheusData(basic_query_01)
    base_entry = x.raw['data']['result'][0]
    new_entry1 = copy.deepcopy(base_entry)
    new_entry1['metric']['__name__'] = 'uno'
    x.add_entry(new_entry1)
    new_entry2 = copy.deepcopy(base_entry)
    new_entry2['metric']['__name__'] = 'bis'
    new_entry2['values'] = [(i[0], 20 + i[1]) for i in new_entry2['values']]
    x.add_entry(new_entry2)
    new_entry3 = copy.deepcopy(base_entry)
    new_entry3['metric']['__name__'] = 'ter'

    def trans(t):  # pylint: disable=missing-docstring,invalid-name
        d = hl.convert_timestamp_to_posix(t[0])
        d = d + datetime.timedelta(0, 1)
        return (d.timestamp(), 30 + t[1])

    new_entry3['values'] = [trans(i) for i in new_entry3['values']]
    x.add_entry(new_entry3)
    hl.build_sonata_df_by_id(x)