@flaky
def test_custom_metric(cloud_config):
    PROJECT_RESOURCE = "projects/{}".format(cloud_config.project)
    client = list_resources.get_client()
    # Use a constant seed so psuedo random number is known ahead of time
    random.seed(1)
    pseudo_random_value = random.randint(0, 10)
    # Reseed it
    random.seed(1)

    INSTANCE_ID = "test_instance"
    METRIC_KIND = "GAUGE"

    create_custom_metric(
        client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
    custom_metric = None
    # wait until metric has been created, use the get call to wait until
    # a response comes back with the new metric
    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)
    # Sometimes on new metric descriptors, writes have a delay in being
    # read back. 3 seconds should be enough to make sure our read call
    # picks up the write
    time.sleep(3)
    response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
    value = int(
        response['timeSeries'][0]['points'][0]['value']['int64Value'])
    # using seed of 1 will create a value of 1
    assert value == pseudo_random_value
dataset/ETHPy150Open GoogleCloudPlatform/python-docs-samples/monitoring/api/v3/custom_metric_test.py/test_custom_metric/original