Skip to content

[backend] add more telemetry data for draft & workbenches (#11014) #11015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions opencti-platform/opencti-graphql/src/domain/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import { extractEntityRepresentativeName } from '../database/entity-representative';
import type { BasicStoreCommon } from '../types/store';
import type { Connector } from '../connector/internalConnector';
import { addWorkbenchDraftConvertionCount, addWorkbenchValidationCount } from '../manager/telemetryManager';

// region connectors
export const connectorForWork = async (context: AuthContext, user: AuthUser, id: string) => {
Expand Down Expand Up @@ -416,6 +417,13 @@
controlUserConfidenceAgainstElement(user, entity);
}
const connectorsForFile = await uploadJobImport(context, user, file, entityId, opts);
if (file.id.startsWith('import/pending')) {
if (args.forceValidation && args.validationMode === 'draft') {
await addWorkbenchDraftConvertionCount();
} else if (args.bypassValidation) {
await addWorkbenchValidationCount();
}
}

Check warning on line 426 in opencti-platform/opencti-graphql/src/domain/connector.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/domain/connector.ts#L420-L426

Added lines #L420 - L426 were not covered by tests
const entityName = entityId ? extractEntityRepresentativeName(entity) : 'global';
const entityType = entityId ? entity.entity_type : 'global';
const baseData: UserImportActionContextData = {
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-graphql/src/domain/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { UnsupportedError } from '../config/errors';
import { isDraftFile } from '../database/draft-utils';
import { askJobImport } from './connector';
import { addWorkbenchUploadCount } from '../manager/telemetryManager';

export const buildOptionsFromFileManager = async (context) => {
let importPaths = ['import/'];
Expand Down Expand Up @@ -129,6 +130,7 @@

const { upload: up } = await uploadToStorage(context, user, 'import/pending', finalFile, { meta, file_markings, errorOnExisting, entity });
const contextData = buildContextDataForFile(entity, 'import/pending', up.name, up.metaData.file_markings);
await addWorkbenchUploadCount();

Check warning on line 133 in opencti-platform/opencti-graphql/src/domain/file.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/domain/file.js#L133

Added line #L133 was not covered by tests
await publishUserAction({
user,
event_type: 'file',
Expand Down
31 changes: 30 additions & 1 deletion opencti-platform/opencti-graphql/src/manager/telemetryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,36 @@
export const TELEMETRY_GAUGE_DISSEMINATION = 'disseminationCount';
export const TELEMETRY_GAUGE_NLQ = 'nlqQueryCount';
export const TELEMETRY_GAUGE_REQUEST_ACCESS = 'requestAccessCreationCount';
export const TELEMETRY_GAUGE_DRAFT_CREATION = 'draftCreationCount';
export const TELEMETRY_GAUGE_DRAFT_VALIDATION = 'draftValidationCount';
export const TELEMETRY_GAUGE_WORKBENCH_UPLOAD = 'workbenchUploadCount';
export const TELEMETRY_GAUGE_WORKBENCH_DRAFT_CONVERTION = 'workbenchDraftConvertionCount';
export const TELEMETRY_GAUGE_WORKBENCH_VALIDATION = 'workbenchValidationCount';

export const addDisseminationCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_DISSEMINATION, 1);
};
export const addNlqQueryCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_NLQ, 1);
};

export const addRequestAccessCreationCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_REQUEST_ACCESS, 1);
};
export const addDraftCreationCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_DRAFT_CREATION, 1);
};
export const addDraftValidationCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_DRAFT_VALIDATION, 1);
};

Check warning on line 68 in opencti-platform/opencti-graphql/src/manager/telemetryManager.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/manager/telemetryManager.ts#L67-L68

Added lines #L67 - L68 were not covered by tests
export const addWorkbenchUploadCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_WORKBENCH_UPLOAD, 1);
};

Check warning on line 71 in opencti-platform/opencti-graphql/src/manager/telemetryManager.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/manager/telemetryManager.ts#L70-L71

Added lines #L70 - L71 were not covered by tests
export const addWorkbenchDraftConvertionCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_WORKBENCH_DRAFT_CONVERTION, 1);
};

Check warning on line 74 in opencti-platform/opencti-graphql/src/manager/telemetryManager.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/manager/telemetryManager.ts#L73-L74

Added lines #L73 - L74 were not covered by tests
export const addWorkbenchValidationCount = async () => {
await redisSetTelemetryAdd(TELEMETRY_GAUGE_WORKBENCH_VALIDATION, 1);
};

Check warning on line 77 in opencti-platform/opencti-graphql/src/manager/telemetryManager.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/manager/telemetryManager.ts#L76-L77

Added lines #L76 - L77 were not covered by tests

// End Region user event counters

