-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] Introducing profiling capability with pyroscope
- Loading branch information
1 parent
b045d0f
commit 29dded4
Showing
17 changed files
with
314 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
opencti-platform/opencti-graphql/patch/@datadog-pprof-5.4.1.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
diff --git a/out/src/time-profiler-bindings.js b/out/src/time-profiler-bindings.js | ||
index d6d3f23..b7da0d7 100644 | ||
--- a/out/src/time-profiler-bindings.js | ||
+++ b/out/src/time-profiler-bindings.js | ||
@@ -18,7 +18,7 @@ exports.getNativeThreadId = exports.constants = exports.TimeProfiler = void 0; | ||
*/ | ||
const path_1 = require("path"); | ||
const findBinding = require('node-gyp-build'); | ||
-const profiler = findBinding((0, path_1.join)(__dirname, '..', '..')); | ||
+const profiler = findBinding((0, path_1.join)(__dirname, '..', 'build')); | ||
exports.TimeProfiler = profiler.TimeProfiler; | ||
exports.constants = profiler.constants; | ||
exports.getNativeThreadId = profiler.getNativeThreadId; | ||
diff --git a/out/src/heap-profiler-bindings.js b/out/src/heap-profiler-bindings.js | ||
index 25157fb..8838bec 100644 | ||
--- a/out/src/heap-profiler-bindings.js | ||
+++ b/out/src/heap-profiler-bindings.js | ||
@@ -41,7 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.monitorOutOfMemory = exports.getAllocationProfile = exports.stopSamplingHeapProfiler = exports.startSamplingHeapProfiler = void 0; | ||
const path = __importStar(require("path")); | ||
const findBinding = require('node-gyp-build'); | ||
-const profiler = findBinding(path.join(__dirname, '..', '..')); | ||
+const profiler = findBinding(path.join(__dirname, '..', 'build')); | ||
// Wrappers around native heap profiler functions. | ||
function startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth) { | ||
profiler.heapProfiler.startSamplingHeapProfiler(heapIntervalBytes, heapStackDepth); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
opencti-platform/opencti-graphql/src/graphql/tracingPlugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { head, includes } from 'ramda'; | ||
import { SEMATTRS_DB_OPERATION, SEMATTRS_ENDUSER_ID, SEMATTRS_MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES } from '@opentelemetry/semantic-conventions'; | ||
import { AUTH_FAILURE, AUTH_REQUIRED, FORBIDDEN_ACCESS } from '../config/errors'; | ||
import { isEmptyField } from '../database/utils'; | ||
|
||
const getRequestError = (context) => { | ||
const isSuccess = isEmptyField(context.errors) || context.errors.length === 0; | ||
if (isSuccess) { | ||
return undefined; | ||
} | ||
const currentError = head(context.errors); | ||
const callError = currentError.originalError ? currentError.originalError : currentError; | ||
const isAuthenticationCall = includes(callError.name, [AUTH_REQUIRED, AUTH_FAILURE, FORBIDDEN_ACCESS]); | ||
if (isAuthenticationCall) { | ||
return undefined; | ||
} | ||
return callError; | ||
}; | ||
|
||
// noinspection JSUnusedGlobalSymbols | ||
export default { | ||
requestDidStart: /* v8 ignore next */ () => { | ||
let tracingSpan; | ||
return { | ||
didResolveOperation: (resolveContext) => { | ||
const isWrite = resolveContext.operation && resolveContext.operation.operation === 'mutation'; | ||
const operationType = `${isWrite ? 'INSERT' : 'SELECT'}`; | ||
const { contextValue: context } = resolveContext; | ||
const endUserId = context.user?.origin?.user_id ?? 'anonymous'; | ||
tracingSpan = context.tracing.getTracer().startSpan(`${operationType} ${resolveContext.operationName}`, { | ||
attributes: { | ||
'enduser.type': context.source, | ||
[SEMATTRS_DB_OPERATION]: operationType, | ||
[SEMATTRS_ENDUSER_ID]: endUserId, | ||
}, | ||
kind: 1, | ||
}); | ||
context.tracing.setCurrentCtx(tracingSpan); | ||
}, | ||
willSendResponse: async (sendContext) => { | ||
if (tracingSpan) { // Tracing span can be null for invalid operations | ||
const requestError = getRequestError(sendContext); | ||
const payloadSize = Buffer.byteLength(JSON.stringify(sendContext.request.variables || {})); | ||
tracingSpan.setAttribute(SEMATTRS_MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES, payloadSize); | ||
if (requestError) { | ||
tracingSpan.setStatus({ code: 2, message: requestError.name }); | ||
} else { | ||
tracingSpan.setStatus({ code: 1 }); | ||
} | ||
tracingSpan.end(); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.