Beispiel #1
0
def excessive_event_rate(project_id: int, event_counts: BucketedCounts) -> bool:
    """Whether the project is sending too many symbolication requests."""
    total_rate = event_counts.rate(event_counts.TOTAL_PERIOD)
    recent_rate = event_counts.rate(period=60)

    # Note, We had these tagged with tags={"project_id": project_id} during our initial
    # evaluation, however the cardinality for this is really too high to leave that on
    # forever in production.
    metrics.gauge("symbolication.lpq.computation.rate.total", total_rate)
    metrics.gauge("symbolication.lpq.computation.rate.recent", recent_rate)

    if recent_rate > 50 and recent_rate > 5 * total_rate:
        return True
    else:
        return False
 def test_flatline(self) -> None:
     event_counts = BucketedCounts(timestamp=0, width=10, counts=[0] * 12)
     assert not excessive_event_rate(project_id=1, event_counts=event_counts)
 def test_high_rate_spike(self) -> None:
     # 0 events for 5m, then 500 events/10s for 1m
     # total event rate = 3600/360 = 10,
     # recent event rate = 3600/60 = 60 > 5 * total event rate
     event_counts = BucketedCounts(timestamp=0, width=10, counts=[0] * 30 + [600] * 6)
     assert excessive_event_rate(project_id=1, event_counts=event_counts)
 def test_low_rate_spike(self) -> None:
     # 0 events for 5m, then 5 events/10s for 1m
     # total event rate = 30/360 = 1/12,
     # recent event rate = 30/60 = 1/2 > 5 * total event rate
     event_counts = BucketedCounts(timestamp=0, width=10, counts=[0] * 30 + [5] * 6)
     assert not excessive_event_rate(project_id=1, event_counts=event_counts)
 def test_low_rate_no_spike(self) -> None:
     # 1 event/s for 2 minutes
     event_counts = BucketedCounts(timestamp=0, width=10, counts=[10] * 12)
     assert not excessive_event_rate(project_id=1, event_counts=event_counts)
Beispiel #6
0
 def test_rate_too_large_period(self, buckets: base.BucketedCounts) -> None:
     with pytest.raises(ValueError):
         buckets.rate(period=60)
Beispiel #7
0
 def test_rate(self, buckets: base.BucketedCounts) -> None:
     assert buckets.rate() == 6 / 30
     assert buckets.rate(period=10) == 3 / 10
Beispiel #8
0
 def test_total_count(self, buckets: base.BucketedCounts) -> None:
     assert buckets.total_count() == 6
Beispiel #9
0
 def test_total_time(self, buckets: base.BucketedCounts) -> None:
     assert buckets.total_time() == 30