Skip to content

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

feat(telemetry): enrich self-hosted TelemetryInstanceStats with deployment depth metrics

Devin AI0f71a51684ae
diff --git a/backend/src/services/telemetry/telemetry-dal.ts b/backend/src/services/telemetry/telemetry-dal.ts
index 9fac4f1ef9..8ecca8605e 100644
--- a/backend/src/services/telemetry/telemetry-dal.ts
+++ b/backend/src/services/telemetry/telemetry-dal.ts
@@ -4,20 +4,79 @@ import { DatabaseError } from "@app/lib/errors";
export type TTelemetryDALFactory = ReturnType<typeof telemetryDALFactory>;
+const IDENTITY_AUTH_TABLES: readonly string[] = [
+ TableName.IdentityUniversalAuth,
+ TableName.IdentityTokenAuth,
+ TableName.IdentityKubernetesAuth,
+ TableName.IdentityGcpAuth,
+ TableName.IdentityAwsAuth,
+ TableName.IdentityAzureAuth,
+ TableName.IdentityOciAuth,
+ TableName.IdentityOidcAuth,
+ TableName.IdentityJwtAuth,
+ TableName.IdentityLdapAuth,
+ TableName.IdentityAliCloudAuth,
+ TableName.IdentityTlsCertAuth,
+ 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);
+};
+
export const telemetryDALFactory = (db: TDbClient) => {
const getTelemetryInstanceStats = async () => {
try {
- const userCount = (await db(TableName.Users).where({ isGhost: false }).count().first())?.count as string;
- const users = parseInt(userCount || "0", 10);
-
- const identityCount = (await db(TableName.Identity).count().first())?.count as string;
- const identities = parseInt(identityCount || "0", 10);
+ const [
+ users,
+ identities,
+ projects,
+ secrets,
+ environments,
+ secretSyncs,
+ integrations,
+ certificateAuthorities,
+ certificates,
+ dynamicSecrets,
+ groups,
+ secretApprovalPolicies
+ ] = await Promise.all([
+ (async () => {
+ const result = (await db(TableName.Users).where({ isGhost: false }).count().first())?.count as string;
+ return parseInt(result || "0", 10);
+ })(),
+ countTable(db, TableName.Identity),
+ countTable(db, TableName.Project),
+ countTable(db, TableName.Secret),
+ countTable(db, TableName.Environment),
+ countTable(db, TableName.SecretSync),
+ countTable(db, TableName.Integration),
+ countTable(db, TableName.CertificateAuthority),
+ countTable(db, TableName.Certificate),
+ countTable(db, TableName.DynamicSecret),
+ countTable(db, TableName.Groups),
+ countTable(db, TableName.SecretApprovalPolicy)
+ ]);
- const projectCount = (await db(TableName.Project).count().first())?.count as string;
- const projects = parseInt(projectCount || "0", 10);
+ const identityAuthMethodsResult = await db.raw<{ rows: { count: string }[] }>(
+ IDENTITY_AUTH_TABLES.map((table) => `SELECT COUNT(*)::text AS count FROM ${table}`).join(" UNION ALL ")
+ );
+ const identityAuthMethods = identityAuthMethodsResult.rows.reduce(
+ (sum: number, row: { count: string }) => sum + parseInt(row.count || "0", 10),
+ 0
+ );
- const secretCount = (await db(TableName.Secret).count().first())?.count as string;
- const secrets = parseInt(secretCount || "0", 10);
+ const activeGatewaysResult = (
+ await db(TableName.Gateway)
+ .whereRaw(`"heartbeat" > NOW() - INTERVAL '${GATEWAY_HEARTBEAT_THRESHOLD_SECONDS} seconds'`)
+ .count()
+ .first()
+ )?.count as string;
+ const activeGateways = parseInt(activeGatewaysResult || "0", 10);
const organizationNames = await db(TableName.Organization).select("name");
const organizations = organizationNames.length;
@@ -28,10 +87,20 @@ export const telemetryDALFactory = (db: TDbClient) => {
projects,
secrets,
organizations,
- organizationNames: organizationNames.map(({ name }) => name)
+ organizationNames: organizationNames.map(({ name }) => name),
+ environments,
+ secretSyncs,
+ integrations,
+ certificateAuthorities,
+ certificates,
+ dynamicSecrets,
+ identityAuthMethods,
+ groups,
+ secretApprovalPolicies,
+ activeGateways
};
} catch (error) {
- throw new DatabaseError({ error, name: "TelemtryInstanceStats" });
+ throw new DatabaseError({ error, name: "TelemetryInstanceStats" });
}
};
diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts
index 309586a6b0..e8dec1aefa 100644
--- a/backend/src/services/telemetry/telemetry-types.ts
+++ b/backend/src/services/telemetry/telemetry-types.ts
@@ -338,6 +338,16 @@ export type TTelemetryInstanceStatsEvent = {
organizationNames: number;
numberOfSecretOperationsMade: number;
numberOfSecretProcessed: number;
+ environments: number;
+ secretSyncs: number;
+ integrations: number;
+ certificateAuthorities: number;
+ certificates: number;
+ dynamicSecrets: number;
+ identityAuthMethods: number;
+ groups: number;
+ secretApprovalPolicies: number;
+ activeGateways: number;
};
};