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
+52 -48
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,18 +259,20 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
}); });
await server.services.telemetry.sendPostHogEvents({ if (getUserAgentType(req.headers["user-agent"]) !== UserAgentType.K8_OPERATOR) {
event: PostHogEventTypes.SecretPulled, await server.services.telemetry.sendPostHogEvents({
distinctId: getTelemetryDistinctId(req), event: PostHogEventTypes.SecretPulled,
properties: { distinctId: getTelemetryDistinctId(req),
numberOfSecrets: secrets.length, properties: {
workspaceId, numberOfSecrets: secrets.length,
environment, workspaceId,
secretPath: req.query.secretPath, environment,
channel: getUserAgentType(req.headers["user-agent"]), secretPath: req.query.secretPath,
...req.auditLogInfo channel: getUserAgentType(req.headers["user-agent"]),
} ...req.auditLogInfo
}); }
});
}
return { secrets, imports }; return { secrets, imports };
} }
}); });
@@ -367,18 +369,20 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
}); });
await server.services.telemetry.sendPostHogEvents({ if (getUserAgentType(req.headers["user-agent"]) !== UserAgentType.K8_OPERATOR) {
event: PostHogEventTypes.SecretPulled, await server.services.telemetry.sendPostHogEvents({
distinctId: getTelemetryDistinctId(req), event: PostHogEventTypes.SecretPulled,
properties: { distinctId: getTelemetryDistinctId(req),
numberOfSecrets: 1, properties: {
workspaceId: secret.workspace, numberOfSecrets: 1,
environment, workspaceId: secret.workspace,
secretPath: req.query.secretPath, environment,
channel: getUserAgentType(req.headers["user-agent"]), secretPath: req.query.secretPath,
...req.auditLogInfo channel: getUserAgentType(req.headers["user-agent"]),
} ...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,18 +819,20 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
}); });
await server.services.telemetry.sendPostHogEvents({ if (getUserAgentType(req.headers["user-agent"]) !== UserAgentType.K8_OPERATOR) {
event: PostHogEventTypes.SecretPulled, await server.services.telemetry.sendPostHogEvents({
distinctId: getTelemetryDistinctId(req), event: PostHogEventTypes.SecretPulled,
properties: { distinctId: getTelemetryDistinctId(req),
numberOfSecrets: 1, properties: {
workspaceId: req.query.workspaceId, numberOfSecrets: 1,
environment: req.query.environment, workspaceId: req.query.workspaceId,
secretPath: req.query.secretPath, environment: req.query.environment,
channel: getUserAgentType(req.headers["user-agent"]), secretPath: req.query.secretPath,
...req.auditLogInfo channel: getUserAgentType(req.headers["user-agent"]),
} ...req.auditLogInfo
}); }
});
}
return { secret }; return { secret };
} }
}); });