Skip to content

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

feat: addressed review comments

=d1fd7d07f8e8
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.ts
index 85f06bed29..7256692ae6 100644
--- a/backend/src/ee/routes/v1/license-v2-router.ts
+++ b/backend/src/ee/routes/v1/license-v2-router.ts
@@ -436,8 +436,8 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {
schema: {
params: z.object({ organizationId: z.string().trim() }),
body: z.object({
- // One or more per_resource commitment changes; the service applies them per dimension. The
- changes: BillingV2CommitmentChangeSchema.array().min(1)
+ // One or more per_resource commitment changes; the service applies them per dimension
+ changes: BillingV2CommitmentChangeSchema.array().min(1).max(20),
}),
response: {
200: BillingV2MutationResultSchema
diff --git a/backend/src/queue/queue-service.ts b/backend/src/queue/queue-service.ts
index 93cc403701..febf16a5dc 100644
--- a/backend/src/queue/queue-service.ts
+++ b/backend/src/queue/queue-service.ts
@@ -212,6 +212,10 @@ export type TQueueOptions = {
type: "exponential" | "fixed";
delay: number;
};
+ deduplication?: {
+ id: string;
+ keepLastIfActive?: boolean;
+ };
// @deprecated Use upsertJobScheduler instead.
repeat?: {
pattern?: string;
diff --git a/backend/src/services/license-client/usage/usage-event-queue.ts b/backend/src/services/license-client/usage/usage-event-queue.ts
index 638788f9b2..7973f0f49f 100644
--- a/backend/src/services/license-client/usage/usage-event-queue.ts
+++ b/backend/src/services/license-client/usage/usage-event-queue.ts
@@ -34,7 +34,7 @@ export const usageEventQueueFactory = ({
// Counts the meter and reports it to the License Server only when the value changed since the last
// report. No-ops when the reporter is null (v2 disabled), so queued events drain harmlessly.
- const handleUsageEvent = async (orgId: string, dimensionKey: string) => {
+ const handleUsageEvent = async (orgId: string, dimensionKey: string, observedAt: Date) => {
if (!usageReporter) {
return;
}
@@ -53,14 +53,12 @@ export const usageEventQueueFactory = ({
return;
}
- const observedAt = new Date();
- const minuteBucketSeconds = Math.floor(observedAt.getTime() / 60_000) * 60;
await usageReporter.reportSnapshots(orgId, [
{
dimension_key: dimensionKey,
value,
observed_at: observedAt.toISOString(),
- idempotency_key: `${source}:${orgId}:${dimensionKey}:${minuteBucketSeconds}`,
+ idempotency_key: `${source}:${orgId}:${dimensionKey}:${observedAt.getTime()}`,
source
}
]);
@@ -105,10 +103,14 @@ export const usageEventQueueFactory = ({
const startWorker = () => {
// Counts are DB-heavy, so concurrency + limiter rate-shape a backlog instead of bursting the read replica.
- queueService.start(QueueName.UsageEvent, (job) => handleUsageEvent(job.data.orgId, job.data.dimensionKey), {
- concurrency: 5,
- limiter: { max: 50, duration: 1000 }
- });
+ queueService.start(
+ QueueName.UsageEvent,
+ (job) => handleUsageEvent(job.data.orgId, job.data.dimensionKey, new Date(job.timestamp)),
+ {
+ concurrency: 5,
+ limiter: { max: 50, duration: 1000 }
+ }
+ );
};
const init = () => {
diff --git a/backend/src/services/license-client/usage/usage-metering-service.ts b/backend/src/services/license-client/usage/usage-metering-service.ts
index 164c03c883..5bf7eb53f4 100644
--- a/backend/src/services/license-client/usage/usage-metering-service.ts
+++ b/backend/src/services/license-client/usage/usage-metering-service.ts
@@ -26,10 +26,14 @@ export const usageMeteringServiceFactory = ({
QueueJobs.UsageEvent,
{ orgId, dimensionKey },
{
- jobId: `usage-event:${orgId}:${dimensionKey}`,
+ jobId: `usage-event-${orgId}-${dimensionKey}`,
delay: process.env.NODE_ENV === "development" ? 5000 : DEBOUNCE_MS,
removeOnComplete: true,
- removeOnFail: true
+ removeOnFail: true,
+ deduplication: {
+ id: `usage-event-${orgId}-${dimensionKey}`,
+ keepLastIfActive: true
+ }
}
);
};
diff --git a/backend/src/services/license-client/usage/usage-metering.test.ts b/backend/src/services/license-client/usage/usage-metering.test.ts
index d45fb8fde8..36dad6271e 100644
--- a/backend/src/services/license-client/usage/usage-metering.test.ts
+++ b/backend/src/services/license-client/usage/usage-metering.test.ts
@@ -230,13 +230,13 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
test("no-ops when the reporter is null (v2 disabled)", async () => {
const { queue } = buildQueue({ usageReporter: null });
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key);
+ await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
expect(meteredFeatures[0].count).not.toHaveBeenCalled();
});
test("reports a snapshot and records the value on first observation", async () => {
const { queue, reportSnapshots, keyStore } = buildQueue();
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key);
+ await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
expect(reportSnapshots).toHaveBeenCalledTimes(1);
const [orgId, snapshots] = reportSnapshots.mock.calls[0] as unknown as [string, TUsageSnapshot[]];
@@ -254,13 +254,13 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
keyStore.store.set(`license-usage-last-reported-${ORG_ID}-${MaxIdentities.key}`, "42");
const { queue, reportSnapshots } = buildQueue({ keyStore });
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key);
+ await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
expect(reportSnapshots).not.toHaveBeenCalled();
});
test("drops events for unknown features", async () => {
const { queue, reportSnapshots } = buildQueue();
- await queue.handleUsageEvent(ORG_ID, "not_a_meter");
+ await queue.handleUsageEvent(ORG_ID, "not_a_meter", new Date());
expect(reportSnapshots).not.toHaveBeenCalled();
});
diff --git a/frontend/src/pages/organization/BillingV2Page/components/CommitmentView.tsx b/frontend/src/pages/organization/BillingV2Page/components/CommitmentView.tsx
index 7f98c3b73d..fbd1ffad14 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/CommitmentView.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/CommitmentView.tsx
@@ -83,7 +83,14 @@ export const CommitmentView = ({ orgId, prod, entitlement, renewsOn, onBack, onD
(sum, dim) => sum + (dim.committed ?? 0) * (dim.committedRate ?? 0),
0
);
- const newAnnual = hasChanges && preview.data ? preview.data.nextRecurringTotal : currentAnnual;
+ // The product's new annual commitment is deterministic from the version-pinned committed rates:
+ // quantities × committedRate over this product's annual dims (mirrors currentAnnual with the stepped
+ // values). Derive it client-side so the figure stays product-scoped and exact — the preview's
+ // nextRecurringTotal is the whole subscription's recurring total and must not be shown here.
+ const newAnnual = committable.reduce(
+ (sum, dim) => sum + (quantities[dim.key] ?? 0) * (dim.committedRate ?? 0),
+ 0
+ );
const currentOnDemand =
entitlement.onDemandAmount ??
committable.reduce(
@@ -127,6 +134,15 @@ export const CommitmentView = ({ orgId, prod, entitlement, renewsOn, onBack, onD
? `Down from ${fmtMoney(currentOnDemand)} / mo`
: `Up from ${fmtMoney(currentOnDemand)} / mo`;
+ const annualNote = `For ${prod.name}${renewsOn ? `, billed on ${renewsOn}` : ""}`;
+ const annualDelta =
+ // eslint-disable-next-line no-nested-ternary
+ newAnnual === currentAnnual
+ ? null
+ : newAnnual > currentAnnual
+ ? `Up from ${fmtMoney(currentAnnual)} / year`
+ : `Down from ${fmtMoney(currentAnnual)} / year`;
+
return (
<>
<SheetHeader className="flex-row items-center gap-3.5 border-b pr-12">
@@ -186,8 +202,8 @@ export const CommitmentView = ({ orgId, prod, entitlement, renewsOn, onBack, onD
<InfoIcon />
<AlertDescription className="text-foreground">
Committed units are pre-bought for the year at the annual rate. Usage above your
- commitment is billed monthly at the on-demand rate until your renewal. Raising your
- commitment is prorated for the rest of the term; lowering it takes effect at renewal.
+ commitment is billed monthly at the on-demand rate until your renewal.Increasing your
+ commitment takes effect immediately for the rest of the term and is invoiced right away.
</AlertDescription>
</Alert>
@@ -201,15 +217,13 @@ export const CommitmentView = ({ orgId, prod, entitlement, renewsOn, onBack, onD
/>
<CostSummaryRow
label="New annual commitment"
- note={`For ${prod.name}${renewsOn ? `, billed on ${renewsOn}` : ""}`}
+ note={annualDelta ?? annualNote}
value={`${fmtMoney(newAnnual)} / year`}
- isCalculating={isCalculating}
/>
<CostSummaryRow
label="On-demand after change"
note={onDemandDelta ?? "Billed monthly for usage above your commitment"}
value={`${fmtMoney(newOnDemand)} / mo`}
- isCalculating={isCalculating}
valueClassName={newOnDemand > 0 ? "text-warning/90" : "text-muted"}
/>
</CostSummary>
diff --git a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
index f8a7666228..4872c796ae 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
@@ -543,17 +543,9 @@ export const ProductSheet = ({
<span className="text-xs text-muted">
Choose monthly or yearly at checkout · cancel any time
</span>
- <div className="flex items-center gap-2">
- <Button variant="outline" onClick={onClose}>
- Close
- </Button>
- {selfServePlan && (
- <Button variant="org" onClick={() => openActivate(selfServePlan.tier)}>
- <PlusIcon />
- Activate
- </Button>
- )}
- </div>
+ <Button variant="outline" onClick={onClose}>
+ Close
+ </Button>
</>
)}
</SheetFooter>