

@flaky
def test_custom_metric(cloud_config):
    PROJECT_RESOURCE = 'projects/{}'.format(cloud_config.project)
    client = list_resources.get_client()
    random.seed(1)
    pseudo_random_value = random.randint(0, 10)
    random.seed(1)
    INSTANCE_ID = 'test_instance'
    METRIC_KIND = 'GAUGE'
    create_custom_metric(client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
    custom_metric = None
    while (not custom_metric):
        time.sleep(1)
        custom_metric = get_custom_metric(client, PROJECT_RESOURCE, METRIC_RESOURCE)
    write_timeseries_value(client, PROJECT_RESOURCE, METRIC_RESOURCE, INSTANCE_ID, METRIC_KIND)
    time.sleep(3)
    response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
    value = int(response['timeSeries'][0]['points'][0]['value']['int64Value'])
    assert (value == pseudo_random_value)

dataset/ETHPy150Open GoogleCloudPlatform/python-docs-samples/monitoring/api/v3/custom_metric_test.py test_custom_metric/original