示例#1
0
def test_tags_limit_indirect(mock_post):
    """
    Test for failure when too many tags are used indirectly (when combined with global tags)
    """
    gtags_list = [
        "gtk-%d:gtv-%d" % (i, i)
        for i in range(apptuit_client.MAX_TAGS_LIMIT // 2 + 1)
    ]
    global_tags = ",".join(gtags_list)
    tags = {
        'tagk-%d' % i: 'tagv-%d' % i
        for i in range(apptuit_client.MAX_TAGS_LIMIT // 2 + 1)
    }
    timestamp = int(time.time())
    with patch.dict(os.environ, {APPTUIT_PY_TAGS: global_tags}):
        client = Apptuit(sanitize_mode=None, token="test_token")
        point1 = DataPoint("metric1", {"tagk1": "tagv1"}, timestamp, 3.14)
        point2 = DataPoint("metric1", tags, timestamp, 3.14)
        with assert_raises(ValueError):
            client.send([point1, point2])

    with patch.dict(os.environ, {APPTUIT_PY_TAGS: global_tags}):
        client = Apptuit(sanitize_mode=None, token="test_token")
        series1 = TimeSeries('metric1', {"tagk1": "tagv1"})
        series1.add_point(timestamp, 3.14)
        series2 = TimeSeries('metric1', tags)
        series2.add_point(timestamp, 3.14)
        with assert_raises(ValueError):
            client.send_timeseries([series1, series2])
示例#2
0
def test_tags_limit_direct(mock_post):
    """
    Test for failure when too many tags are used for datapoints/series
    """
    tags = {
        'tagk-%d' % i: 'tagv-%d' % i
        for i in range(apptuit_client.MAX_TAGS_LIMIT + 1)
    }
    timestamp = int(time.time())
    client = Apptuit(sanitize_mode=None, token="test_token")
    point1 = DataPoint("metric1", {"tagk1": "tagv1"}, timestamp, 3.14)
    point2 = DataPoint("metric1", tags, timestamp, 3.14)
    with assert_raises(ValueError):
        client.send([point1, point2])
    series1 = TimeSeries('metric1', {"tagk1": "tagv1"})
    series1.add_point(timestamp, 3.14)
    series2 = TimeSeries('metric1', tags)
    series2.add_point(timestamp, 3.14)
    with assert_raises(ValueError):
        client.send_timeseries([series1, series2])