Skip to content

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

feat: fixed the annual recurring issue not counting

=7a65b04dcdc4
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 0c4e8b4ccf..eb0a90ddf2 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -846,7 +846,6 @@ export const registerRoutes = async (
usageMeteringService,
meteredFeatures,
usageReporter,
- licenseClient,
source: usageSource
});
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 b5fe16d7ca..1a9657a3d0 100644
--- a/backend/src/services/license-client/usage/usage-event-queue.ts
+++ b/backend/src/services/license-client/usage/usage-event-queue.ts
@@ -5,10 +5,9 @@ import { logger } from "@app/lib/logger";
import { QueueName, TQueueServiceFactory } from "@app/queue";
import { TOrgDALFactory } from "@app/services/org/org-dal";
-import { TLicenseClientFactory } from "../license-client";
import { TMeteredFeature } from "./usage-counters";
import { TUsageMeteringServiceFactory } from "./usage-metering-service";
-import { TUsageReporter } from "./usage-reporter";
+import { TUsageReporter, UsageReportError } from "./usage-reporter";
type TUsageEventQueueFactoryDep = {
queueService: Pick<TQueueServiceFactory, "start">;
@@ -18,8 +17,6 @@ type TUsageEventQueueFactoryDep = {
usageMeteringService: Pick<TUsageMeteringServiceFactory, "emit">;
meteredFeatures: TMeteredFeature[];
usageReporter: TUsageReporter | null;
- // Resolves the org's plan so we only report dimensions the plan actually includes. Cached.
- licenseClient: Pick<TLicenseClientFactory, "getEntitlements">;
source: string;
};
@@ -31,7 +28,6 @@ export const usageEventQueueFactory = ({
usageMeteringService,
meteredFeatures,
usageReporter,
- licenseClient,
source
}: TUsageEventQueueFactoryDep) => {
const featureByKey = new Map(meteredFeatures.map((m) => [m.feature.key, m]));
@@ -49,19 +45,6 @@ export const usageEventQueueFactory = ({
return;
}
- // Only report a dimension the org's plan actually includes. Metered features are entitlement
- // features (each meter resolves its cap from entitlements.features[key]), so a dimension the plan
- // doesn't grant is absent here. Works for cloud (per-org entitlements) and self-hosted
- // (instance-wide entitlements; the backend ignores the org id). Entitlements are cached, so this
- // check is cheap and also spares the DB count below.
- const entitlements = await licenseClient.getEntitlements({ id: orgId });
- if (!entitlements || !(dimensionKey in entitlements.features)) {
- logger.info(
- `usage-event-queue: dimension not in org plan, skipping [orgId=${orgId}] [dimensionKey=${dimensionKey}]`
- );
- return;
- }
-
const value = await metered.count(orgId);
const lastReportedKey = KeyStorePrefixes.LicenseUsageLastReported(orgId, dimensionKey);
@@ -70,15 +53,33 @@ export const usageEventQueueFactory = ({
return;
}
- await usageReporter.reportSnapshots(orgId, [
- {
- dimension_key: dimensionKey,
- value,
- observed_at: observedAt.toISOString(),
- idempotency_key: `${source}:${orgId}:${dimensionKey}:${observedAt.getTime()}`,
- source
+ // Send the snapshot and let the license server decide whether the dimension is billable. A 422
+ // "not priced by any active product on this license" means the org's plan doesn't carry this
+ // dimension, so swallow it (no retry, don't record it as reported). Any other failure rethrows to
+ // the outer handler so the job retries.
+ try {
+ await usageReporter.reportSnapshots(orgId, [
+ {
+ dimension_key: dimensionKey,
+ value,
+ observed_at: observedAt.toISOString(),
+ idempotency_key: `${source}:${orgId}:${dimensionKey}:${observedAt.getTime()}`,
+ source
+ }
+ ]);
+ } catch (error) {
+ if (
+ error instanceof UsageReportError &&
+ error.status === 422 &&
+ error.serverMessage.includes("not priced by any active product on this license")
+ ) {
+ logger.info(
+ `usage-event-queue: dimension not priced on this license, skipping [orgId=${orgId}] [dimensionKey=${dimensionKey}]`
+ );
+ return;
}
- ]);
+ throw error;
+ }
logger.info(
`usage-event-queue: reported usage event [orgId=${orgId}] [dimensionKey=${dimensionKey}] [value=${value}]`
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 a570d94ee1..c1da836074 100644
--- a/backend/src/services/license-client/usage/usage-metering.test.ts
+++ b/backend/src/services/license-client/usage/usage-metering.test.ts
@@ -14,7 +14,7 @@ import {
import { buildMeteredFeatures } from "./usage-counters";
import { usageEventQueueFactory } from "./usage-event-queue";
import { usageMeteringServiceFactory } from "./usage-metering-service";
-import { buildUsageReporter, TUsageSnapshot } from "./usage-reporter";
+import { buildUsageReporter, TUsageSnapshot, UsageReportError } from "./usage-reporter";
type TQueueCall = [
QueueName,
@@ -245,8 +245,6 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
usageReporter?: unknown;
keyStore?: ReturnType<typeof createFakeKeyStore>;
orgFind?: unknown;
- // Feature keys the org's plan includes; defaults to the metered feature under test.
- planFeatures?: string[];
} = {}
) => {
const reportSnapshots = vi.fn(async () => {});
@@ -254,10 +252,6 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
const usageReporter = overrides.usageReporter === undefined ? { reportSnapshots } : overrides.usageReporter;
const emit = vi.fn();
const find = overrides.orgFind ?? vi.fn(async () => []);
- const planFeatures = overrides.planFeatures ?? [IdentitiesMeter.key];
- const getEntitlements = vi.fn(async () => ({
- features: Object.fromEntries(planFeatures.map((key) => [key, { value: 100, source: "plan" }]))
- }));
const queue = usageEventQueueFactory({
queueService: { start: vi.fn() },
cronJob: { register: vi.fn(), start: vi.fn(), stop: vi.fn() } as never,
@@ -266,10 +260,9 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
usageMeteringService: { emit },
meteredFeatures,
usageReporter: usageReporter as never,
- licenseClient: { getEntitlements } as never,
source: "test-region"
});
- return { queue, reportSnapshots, keyStore, emit, find, getEntitlements };
+ return { queue, reportSnapshots, keyStore, emit, find };
};
beforeEach(() => {
@@ -312,12 +305,27 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
expect(reportSnapshots).not.toHaveBeenCalled();
});
- test("skips the count and report when the dimension is not in the org's plan", async () => {
- // The org's plan has no metered features, so the dimension is absent from entitlements.features.
- const { queue, reportSnapshots } = buildQueue({ planFeatures: [] });
- await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());
- expect(meteredFeatures[0].count).not.toHaveBeenCalled();
- expect(reportSnapshots).not.toHaveBeenCalled();
+ test("swallows a 422 'not priced' report error without retrying or recording it", async () => {
+ const reportSnapshots = vi.fn(async () => {
+ throw new UsageReportError(422, "dimension X is not priced by any active product on this license");
+ });
+ const { queue, keyStore } = buildQueue({ usageReporter: { reportSnapshots } });
+
+ // Does not throw (so the job is not retried).
+ await expect(queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date())).resolves.toBeUndefined();
+ // Not recorded as reported, so a later change can retry.
+ expect(keyStore.store.get(`license-usage-last-reported-${ORG_ID}-${IdentitiesMeter.key}`)).toBeUndefined();
+ });
+
+ test("rethrows other report errors so the job retries", async () => {
+ const reportSnapshots = vi.fn(async () => {
+ throw new UsageReportError(500, "internal server error");
+ });
+ const { queue } = buildQueue({ usageReporter: { reportSnapshots } });
+
+ await expect(queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date())).rejects.toBeInstanceOf(
+ UsageReportError
+ );
});
test("flushAllOrgs pages through orgs and emits per meter", async () => {
diff --git a/backend/src/services/license-client/usage/usage-reporter.ts b/backend/src/services/license-client/usage/usage-reporter.ts
index e9b69575c9..9535142f47 100644
--- a/backend/src/services/license-client/usage/usage-reporter.ts
+++ b/backend/src/services/license-client/usage/usage-reporter.ts
@@ -15,6 +15,21 @@ export type TUsageReporter = {
reportSnapshots: (orgId: string, snapshots: TUsageSnapshot[]) => Promise<void>;
};
+// Carries the license server's HTTP status + parsed message so callers can special-case responses
+// (e.g. swallow a 422 "not priced by any active product on this license") instead of retrying.
+export class UsageReportError extends Error {
+ readonly status: number;
+
+ readonly serverMessage: string;
+
+ constructor(status: number, serverMessage: string) {
+ super(`usage snapshot report failed with ${status}${serverMessage ? `: ${serverMessage}` : ""}`);
+ this.name = "UsageReportError";
+ this.status = status;
+ this.serverMessage = serverMessage;
+ }
+}
+
// getBearerToken is called per request so a cloud reporter can mint a fresh short-lived JWT each time
// (a self-hosted reporter just returns its static license key).
export const usageReporterFactory = (serverUrl: string, getBearerToken: () => string): TUsageReporter => ({
@@ -32,7 +47,14 @@ export const usageReporterFactory = (serverUrl: string, getBearerToken: () => st
});
if (!res.ok) {
- throw new Error(`usage snapshot report failed with ${res.status}`);
+ let serverMessage = "";
+ try {
+ const body = (await res.json()) as { message?: string; error?: string };
+ serverMessage = body?.message ?? body?.error ?? "";
+ } catch {
+ // non-JSON body; leave the message empty
+ }
+ throw new UsageReportError(res.status, serverMessage);
}
}
});
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index f7360adda4..d6107957dd 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -53,6 +53,7 @@ services:
nofile:
soft: 262144
hard: 262144
+ profiles: [clickhouse]
redis-commander:
container_name: infisical-dev-redis-commander
@@ -101,8 +102,6 @@ services:
condition: service_started
redis:
condition: service_started
- clickhouse:
- condition: service_started
env_file:
- .env
ports:
diff --git a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
index 18ee258f8b..8273cd1330 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/Overview.tsx
@@ -7,7 +7,6 @@ import { DetailsCard } from "./cards/DetailsCard";
import { InvoicesCard } from "./cards/InvoicesCard";
import { PaymentCard } from "./cards/PaymentCard";
import { ProductsCard } from "./cards/ProductsCard";
-import { DeprecationBanners } from "./deprecation/DeprecationBanners";
import { ErrorPanel } from "./states/ErrorPanel";
import { OverviewSkeleton } from "./states/OverviewSkeleton";
import { Banner } from "./Banner";
@@ -89,12 +88,12 @@ export const Overview = ({
onUpdatePayment={onUpdatePayment}
onManageSubscription={onManageSubscription}
/>
- <DeprecationBanners
+ {/* <DeprecationBanners
overview={overview}
catalog={catalog}
onManage={onUpgrade}
onContact={onContact}
- />
+ /> */}
<BillingHeaderCard overview={overview} catalog={catalog} />
<ProductsCard
overview={overview}
diff --git a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
index 8688072c39..c8a9b33224 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/ProductSheet.tsx
@@ -245,12 +245,6 @@ const PlanCard = ({
<PlanPricing plan={plan} cadence={cadence} />
)}
{plan.feature && <div className="text-xs text-accent">{plan.feature}</div>}
- {offersTrial && (
- <div className="flex items-center gap-1.5 text-xs text-success">
- <Check className="size-3.5" />
- Free trial · no charge for your first cycle
- </div>
- )}
{cta}
</div>
);
@@ -456,9 +450,6 @@ export const ProductSheet = ({
const activatePlanObj = activatePlan
? plans.find((plan) => plan.tier === activatePlan)
: (selfServePlan ?? undefined);
- const trialPlanObj = trialConfirmTier
- ? plans.find((plan) => plan.tier === trialConfirmTier)
- : undefined;
return (
<>
@@ -586,11 +577,11 @@ export const ProductSheet = ({
<AlertDialogMedia>
<Sparkles />
</AlertDialogMedia>
- <AlertDialogTitle>Start your {prod.name} trial?</AlertDialogTitle>
+ <AlertDialogTitle>Start your {prod.name} trial</AlertDialogTitle>
<AlertDialogDescription>
- Your free trial starts now with no charge. When it ends, {prod.name} continues on the
- monthly {trialPlanObj?.name ?? "Pro"} plan and you&apos;ll be billed for what you use.
- Cancel anytime before then to avoid charges.
+ Your 30-day trial is free. After it ends, your subscription continues automatically
+ and you&apos;ll be billed monthly based on usage. Cancel before the trial ends to
+ avoid charges.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
@@ -623,10 +614,10 @@ export const ProductSheet = ({
<AlertDialogMedia>
<CalendarX2Icon />
</AlertDialogMedia>
- <AlertDialogTitle>Cancel your {prod.name} trial?</AlertDialogTitle>
+ <AlertDialogTitle>Cancel your {prod.name} trial</AlertDialogTitle>
<AlertDialogDescription>
- {prod.name} drops back to the free tier right away and the trial won&apos;t convert to
- a paid plan. You can&apos;t restart this trial later.
+ Canceling returns you to the free tier immediately and stops the trial from converting
+ to a paid plan. This trial can&apos;t be restarted later.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
diff --git a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
index 1ce6da555d..b0a5b2c231 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
@@ -31,7 +31,7 @@ import {
productAnnualCommitted,
tierLabel
} from "../../billing-v2-format";
-import { deprecationSubline } from "../deprecation/deprecation-data";
+import { asPlanDeprecation, deprecationSubline } from "../deprecation/deprecation-data";
import {
ActiveBadge,
CardEmpty,
@@ -49,7 +49,8 @@ type ActiveProductCardProps = {
// Full-width card for an active product: identity and status, price, Manage action, usage meters.
const ActiveProductCard = ({ prod, entitlement, readOnly, onManage }: ActiveProductCardProps) => {
- const deprecation = entitlement?.deprecation;
+ // Every deprecation is presented as a retiring plan for now (see asPlanDeprecation).
+ const deprecation = asPlanDeprecation(entitlement?.deprecation);
const isProductDeprecated = deprecation?.kind === "product";
const isPlanDeprecated = deprecation?.kind === "plan";
@@ -259,7 +260,7 @@ export const ProductsCard = ({
<Package className="size-4 text-accent" />
Products
</CardTitle>
- <CardDescription>Everything you can run on your subscription.</CardDescription>
+ <CardDescription>Active products</CardDescription>
{!readOnly && (
<CardAction>
<Tooltip>
@@ -286,39 +287,47 @@ export const ProductsCard = ({
description="Products will appear here once they're available."
/>
) : (
- <div className="flex flex-col gap-4">
- {active.map((prod) => (
- <ActiveProductCard
- key={prod.id}
- prod={prod}
- entitlement={overview.entitlements[prod.id]}
- readOnly={readOnly}
- onManage={onManage}
+ <>
+ {active.length === 0 && (
+ <CardEmpty
+ title="No active products"
+ description="Activate your first product to get started."
/>
- ))}
- {available.length > 0 && (
- <>
- <div className="flex items-center gap-3 pt-1">
- <span className="text-sm font-medium text-muted">Available to add</span>
- <div className="h-px flex-1 bg-border" />
- </div>
- {/* Container-keyed columns: the collapsible sidebar changes the room, not the viewport. */}
- <div className="@container">
- <div className="grid gap-4 @2xl:grid-cols-2 @4xl:grid-cols-3">
- {available.map((prod) => (
- <AvailableProductTile
- key={prod.id}
- prod={prod}
- readOnly={readOnly}
- onManage={onManage}
- onContact={onContact}
- />
- ))}
- </div>
- </div>
- </>
)}
- </div>
+ <div className="flex flex-col gap-4">
+ {active.map((prod) => (
+ <ActiveProductCard
+ key={prod.id}
+ prod={prod}
+ entitlement={overview.entitlements[prod.id]}
+ readOnly={readOnly}
+ onManage={onManage}
+ />
+ ))}
+ {available.length > 0 && (
+ <>
+ <div className="flex items-center gap-3 pt-2">
+ <span className="text-sm font-medium text-muted">Available products</span>
+ <div className="h-px flex-1 bg-border" />
+ </div>
+ {/* Container-keyed columns: the collapsible sidebar changes the room, not the viewport. */}
+ <div className="@container">
+ <div className="grid gap-4 @2xl:grid-cols-2 @4xl:grid-cols-3">
+ {available.map((prod) => (
+ <AvailableProductTile
+ key={prod.id}
+ prod={prod}
+ readOnly={readOnly}
+ onManage={onManage}
+ onContact={onContact}
+ />
+ ))}
+ </div>
+ </div>
+ </>
+ )}
+ </div>
+ </>
)}
</CardContent>
</Card>
diff --git a/frontend/src/pages/organization/BillingV2Page/components/deprecation/DeprecationBanners.tsx b/frontend/src/pages/organization/BillingV2Page/components/deprecation/DeprecationBanners.tsx
index 5b35bd319d..71df633060 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/deprecation/DeprecationBanners.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/deprecation/DeprecationBanners.tsx
@@ -12,7 +12,7 @@ import {
import { BillingV2CatalogProduct, BillingV2Overview } from "@app/hooks/api";
import { tierLabel } from "../../billing-v2-format";
-import { daysLeftLabel, DeprecatedEntry, Deprecation } from "./deprecation-data";
+import { asPlanDeprecation, daysLeftLabel, DeprecatedEntry } from "./deprecation-data";
import { DeprecationDetailBody } from "./DeprecationDetailBody";
// Attention banners above the summary, one per affected product. A retiring plan reads forward-looking
@@ -38,7 +38,7 @@ export const DeprecationBanners = ({
productId,
name: catalog.find((prod) => prod.id === productId)?.name ?? productId,
planTier: entitlement.planTier,
- deprecation: entitlement.deprecation as Deprecation
+ deprecation: asPlanDeprecation(entitlement.deprecation)!
}))
.sort((a, b) => {
const rank = (entry: DeprecatedEntry) => (entry.deprecation.kind === "product" ? 0 : 1);
diff --git a/frontend/src/pages/organization/BillingV2Page/components/deprecation/deprecation-data.ts b/frontend/src/pages/organization/BillingV2Page/components/deprecation/deprecation-data.ts
index 61f9f9513f..4092475f45 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/deprecation/deprecation-data.ts
+++ b/frontend/src/pages/organization/BillingV2Page/components/deprecation/deprecation-data.ts
@@ -11,6 +11,13 @@ export type DeprecatedEntry = {
deprecation: Deprecation;
};
+// The backend currently emits a single deprecation kind, so we can't yet distinguish a product being
+// discontinued from a plan retiring. Until it does, present every deprecation as a retiring plan (the
+// softer, forward-looking treatment) rather than the terminal product one. Coerce the kind at read
+// sites so all views stay consistent; drop this to restore the per-kind treatment.
+export const asPlanDeprecation = (deprecation?: Deprecation): Deprecation | undefined =>
+ deprecation ? { ...deprecation, kind: "plan" } : undefined;
+
export const daysLeftLabel = (daysLeft: number | null): string | null => {
if (daysLeft === null) {
return null;