|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/onsi/ginkgo/v2" |
| 9 | + "github.com/onsi/gomega" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + queryRequestQueue = "query-request-sortedset" |
| 14 | + queryResultQueue = "query-result-list" |
| 15 | +) |
| 16 | + |
| 17 | +// The prometheus-query gate evaluates an arbitrary PromQL expression as the |
| 18 | +// dispatch budget. The e2e Helm values configure it with the same saturation |
| 19 | +// metric used by the saturation gate tests: |
| 20 | +// |
| 21 | +// 1 - inference_extension_flow_control_pool_saturation{inference_pool="e2e-pool"} |
| 22 | +// |
| 23 | +// Because threshold=0 the raw PromQL result is used directly as the budget. |
| 24 | +var _ = ginkgo.Describe("Prometheus Query Dispatch Gate E2E", ginkgo.Ordered, func() { |
| 25 | + var ctx context.Context |
| 26 | + |
| 27 | + ginkgo.BeforeAll(func() { |
| 28 | + redeployEPPWithFlowControl() |
| 29 | + }) |
| 30 | + |
| 31 | + ginkgo.BeforeEach(func() { |
| 32 | + ctx = context.Background() |
| 33 | + rdb.Del(ctx, queryRequestQueue) //nolint:errcheck |
| 34 | + rdb.Del(ctx, queryResultQueue) //nolint:errcheck |
| 35 | + setSimWaitingRequests(simAdminURL, 0) |
| 36 | + }) |
| 37 | + |
| 38 | + ginkgo.It("processes a message when the query returns a positive budget", func() { |
| 39 | + setSimWaitingRequests(simAdminURL, 0) |
| 40 | + |
| 41 | + waitForSaturation(promURL, envoyURL, func(v float64) bool { return v < 0.5 }) |
| 42 | + |
| 43 | + msg := makeRequestMessage("query-positive", 5*time.Minute) |
| 44 | + enqueueMessage(ctx, rdb, queryRequestQueue, msg) |
| 45 | + |
| 46 | + gomega.Eventually(func() int64 { |
| 47 | + return getResultCount(ctx, rdb, queryResultQueue) |
| 48 | + }, 60*time.Second, 1*time.Second).Should(gomega.BeNumerically(">=", 1)) |
| 49 | + |
| 50 | + result := popResult(ctx, rdb, queryResultQueue) |
| 51 | + gomega.Expect(result).NotTo(gomega.BeNil()) |
| 52 | + gomega.Expect(result.ID).To(gomega.Equal("query-positive")) |
| 53 | + }) |
| 54 | + |
| 55 | + ginkgo.It("pauses processing when the query returns zero budget", func() { |
| 56 | + setSimWaitingRequests(simAdminURL, 10) |
| 57 | + |
| 58 | + waitForSaturation(promURL, envoyURL, func(v float64) bool { return v >= 0.7 }) |
| 59 | + |
| 60 | + msg := makeRequestMessage("query-blocked", 5*time.Minute) |
| 61 | + enqueueMessage(ctx, rdb, queryRequestQueue, msg) |
| 62 | + |
| 63 | + gomega.Consistently(func() int64 { |
| 64 | + return getResultCount(ctx, rdb, queryResultQueue) |
| 65 | + }, 10*time.Second, 1*time.Second).Should(gomega.Equal(int64(0))) |
| 66 | + |
| 67 | + setSimWaitingRequests(simAdminURL, 0) |
| 68 | + |
| 69 | + gomega.Eventually(func() int64 { |
| 70 | + return getResultCount(ctx, rdb, queryResultQueue) |
| 71 | + }, 60*time.Second, 1*time.Second).Should(gomega.BeNumerically(">=", 1)) |
| 72 | + |
| 73 | + result := popResult(ctx, rdb, queryResultQueue) |
| 74 | + gomega.Expect(result).NotTo(gomega.BeNil()) |
| 75 | + gomega.Expect(result.ID).To(gomega.Equal("query-blocked")) |
| 76 | + }) |
| 77 | + |
| 78 | + ginkgo.It("resumes processing when the query budget recovers", func() { |
| 79 | + setSimWaitingRequests(simAdminURL, 10) |
| 80 | + waitForSaturation(promURL, envoyURL, func(v float64) bool { return v >= 0.7 }) |
| 81 | + |
| 82 | + for i := 1; i <= 3; i++ { |
| 83 | + msg := makeRequestMessage(fmt.Sprintf("query-resume-%d", i), 5*time.Minute) |
| 84 | + enqueueMessage(ctx, rdb, queryRequestQueue, msg) |
| 85 | + } |
| 86 | + |
| 87 | + gomega.Consistently(func() int64 { |
| 88 | + return getResultCount(ctx, rdb, queryResultQueue) |
| 89 | + }, 5*time.Second, 1*time.Second).Should(gomega.Equal(int64(0))) |
| 90 | + |
| 91 | + setSimWaitingRequests(simAdminURL, 0) |
| 92 | + |
| 93 | + gomega.Eventually(func() int64 { |
| 94 | + return getResultCount(ctx, rdb, queryResultQueue) |
| 95 | + }, 60*time.Second, 1*time.Second).Should(gomega.BeNumerically(">=", 3)) |
| 96 | + }) |
| 97 | +}) |
0 commit comments