Merge pull request #1979 from Infisical/analytics-update

remove k8s events from posthog
This commit is contained in:
Maidul Islam
2024-06-17 20:14:28 -04:00
committed by GitHub
+16 -12
View File
@@ -8,7 +8,7 @@ import {
SecretType, SecretType,
ServiceTokenScopes ServiceTokenScopes
} from "@app/db/schemas"; } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types"; import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
import { RAW_SECRETS, SECRETS } from "@app/lib/api-docs"; import { RAW_SECRETS, SECRETS } from "@app/lib/api-docs";
import { BadRequestError } from "@app/lib/errors"; import { BadRequestError } from "@app/lib/errors";
import { removeTrailingSlash } from "@app/lib/fn"; import { removeTrailingSlash } from "@app/lib/fn";
@@ -259,6 +259,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
}); });
if (getUserAgentType(req.headers["user-agent"]) !== UserAgentType.K8_OPERATOR) {
await server.services.telemetry.sendPostHogEvents({ await server.services.telemetry.sendPostHogEvents({
event: PostHogEventTypes.SecretPulled, event: PostHogEventTypes.SecretPulled,
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
@@ -271,6 +272,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
...req.auditLogInfo ...req.auditLogInfo
} }
}); });
}
return { secrets, imports }; return { secrets, imports };
} }
}); });
@@ -367,6 +369,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
}); });
if (getUserAgentType(req.headers["user-agent"]) !== UserAgentType.K8_OPERATOR) {
await server.services.telemetry.sendPostHogEvents({ await server.services.telemetry.sendPostHogEvents({
event: PostHogEventTypes.SecretPulled, event: PostHogEventTypes.SecretPulled,
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
@@ -379,6 +382,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
...req.auditLogInfo ...req.auditLogInfo
} }
}); });
}
return { secret }; return { secret };
} }
}); });
@@ -723,24 +727,22 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
}); });
// TODO: Move to telemetry plugin // TODO: Move to telemetry plugin
let shouldRecordK8Event = false; // let shouldRecordK8Event = false;
if (req.headers["user-agent"] === "k8-operatoer") { // if (req.headers["user-agent"] === "k8-operatoer") {
const randomNumber = Math.random(); // const randomNumber = Math.random();
if (randomNumber > 0.95) { // if (randomNumber > 0.95) {
shouldRecordK8Event = true; // shouldRecordK8Event = true;
} // }
} // }
const shouldCapture = const shouldCapture =
req.query.workspaceId !== "650e71fbae3e6c8572f436d4" && req.query.workspaceId !== "650e71fbae3e6c8572f436d4" && req.headers["user-agent"] !== "k8-operator";
(req.headers["user-agent"] !== "k8-operator" || shouldRecordK8Event);
const approximateNumberTotalSecrets = secrets.length * 20;
if (shouldCapture) { if (shouldCapture) {
await server.services.telemetry.sendPostHogEvents({ await server.services.telemetry.sendPostHogEvents({
event: PostHogEventTypes.SecretPulled, event: PostHogEventTypes.SecretPulled,
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
properties: { properties: {
numberOfSecrets: shouldRecordK8Event ? approximateNumberTotalSecrets : secrets.length, numberOfSecrets: secrets.length,
workspaceId: req.query.workspaceId, workspaceId: req.query.workspaceId,
environment: req.query.environment, environment: req.query.environment,
secretPath: req.query.secretPath, secretPath: req.query.secretPath,
@@ -817,6 +819,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
}); });
if (getUserAgentType(req.headers["user-agent"]) !== UserAgentType.K8_OPERATOR) {
await server.services.telemetry.sendPostHogEvents({ await server.services.telemetry.sendPostHogEvents({
event: PostHogEventTypes.SecretPulled, event: PostHogEventTypes.SecretPulled,
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
@@ -829,6 +832,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
...req.auditLogInfo ...req.auditLogInfo
} }
}); });
}
return { secret }; return { secret };
} }
}); });