Skip to content

Commit 8574c35

Browse files
[backend] add more telemetry data for draft & workbenches (#11014)
1 parent a67385c commit 8574c35

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

opencti-platform/opencti-graphql/src/domain/connector.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { controlUserConfidenceAgainstElement } from '../utils/confidence-level';
3636
import { extractEntityRepresentativeName } from '../database/entity-representative';
3737
import type { BasicStoreCommon } from '../types/store';
3838
import type { Connector } from '../connector/internalConnector';
39+
import { addWorkbenchDraftConvertionCount, addWorkbenchValidationCount } from '../manager/telemetryManager';
3940

4041
// region connectors
4142
export const connectorForWork = async (context: AuthContext, user: AuthUser, id: string) => {
@@ -416,6 +417,13 @@ export const askJobImport = async (
416417
controlUserConfidenceAgainstElement(user, entity);
417418
}
418419
const connectorsForFile = await uploadJobImport(context, user, file, entityId, opts);
420+
if (file.id.startsWith('import/pending')) {
421+
if (args.forceValidation && args.validationMode === 'draft') {
422+
await addWorkbenchDraftConvertionCount();
423+
} else if (args.bypassValidation) {
424+
await addWorkbenchValidationCount();
425+
}
426+
}
419427
const entityName = entityId ? extractEntityRepresentativeName(entity) : 'global';
420428
const entityType = entityId ? entity.entity_type : 'global';
421429
const baseData: UserImportActionContextData = {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { getDraftContext } from '../utils/draftContext';
2323
import { UnsupportedError } from '../config/errors';
2424
import { isDraftFile } from '../database/draft-utils';
2525
import { askJobImport } from './connector';
26+
import { addWorkbenchUploadCount } from '../manager/telemetryManager';
2627

2728
export const buildOptionsFromFileManager = async (context) => {
2829
let importPaths = ['import/'];
@@ -129,6 +130,7 @@ export const uploadPending = async (context, user, args) => {
129130

130131
const { upload: up } = await uploadToStorage(context, user, 'import/pending', finalFile, { meta, file_markings, errorOnExisting, entity });
131132
const contextData = buildContextDataForFile(entity, 'import/pending', up.name, up.metaData.file_markings);
133+
await addWorkbenchUploadCount();
132134
await publishUserAction({
133135
user,
134136
event_type: 'file',

opencti-platform/opencti-graphql/src/manager/telemetryManager.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,36 @@ const COMPUTE_SCHEDULE_TIME = DEV_MODE ? ONE_MINUTE / 2 : ONE_HOUR / 2;
4545
export const TELEMETRY_GAUGE_DISSEMINATION = 'disseminationCount';
4646
export const TELEMETRY_GAUGE_NLQ = 'nlqQueryCount';
4747
export const TELEMETRY_GAUGE_REQUEST_ACCESS = 'requestAccessCreationCount';
48+
export const TELEMETRY_GAUGE_DRAFT_CREATION = 'draftCreationCount';
49+
export const TELEMETRY_GAUGE_DRAFT_VALIDATION = 'draftValidationCount';
50+
export const TELEMETRY_GAUGE_WORKBENCH_UPLOAD = 'workbenchUploadCount';
51+
export const TELEMETRY_GAUGE_WORKBENCH_DRAFT_CONVERTION = 'workbenchDraftConvertionCount';
52+
export const TELEMETRY_GAUGE_WORKBENCH_VALIDATION = 'workbenchValidationCount';
4853

4954
export const addDisseminationCount = async () => {
5055
await redisSetTelemetryAdd(TELEMETRY_GAUGE_DISSEMINATION, 1);
5156
};
5257
export const addNlqQueryCount = async () => {
5358
await redisSetTelemetryAdd(TELEMETRY_GAUGE_NLQ, 1);
5459
};
55-
5660
export const addRequestAccessCreationCount = async () => {
5761
await redisSetTelemetryAdd(TELEMETRY_GAUGE_REQUEST_ACCESS, 1);
5862
};
63+
export const addDraftCreationCount = async () => {
64+
await redisSetTelemetryAdd(TELEMETRY_GAUGE_DRAFT_CREATION, 1);
65+
};
66+
export const addDraftValidationCount = async () => {
67+
await redisSetTelemetryAdd(TELEMETRY_GAUGE_DRAFT_VALIDATION, 1);
68+
};
69+
export const addWorkbenchUploadCount = async () => {
70+
await redisSetTelemetryAdd(TELEMETRY_GAUGE_WORKBENCH_UPLOAD, 1);
71+
};
72+
export const addWorkbenchDraftConvertionCount = async () => {
73+
await redisSetTelemetryAdd(TELEMETRY_GAUGE_WORKBENCH_DRAFT_CONVERTION, 1);
74+
};
75+
export const addWorkbenchValidationCount = async () => {
76+
await redisSetTelemetryAdd(TELEMETRY_GAUGE_WORKBENCH_VALIDATION, 1);
77+
};
5978

6079
// End Region user event counters
6180

@@ -171,6 +190,16 @@ export const fetchTelemetryData = async (manager: TelemetryMeterManager) => {
171190
manager.setNlqQueryCount(nlqQueryCountInRedis);
172191
const requestAccessCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_REQUEST_ACCESS);
173192
manager.setRequestAccessCreatedCount(requestAccessCountInRedis);
193+
const draftCreationCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_DRAFT_CREATION);
194+
manager.setDraftCreationCount(draftCreationCountInRedis);
195+
const draftValidationCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_DRAFT_VALIDATION);
196+
manager.setDraftValidationCount(draftValidationCountInRedis);
197+
const workbenchUploadCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_WORKBENCH_UPLOAD);
198+
manager.setWorkbenchUploadCount(workbenchUploadCountInRedis);
199+
const workbenchDraftConvertionCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_WORKBENCH_DRAFT_CONVERTION);
200+
manager.setWorkbenchDraftConvertionCount(workbenchDraftConvertionCountInRedis);
201+
const workbenchValidationCountInRedis = await redisGetTelemetry(TELEMETRY_GAUGE_WORKBENCH_VALIDATION);
202+
manager.setWorkbenchValidationCount(workbenchValidationCountInRedis);
174203
// end region Telemetry user events
175204
logApp.debug('[TELEMETRY] Fetching telemetry data successfully');
176205
} catch (e) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { STIX_EXT_OCTI } from '../../types/stix-2-1-extensions';
3939
import { DRAFT_STATUS_OPEN, DRAFT_STATUS_VALIDATED } from './draftStatuses';
4040
import { notify } from '../../database/redis';
4141
import { publishUserAction } from '../../listener/UserActionListener';
42+
import { addDraftCreationCount, addDraftValidationCount } from '../../manager/telemetryManager';
4243

4344
export const findById = (context: AuthContext, user: AuthUser, id: string) => {
4445
return storeLoadById<BasicStoreEntityDraftWorkspace>(context, user, id, ENTITY_TYPE_DRAFT_WORKSPACE);
@@ -184,6 +185,7 @@ export const addDraftWorkspace = async (context: AuthContext, user: AuthUser, in
184185
};
185186
const draftWorkspaceInput = { ...input, ...defaultOps };
186187
const createdDraftWorkspace = await createEntity(context, user, draftWorkspaceInput, ENTITY_TYPE_DRAFT_WORKSPACE);
188+
await addDraftCreationCount();
187189
await publishUserAction({
188190
user,
189191
event_type: 'mutation',
@@ -340,5 +342,7 @@ export const validateDraftWorkspace = async (context: AuthContext, user: AuthUse
340342
await notify(BUS_TOPICS[ENTITY_TYPE_DRAFT_WORKSPACE].EDIT_TOPIC, element, user);
341343
await deleteDraftContextFromUsers(context, user, draft_id);
342344

345+
await addDraftValidationCount();
346+
343347
return work;
344348
};

opencti-platform/opencti-graphql/src/telemetry/TelemetryMeterManager.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ export class TelemetryMeterManager {
2424
// Number of active drafts
2525
draftCount = 0;
2626

27+
draftCreationCount = 0;
28+
29+
draftValidationCount = 0;
30+
2731
// Number of active workbenches
2832
workbenchCount = 0;
2933

34+
workbenchUploadCount = 0;
35+
36+
workbenchDraftConvertionCount = 0;
37+
38+
workbenchValidationCount = 0;
39+
3040
// Number of NLQ query call
3141
nlqQueryCount = 0;
3242

@@ -65,10 +75,30 @@ export class TelemetryMeterManager {
6575
this.draftCount = n;
6676
}
6777

78+
setDraftCreationCount(n: number) {
79+
this.draftCreationCount = n;
80+
}
81+
82+
setDraftValidationCount(n: number) {
83+
this.draftValidationCount = n;
84+
}
85+
6886
setWorkbenchCount(n: number) {
6987
this.workbenchCount = n;
7088
}
7189

90+
setWorkbenchUploadCount(n: number) {
91+
this.workbenchUploadCount = n;
92+
}
93+
94+
setWorkbenchDraftConvertionCount(n: number) {
95+
this.workbenchDraftConvertionCount = n;
96+
}
97+
98+
setWorkbenchValidationCount(n: number) {
99+
this.workbenchValidationCount = n;
100+
}
101+
72102
setNlqQueryCount(n: number) {
73103
this.nlqQueryCount = n;
74104
}
@@ -97,7 +127,12 @@ export class TelemetryMeterManager {
97127
this.registerGauge('is_enterprise_edition', 'enterprise Edition is activated', 'isEEActivated', { unit: 'boolean' });
98128
this.registerGauge('call_dissemination', 'dissemination feature usage', 'disseminationCount');
99129
this.registerGauge('active_drafts_count', 'number of active drafts', 'draftCount');
130+
this.registerGauge('draft_creation_count', 'number of draft creation', 'draftCreationCount');
131+
this.registerGauge('draft_validation_count', 'number of draft validation', 'draftValidationCount');
100132
this.registerGauge('active_workbenches_count', 'number of active workbenches', 'workbenchCount');
133+
this.registerGauge('workbench_upload_count', 'number of workbench upload - creation and updates', 'workbenchUploadCount');
134+
this.registerGauge('workbench_draft_convertion_count', 'number of workbench to draft convertion', 'workbenchDraftConvertionCount');
135+
this.registerGauge('workbench_validation_count', 'number of workbench validation', 'workbenchValidationCount');
101136
this.registerGauge('call_nlq', 'NLQ feature usage', 'nlqQueryCount');
102137
this.registerGauge('request_access_creation_count', 'Number of RFI of request access type that are created', 'requestAccessCreationCount');
103138
}

0 commit comments

Comments
 (0)