Expand Down Expand Up @@ -171,6 +190,16 @@
manager.setNlqQueryCount(nlqQueryCountInRedis);
const requestAccessCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_REQUEST_ACCESS);
manager.setRequestAccessCreatedCount(requestAccessCountInRedis);
const draftCreationCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_DRAFT_CREATION);
manager.setDraftCreationCount(draftCreationCountInRedis);
const draftValidationCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_DRAFT_VALIDATION);
manager.setDraftValidationCount(draftValidationCountInRedis);
const workbenchUploadCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_WORKBENCH_UPLOAD);
manager.setWorkbenchUploadCount(workbenchUploadCountInRedis);
const workbenchDraftConvertionCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_WORKBENCH_DRAFT_CONVERTION);
manager.setWorkbenchDraftConvertionCount(workbenchDraftConvertionCountInRedis);
const workbenchValidationCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_WORKBENCH_VALIDATION);
manager.setWorkbenchValidationCount(workbenchValidationCountInRedis);
// end region Telemetry user events
logApp.debug('[TELEMETRY] Fetching telemetry data successfully');
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import { DRAFT_STATUS_OPEN, DRAFT_STATUS_VALIDATED } from './draftStatuses';
import { notify } from '../../database/redis';
import { publishUserAction } from '../../listener/UserActionListener';
import { addDraftCreationCount, addDraftValidationCount } from '../../manager/telemetryManager';

export const findById = (context: AuthContext, user: AuthUser, id: string) => {
return storeLoadById<BasicStoreEntityDraftWorkspace>(context, user, id, ENTITY_TYPE_DRAFT_WORKSPACE);
Expand Down Expand Up @@ -184,6 +185,7 @@
};
const draftWorkspaceInput = { ...input, ...defaultOps };
const createdDraftWorkspace = await createEntity(context, user, draftWorkspaceInput, ENTITY_TYPE_DRAFT_WORKSPACE);
await addDraftCreationCount();
await publishUserAction({
user,
event_type: 'mutation',
Expand Down Expand Up @@ -340,5 +342,7 @@
await notify(BUS_TOPICS[ENTITY_TYPE_DRAFT_WORKSPACE].EDIT_TOPIC, element, user);
await deleteDraftContextFromUsers(context, user, draft_id);

await addDraftValidationCount();

Check warning on line 345 in opencti-platform/opencti-graphql/src/modules/draftWorkspace/draftWorkspace-domain.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/draftWorkspace/draftWorkspace-domain.ts#L345

Added line #L345 was not covered by tests

return work;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ export class TelemetryMeterManager {
// Number of active drafts
draftCount = 0;

draftCreationCount = 0;

draftValidationCount = 0;

// Number of active workbenches
workbenchCount = 0;

workbenchUploadCount = 0;

workbenchDraftConvertionCount = 0;

workbenchValidationCount = 0;

// Number of NLQ query call
nlqQueryCount = 0;

Expand Down Expand Up @@ -65,10 +75,30 @@ export class TelemetryMeterManager {
this.draftCount = n;
}

setDraftCreationCount(n: number) {
this.draftCreationCount = n;
}

setDraftValidationCount(n: number) {
this.draftValidationCount = n;
}

setWorkbenchCount(n: number) {
this.workbenchCount = n;
}

setWorkbenchUploadCount(n: number) {
this.workbenchUploadCount = n;
}

setWorkbenchDraftConvertionCount(n: number) {
this.workbenchDraftConvertionCount = n;
}

setWorkbenchValidationCount(n: number) {
this.workbenchValidationCount = n;
}

setNlqQueryCount(n: number) {
this.nlqQueryCount = n;
}
Expand Down Expand Up @@ -97,7 +127,12 @@ export class TelemetryMeterManager {
this.registerGauge('is_enterprise_edition', 'enterprise Edition is activated', 'isEEActivated', { unit: 'boolean' });
this.registerGauge('call_dissemination', 'dissemination feature usage', 'disseminationCount');
this.registerGauge('active_drafts_count', 'number of active drafts', 'draftCount');
this.registerGauge('draft_creation_count', 'number of draft creation', 'draftCreationCount');
this.registerGauge('draft_validation_count', 'number of draft validation', 'draftValidationCount');
this.registerGauge('active_workbenches_count', 'number of active workbenches', 'workbenchCount');
this.registerGauge('workbench_upload_count', 'number of workbench upload - creation and updates', 'workbenchUploadCount');
this.registerGauge('workbench_draft_convertion_count', 'number of workbench to draft convertion', 'workbenchDraftConvertionCount');
this.registerGauge('workbench_validation_count', 'number of workbench validation', 'workbenchValidationCount');
this.registerGauge('call_nlq', 'NLQ feature usage', 'nlqQueryCount');
this.registerGauge('request_access_creation_count', 'Number of RFI of request access type that are created', 'requestAccessCreationCount');
}
Expand Down