Esempio n. 1
0
def test_update_metrics__server_loaded(erddap_server_metrics, mocked_responses):
    status_page_html = _read_test_file('data/erddap_status_page.html')
    test_helper._stub_request(mocked_responses, status_page_html)

    erddap_server_metrics.update_metrics()

    metrics = erddap_server_metrics.get_metrics()

    # verify only one region
    for metric in metrics:
        assert ['testing'] == metric.label_values

    # check values
    _assert_value(metrics, 'erddap_server_status', 1)

    _assert_value(metrics, 'erddap_server_num_datasets', 2046)
    _assert_value(metrics, 'erddap_server_num_grid_datasets', 2)
    _assert_value(metrics, 'erddap_server_num_table_datasets', 2044)

    _assert_value(metrics, 'erddap_server_mins_since_last_refresh', 4)
    _assert_value(metrics, 'erddap_server_last_refresh_seconds', 5)
    _assert_value(metrics, 'erddap_server_num_failed_load_datasets', 6)

    _assert_value(metrics, 'erddap_server_num_recent_success_responses', 8389)
    _assert_value(metrics, 'erddap_server_num_recent_failed_responses', 1)
Esempio n. 2
0
def test_update_metrics__handles_error(erddap_server_metrics, mocked_responses):
    status_page_html = _read_test_file('data/erddap_status_page_502_error.html')
    test_helper._stub_request(mocked_responses, status_page_html)

    erddap_server_metrics.update_metrics()

    metrics = erddap_server_metrics.get_metrics()

    _assert_value(metrics, 'erddap_server_status', 0)

    # shouldn't set these gauges, since erddap is down
    _assert_value(metrics, 'erddap_server_num_datasets', None)
    _assert_value(metrics, 'erddap_server_num_failed_load_datasets', None)
    _assert_value(metrics, 'erddap_server_mins_since_last_refresh', None)
Esempio n. 3
0
def test_update_metrics__server_updating(erddap_server_metrics, mocked_responses):
    status_page_html = _read_test_file('data/erddap_status_page_updating.html')
    test_helper._stub_request(mocked_responses, status_page_html)

    erddap_server_metrics.update_metrics()

    metrics = erddap_server_metrics.get_metrics()

    _assert_value(metrics, 'erddap_server_status', 1)
    _assert_value(metrics, 'erddap_server_num_datasets', 546)

    # shouldn't set these gauges, since erddap is still updating
    _assert_value(metrics, 'erddap_server_mins_since_last_refresh', None)
    _assert_value(metrics, 'erddap_server_last_refresh_seconds', None)
Esempio n. 4
0
def test_converts_erddap_metrics_to_prom_gauges(erddap_server_metrics,
                                                mocked_responses):
    prom_metrics = PromMetrics(erddap_server_metrics)

    assert 0 == len(prom_metrics.gauges)

    # successfully initialized server
    status_page_html = _read_test_file('data/erddap_status_page.html')
    test_helper._stub_request(mocked_responses, status_page_html)
    erddap_server_metrics.update_metrics()

    prom_metrics.update_gauges()
    prom_metrics.update_gauges()

    gauges = prom_metrics.gauges

    assert 9 == len(gauges)
Esempio n. 5
0
def test_dataset_metrics_for_region(erddap_server_metrics, mocked_responses, mock_now_time):
    # http://erddap.cencoos.org/erddap/tabledap/allDatasets.csv?datasetID%2CmaxTime
    all_datasets_csv = _read_test_file('data/erddap_allDatasets_cencoos.csv')
    test_helper._stub_request(mocked_responses, all_datasets_csv)

    region = erddap_server_metrics.regions_list[0]

    metrics = erddap_server_metrics._dataset_metrics_for_region(region)

    # only 400 of the 1,285 have "realtime" data
    assert 396 == len(metrics)
    humboldt_metric = next(m for m in metrics
                           if m.label_names[1] == 'dataset_id' and m.label_values[1] == 'edu_humboldt_tdp')
    assert 'erddap_dataset_time_since_latest_data' == humboldt_metric.name
    assert 'Number of seconds since the latest available data point for this dataset' == humboldt_metric.help
    # last data pt: 2020-12-21T17:30:00Z
    # current time: 2020-12-21T18:41:00Z
    # 71 minutes / 4260 seconds
    assert 4260 == humboldt_metric.metric_value