Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(telemetry): count gateways from both legacy and V2 tables, fix organizationNames type
Devin AI7b04452b3dee
diff --git a/backend/src/services/telemetry/telemetry-dal.ts b/backend/src/services/telemetry/telemetry-dal.tsindex 8ecca8605e..6582e5a26c 100644--- a/backend/src/services/telemetry/telemetry-dal.ts+++ b/backend/src/services/telemetry/telemetry-dal.ts@@ -1,5 +1,6 @@import { TDbClient } from "@app/db";import { TableName } from "@app/db/schemas";+import { HEARTBEAT_BUFFER_SECONDS } from "@app/ee/services/gateway-v2/gateway-v2-constants";import { DatabaseError } from "@app/lib/errors";export type TTelemetryDALFactory = ReturnType<typeof telemetryDALFactory>;@@ -20,9 +21,6 @@ const IDENTITY_AUTH_TABLES: readonly string[] = [TableName.IdentitySpiffeAuth];-// Gateways with a heartbeat within the last 60 seconds are considered active-const GATEWAY_HEARTBEAT_THRESHOLD_SECONDS = 60;-const countTable = async (db: TDbClient, table: TableName) => {const result = (await db(table).count().first())?.count as string;return parseInt(result || "0", 10);@@ -70,13 +68,28 @@ export const telemetryDALFactory = (db: TDbClient) => {0);- const activeGatewaysResult = (+ // Count active gateways from both legacy (Gateway) and V2 (GatewayV2) tables.+ // Legacy gateways heartbeat every ~3 minutes; use a 5-minute window to avoid undercounting.+ // V2 gateways report their own heartbeatTTL; use the same expression as gateway-v2-dal.ts.+ const legacyActiveResult = (await db(TableName.Gateway)- .whereRaw(`"heartbeat" > NOW() - INTERVAL '${GATEWAY_HEARTBEAT_THRESHOLD_SECONDS} seconds'`)+ .whereNotNull("heartbeat")+ .whereRaw(`"heartbeat" > NOW() - INTERVAL '5 minutes'`)+ .count()+ .first()+ )?.count as string;++ const v2ActiveResult = (+ await db(TableName.GatewayV2)+ .whereNotNull("heartbeat")+ .whereRaw(+ `COALESCE("heartbeatTTL", 0) > 0 AND "heartbeat" + make_interval(secs => COALESCE("heartbeatTTL", 0) + ${HEARTBEAT_BUFFER_SECONDS}) > NOW()`+ ).count().first())?.count as string;- const activeGateways = parseInt(activeGatewaysResult || "0", 10);++ const activeGateways = parseInt(legacyActiveResult || "0", 10) + parseInt(v2ActiveResult || "0", 10);const organizationNames = await db(TableName.Organization).select("name");const organizations = organizationNames.length;diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.tsindex e8dec1aefa..9381806dd8 100644--- a/backend/src/services/telemetry/telemetry-types.ts+++ b/backend/src/services/telemetry/telemetry-types.ts@@ -335,7 +335,7 @@ export type TTelemetryInstanceStatsEvent = {projects: number;secrets: number;organizations: number;- organizationNames: number;+ organizationNames: string[];numberOfSecretOperationsMade: number;numberOfSecretProcessed: number;environments: number;