Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(gateway-pools): rename the selection gate to canLoadBalance

bernie-g8a4c8bf252cd
diff --git a/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.test.ts b/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.test.ts
index e63457cfcf..00bb5425d3 100644
--- a/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.test.ts
+++ b/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.test.ts
@@ -1,6 +1,6 @@
import { TGatewayScore } from "@app/lib/gateway-v2/gateway-load-tracker";
-import { everyMemberReportsLoad, pickRandomGateway, shuffleForTieBreak } from "./gateway-pool-selection-fns";
+import { canLoadBalance, pickRandomGateway, shuffleForTieBreak } from "./gateway-pool-selection-fns";
// Every member reports unless a test says otherwise; a mixed pool is covered separately.
const reported = (entries: Record<string, number>): Map<string, TGatewayScore> =>
@@ -8,14 +8,14 @@ const reported = (entries: Record<string, number>): Map<string, TGatewayScore> =
const gateways = [{ id: "a" }, { id: "b" }, { id: "c" }];
-describe("everyMemberReportsLoad", () => {
+describe("canLoadBalance", () => {
test("true when every member reports", () => {
- expect(everyMemberReportsLoad(gateways, reported({ a: 1, b: 2, c: 3 }))).toBe(true);
+ expect(canLoadBalance(gateways, reported({ a: 1, b: 2, c: 3 }))).toBe(true);
});
test("false when no member reports, because a platform-side count is not the same measurement", () => {
const legacy = new Map(["a", "b", "c"].map((id) => [id, { score: 1, base: 1, reported: false }]));
- expect(everyMemberReportsLoad(gateways, legacy)).toBe(false);
+ expect(canLoadBalance(gateways, legacy)).toBe(false);
});
test("false when the pool is mid-rollout", () => {
@@ -24,15 +24,15 @@ describe("everyMemberReportsLoad", () => {
["b", { score: 0, base: 0, reported: false }],
["c", { score: 41, base: 41, reported: true }]
]);
- expect(everyMemberReportsLoad(gateways, mixed)).toBe(false);
+ expect(canLoadBalance(gateways, mixed)).toBe(false);
});
test("false when a member has no data at all", () => {
- expect(everyMemberReportsLoad(gateways, reported({ a: 5, b: 5 }))).toBe(false);
+ expect(canLoadBalance(gateways, reported({ a: 5, b: 5 }))).toBe(false);
});
test("false for an empty pool, so the caller never claims against nothing", () => {
- expect(everyMemberReportsLoad([], reported({}))).toBe(false);
+ expect(canLoadBalance([], reported({}))).toBe(false);
});
});
diff --git a/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.ts b/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.ts
index 4fc9ba9f75..f3ee857ecb 100644
--- a/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.ts
+++ b/backend/src/ee/services/gateway-pool/gateway-pool-selection-fns.ts
@@ -15,7 +15,7 @@ export const pickRandomGateway = <T extends TSelectableGateway>(
* sees. One too old to report can only be scored on what the platform opened itself, which is always
* lower. Rather than trust that, a pool that is not fully upgraded picks at random.
*/
-export const everyMemberReportsLoad = <T extends TSelectableGateway>(
+export const canLoadBalance = <T extends TSelectableGateway>(
candidates: T[],
scores: Map<string, TGatewayScore>
): boolean => candidates.length > 0 && candidates.every((candidate) => scores.get(candidate.id)?.reported);
diff --git a/backend/src/ee/services/gateway-pool/gateway-pool-service.ts b/backend/src/ee/services/gateway-pool/gateway-pool-service.ts
index 473f57b356..4ca215c123 100644
--- a/backend/src/ee/services/gateway-pool/gateway-pool-service.ts
+++ b/backend/src/ee/services/gateway-pool/gateway-pool-service.ts
@@ -21,7 +21,7 @@ import { TPermissionServiceFactory } from "../permission/permission-service-type
import { TPkiDiscoveryConfigDALFactory } from "../pki-discovery/pki-discovery-config-dal";
import { TGatewayPoolDALFactory } from "./gateway-pool-dal";
import { TGatewayPoolMembershipDALFactory } from "./gateway-pool-membership-dal";
-import { everyMemberReportsLoad, pickRandomGateway, shuffleForTieBreak } from "./gateway-pool-selection-fns";
+import { canLoadBalance, pickRandomGateway, shuffleForTieBreak } from "./gateway-pool-selection-fns";
import {
DEFAULT_POOL_FAILOVER_ATTEMPTS,
TAddGatewayToPoolDTO,
@@ -298,7 +298,7 @@ export const gatewayPoolServiceFactory = ({
const scores = await loadTracker.getScores(pool.map((gateway) => gateway.id));
- if (everyMemberReportsLoad(pool, scores)) {
+ if (canLoadBalance(pool, scores)) {
// Two calls would let every concurrent selection read the same minimum and pile onto it.
const claimed = await loadTracker.claimLeastLoaded(
shuffleForTieBreak(pool, Math.random).map((gateway) => ({