TestInstanceLimits verifies MaxBytesPerTrace and MaxLocalTracesPerUser enforcement in livestore.
(t *testing.T)
| 48 | |
| 49 | // TestInstanceLimits verifies MaxBytesPerTrace and MaxLocalTracesPerUser enforcement in livestore. |
| 50 | func TestInstanceLimits(t *testing.T) { |
| 51 | const batches = 20 |
| 52 | // Configure limits: allow up to ~1.5x small trace, and max 4 live traces |
| 53 | maxTraces := 4 |
| 54 | |
| 55 | batch1 := test.MakeTrace(batches, test.ValidTraceID(nil)) |
| 56 | batch2 := test.MakeTrace(batches, test.ValidTraceID(nil)) |
| 57 | maxBytes := batch1.Size() + batch2.Size()/2 // set limit between 1 and 2 batches so pushing both batches to a single trace exceeds limit |
| 58 | |
| 59 | // bytes - succeeds: push two different traces under size limit |
| 60 | t.Run("bytes - succeeds", func(t *testing.T) { |
| 61 | instance, ls := instanceWithPushLimits(t, maxBytes, maxTraces) |
| 62 | // two different traces with different ids |
| 63 | id1 := test.ValidTraceID(nil) |
| 64 | id2 := test.ValidTraceID(nil) |
| 65 | pushTrace(t.Context(), t, instance, batch1, id1) |
| 66 | pushTrace(t.Context(), t, instance, batch2, id2) |
| 67 | require.Equal(t, uint64(2), instance.liveTraces.Len()) |
| 68 | |
| 69 | err := services.StopAndAwaitTerminated(t.Context(), ls) |
| 70 | require.NoError(t, err) |
| 71 | }) |
| 72 | |
| 73 | // bytes - one fails: second push of the same trace exceeds MaxBytesPerTrace |
| 74 | t.Run("bytes - one fails", func(t *testing.T) { |
| 75 | instance, ls := instanceWithPushLimits(t, maxBytes, maxTraces) |
| 76 | |
| 77 | id := test.ValidTraceID(nil) |
| 78 | // First push fits |
| 79 | pushTrace(t.Context(), t, instance, batch1, id) |
| 80 | // Second push with same id will exceed combined size (> maxBytes) |
| 81 | pushTrace(t.Context(), t, instance, batch2, id) |
| 82 | // Only one live trace stored, and accumulated size should be <= maxBytes |
| 83 | require.Equal(t, uint64(1), instance.liveTraces.Len()) |
| 84 | require.LessOrEqual(t, instance.liveTraces.Size(), uint64(maxBytes)) |
| 85 | |
| 86 | err := services.StopAndAwaitTerminated(t.Context(), ls) |
| 87 | require.NoError(t, err) |
| 88 | }) |
| 89 | |
| 90 | // bytes - second push fails even after cutIdleTraces |
| 91 | t.Run("bytes - second push fails even after cutIdleTraces", func(t *testing.T) { |
| 92 | instance, ls := instanceWithPushLimits(t, maxBytes, maxTraces) |
| 93 | |
| 94 | id := test.ValidTraceID(nil) |
| 95 | // First push fits |
| 96 | pushTrace(t.Context(), t, instance, batch1, id) |
| 97 | |
| 98 | // cut idle traces but we retain the too large trace in traceSizes |
| 99 | drained, err := instance.cutIdleTraces(t.Context(), true) |
| 100 | require.NoError(t, err) |
| 101 | require.True(t, drained, "should drain live traces in one iteration") |
| 102 | |
| 103 | // Second push with same id will fail b/c we are still tracking in traceSizes |
| 104 | pushTrace(t.Context(), t, instance, batch2, id) |
| 105 | require.Equal(t, uint64(0), instance.liveTraces.Len()) |
| 106 | require.Equal(t, instance.liveTraces.Size(), uint64(0)) |
| 107 |
nothing calls this directly
no test coverage detected