mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 14:28:20 +00:00
reduce k8 events
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
ACTION_UPDATE_SECRETS,
|
ACTION_UPDATE_SECRETS,
|
||||||
ALGORITHM_AES_256_GCM,
|
ALGORITHM_AES_256_GCM,
|
||||||
ENCODING_SCHEME_UTF8,
|
ENCODING_SCHEME_UTF8,
|
||||||
|
K8_USER_AGENT_NAME,
|
||||||
SECRET_PERSONAL
|
SECRET_PERSONAL
|
||||||
} from "../../variables";
|
} from "../../variables";
|
||||||
import { BadRequestError, UnauthorizedRequestError } from "../../utils/errors";
|
import { BadRequestError, UnauthorizedRequestError } from "../../utils/errors";
|
||||||
@@ -338,13 +339,13 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
$in: deleteSecretIds
|
$in: deleteSecretIds
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.reduce(
|
.reduce(
|
||||||
(obj: any, secret: ISecret) => ({
|
(obj: any, secret: ISecret) => ({
|
||||||
...obj,
|
...obj,
|
||||||
[secret._id.toString()]: secret
|
[secret._id.toString()]: secret
|
||||||
}),
|
}),
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
await Secret.deleteMany({
|
await Secret.deleteMany({
|
||||||
_id: {
|
_id: {
|
||||||
@@ -970,21 +971,35 @@ export const getSecrets = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
const postHogClient = await TelemetryService.getPostHogClient();
|
const postHogClient = await TelemetryService.getPostHogClient();
|
||||||
|
|
||||||
|
// reduce the number of events captured
|
||||||
|
let shouldRecordK8Event = false
|
||||||
|
if (req.authData instanceof ServiceTokenData && req.authData.userAgent == K8_USER_AGENT_NAME) {
|
||||||
|
const randomNumber = Math.random();
|
||||||
|
if (randomNumber > 0.9) {
|
||||||
|
shouldRecordK8Event = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (postHogClient) {
|
if (postHogClient) {
|
||||||
postHogClient.capture({
|
const shouldCapture = req.authData.userAgent !== K8_USER_AGENT_NAME || shouldRecordK8Event;
|
||||||
event: "secrets pulled",
|
const approximateForNoneCapturedEvents = secrets.length * 10
|
||||||
distinctId: await TelemetryService.getDistinctId({
|
|
||||||
authData: req.authData
|
if (shouldCapture) {
|
||||||
}),
|
postHogClient.capture({
|
||||||
properties: {
|
event: "secrets pulled",
|
||||||
numberOfSecrets: secrets.length,
|
distinctId: await TelemetryService.getDistinctId({
|
||||||
environment,
|
authData: req.authData
|
||||||
workspaceId,
|
}),
|
||||||
channel,
|
properties: {
|
||||||
folderId,
|
numberOfSecrets: shouldRecordK8Event ? approximateForNoneCapturedEvents : secrets.length,
|
||||||
userAgent: req.headers?.["user-agent"]
|
environment,
|
||||||
}
|
workspaceId,
|
||||||
});
|
folderId,
|
||||||
|
channel: req.authData.userAgentType,
|
||||||
|
userAgent: req.authData.userAgent
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
@@ -1091,10 +1106,10 @@ export const updateSecrets = async (req: Request, res: Response) => {
|
|||||||
tags,
|
tags,
|
||||||
...(secretCommentCiphertext !== undefined && secretCommentIV && secretCommentTag
|
...(secretCommentCiphertext !== undefined && secretCommentIV && secretCommentTag
|
||||||
? {
|
? {
|
||||||
secretCommentCiphertext,
|
secretCommentCiphertext,
|
||||||
secretCommentIV,
|
secretCommentIV,
|
||||||
secretCommentTag
|
secretCommentTag
|
||||||
}
|
}
|
||||||
: {})
|
: {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
ALGORITHM_AES_256_GCM,
|
ALGORITHM_AES_256_GCM,
|
||||||
ENCODING_SCHEME_BASE64,
|
ENCODING_SCHEME_BASE64,
|
||||||
ENCODING_SCHEME_UTF8,
|
ENCODING_SCHEME_UTF8,
|
||||||
|
K8_USER_AGENT_NAME,
|
||||||
SECRET_PERSONAL,
|
SECRET_PERSONAL,
|
||||||
SECRET_SHARED
|
SECRET_SHARED
|
||||||
} from "../variables";
|
} from "../variables";
|
||||||
@@ -568,23 +569,33 @@ export const getSecretsHelper = async ({
|
|||||||
|
|
||||||
const postHogClient = await TelemetryService.getPostHogClient();
|
const postHogClient = await TelemetryService.getPostHogClient();
|
||||||
|
|
||||||
const numberOfSignupSecrets = (secrets.filter((secret) => secret?.metadata?.source === "signup")).length;
|
// reduce the number of events captured
|
||||||
|
let shouldRecordK8Event = false
|
||||||
|
if (authData instanceof ServiceTokenData && authData.userAgent == K8_USER_AGENT_NAME) {
|
||||||
|
const randomNumber = Math.random();
|
||||||
|
if (randomNumber > 0.9) {
|
||||||
|
shouldRecordK8Event = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (postHogClient && (secrets.length - numberOfSignupSecrets > 0)) {
|
if (postHogClient) {
|
||||||
postHogClient.capture({
|
const shouldCapture = authData.userAgent !== K8_USER_AGENT_NAME || shouldRecordK8Event;
|
||||||
event: "secrets pulled",
|
const approximateForNoneCapturedEvents = secrets.length * 10
|
||||||
distinctId: await TelemetryService.getDistinctId({
|
|
||||||
authData
|
if (shouldCapture) {
|
||||||
}),
|
postHogClient.capture({
|
||||||
properties: {
|
event: "secrets pulled",
|
||||||
numberOfSecrets: secrets.length - numberOfSignupSecrets,
|
distinctId: await TelemetryService.getDistinctId({ authData }),
|
||||||
environment,
|
properties: {
|
||||||
workspaceId,
|
numberOfSecrets: shouldRecordK8Event ? approximateForNoneCapturedEvents : secrets.length,
|
||||||
folderId,
|
environment,
|
||||||
channel: authData.userAgentType,
|
workspaceId,
|
||||||
userAgent: authData.userAgent
|
folderId,
|
||||||
}
|
channel: authData.userAgentType,
|
||||||
});
|
userAgent: authData.userAgent
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return secrets;
|
return secrets;
|
||||||
|
|||||||
@@ -3,3 +3,5 @@ export enum AuthMode {
|
|||||||
SERVICE_TOKEN = "serviceToken",
|
SERVICE_TOKEN = "serviceToken",
|
||||||
API_KEY = "apiKey"
|
API_KEY = "apiKey"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const K8_USER_AGENT_NAME = "k8-operator"
|
||||||
Reference in New Issue
Block a user