示例#1
0
def test_get_counts_for_project_no_matching_keys(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:53:111", 0)

    counts = store.get_counts_for_project(42)
    assert list(counts) == []
示例#2
0
def test_projects_negative_timestamp(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:-111", 0)

    candidates = store.projects()
    assert list(candidates) == [42]
示例#3
0
def test_add_project_to_lpq_backing_off_adding(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set(f"{store._backoff_key_prefix()}:1", 1)

    added = store.add_project_to_lpq(1)
    assert not added
示例#4
0
def test_projects_mixed_buckets(store: RedisRealtimeMetricsStore,
                                redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:111", 0)
    redis_cluster.set("symbolicate_event_low_priority:counter:5:53:111", 0)

    candidates = store.projects()
    assert list(candidates) == [42]
示例#5
0
def test_remove_projects_from_lpq_backing_off_reremoving(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set(f"{store._backoff_key_prefix()}:1", 1)

    removed = store.remove_projects_from_lpq({1})
    assert not removed
示例#6
0
def test_get_counts_for_project_missing_project(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:53:111", 0)

    buckets = store.get_counts_for_project(project_id=42, timestamp=113)

    assert buckets.total_count() == 0
示例#7
0
def test_get_counts_for_project_different_bucket_sizes(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:110", 1)
    redis_cluster.set("symbolicate_event_low_priority:counter:5:42:110", 2)

    buckets = store.get_counts_for_project(project_id=42, timestamp=113)

    assert buckets.total_count() == 1
示例#8
0
def test_projects_multiple_metric_types(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:111", 0)
    redis_cluster.hset("symbolicate_event_low_priority:duration:10:53:111:20",
                       20, 456)

    candidates = store.projects()
    assert list(candidates) == [42, 53]
示例#9
0
def test_get_counts_for_project_negative_count(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:111", -10)

    counts = store.get_counts_for_project(42)
    assert list(counts) == [
        BucketedCount(timestamp=111, count=-10),
    ]
示例#10
0
def test_projects_empty(store: RedisRealtimeMetricsStore,
                        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set(
        "symbolicate_event_low_priority:counter:10:42:111",
        0,
    )
    redis_cluster.delete("symbolicate_event_low_priority:counter:10:42:111")

    candidates = store.projects()
    assert list(candidates) == []
示例#11
0
def test_get_counts_for_project_different_buckets(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:110", 0)
    redis_cluster.set("symbolicate_event_low_priority:counter:5:42:110", 0)

    counts = store.get_counts_for_project(42, 113)

    assert list(counts) == [
        BucketedCount(timestamp=110, count=0),
    ]
示例#12
0
def test_get_counts_for_project_empty(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set(
        "symbolicate_event_low_priority:counter:10:42:111",
        0,
    )
    redis_cluster.delete("symbolicate_event_low_priority:counter:10:42:111")

    counts = store.get_counts_for_project(42)
    assert list(counts) == []
示例#13
0
def test_get_durations_for_project_multi_metric(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:111", 0)
    redis_cluster.hset("symbolicate_event_low_priority:histogram:10:42:222", 0,
                       123)

    counts = store.get_durations_for_project(42)
    assert list(counts) == [
        DurationHistogram(timestamp=222, histogram=BucketedDurations({0: 123}))
    ]
示例#14
0
def test_get_counts_for_project_multi_metric(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:111", 0)
    redis_cluster.hset("symbolicate_event_low_priority:histogram:10:42:222:0",
                       0, 123)

    counts = store.get_counts_for_project(42)
    assert list(counts) == [
        BucketedCount(timestamp=111, count=0),
    ]
示例#15
0
def test_get_counts_for_projects_with_gap(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    store._counter_time_window = 40
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:110", 3)
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:150", 17)

    counts = store.get_counts_for_project(42, 154)

    assert list(counts) == [
        BucketedCount(timestamp=110, count=3),
        BucketedCount(timestamp=120, count=0),
        BucketedCount(timestamp=130, count=0),
        BucketedCount(timestamp=140, count=0),
        BucketedCount(timestamp=150, count=17),
    ]
示例#16
0
def test_get_counts_for_projects_with_gap(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    store._counter_time_window = 40
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:110", 3)
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:150", 17)

    buckets = store.get_counts_for_project(project_id=42, timestamp=154)

    assert buckets.total_count() == 20

    assert buckets.counts[-1] == 17
    assert buckets.counts[-2] == 0
    assert buckets.counts[-3] == 0
    assert buckets.counts[-4] == 0
    assert buckets.counts[-5] == 3
示例#17
0
def test_get_durations_for_project_multi_metric(
    store: RedisRealtimeMetricsStore,
    redis_cluster: redis._RedisCluster,
) -> None:
    redis_cluster.set("symbolicate_event_low_priority:counter:10:42:110", 0)
    redis_cluster.hset("symbolicate_event_low_priority:duration:10:42:220", 0,
                       123)

    histogram = empty_histogram()
    histogram[0] = 123

    durations = store.get_durations_for_project(42, 225)

    assert list(durations) == [
        DurationHistogram(timestamp=220,
                          histogram=BucketedDurations(histogram))
    ]
示例#18
0
def test_get_counts_for_project_empty(
        store: RedisRealtimeMetricsStore,
        redis_cluster: redis._RedisCluster) -> None:
    redis_cluster.set(
        "symbolicate_event_low_priority:counter:10:42:111",
        0,
    )
    redis_cluster.delete("symbolicate_event_low_priority:counter:10:42:111")

    counts = store.get_counts_for_project(42, 113)

    assert list(counts) == [BucketedCount(timestamp=110, count=0)]

    store._counter_time_window = 20

    counts = store.get_counts_for_project(42, 113)

    assert list(counts) == [
        BucketedCount(timestamp=90, count=0),
        BucketedCount(timestamp=100, count=0),
        BucketedCount(timestamp=110, count=0),
    ]