@opensearch-project/opensearch
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -181,3 +181,4 @@ /* | ||
opaqueIdPrefix: options.opaqueIdPrefix, | ||
context: options.context | ||
context: options.context, | ||
memoryCircuitBreaker: options.memoryCircuitBreaker | ||
}) | ||
@@ -184,0 +185,0 @@ |
@@ -118,2 +118,3 @@ /* | ||
} | ||
operation: Action | ||
document: TDocument | ||
@@ -120,0 +121,0 @@ retried: boolean |
@@ -54,2 +54,3 @@ /* | ||
const MAX_STRING_LENGTH = buffer.constants.MAX_STRING_LENGTH | ||
const HEAP_SIZE_LIMIT = require('v8').getHeapStatistics().heap_size_limit | ||
const kCompatibleCheck = Symbol('compatible check') | ||
@@ -85,2 +86,3 @@ const kApiVersioning = Symbol('api versioning') | ||
this[kApiVersioning] = process.env.OPENSEARCH_CLIENT_APIVERSIONING === 'true' | ||
this.memoryCircuitBreaker = opts.memoryCircuitBreaker | ||
@@ -252,6 +254,6 @@ this.nodeFilter = opts.nodeFilter || defaultNodeFilter | ||
const isCompressed = contentEncoding.indexOf('gzip') > -1 || contentEncoding.indexOf('deflate') > -1 | ||
/* istanbul ignore else */ | ||
if (result.headers['content-length'] !== undefined) { | ||
const contentLength = Number(result.headers['content-length']) | ||
// nodeJS data type limit check | ||
if (isCompressed && contentLength > MAX_BUFFER_LENGTH) { | ||
@@ -267,2 +269,8 @@ response.destroy() | ||
) | ||
} else if (shouldApplyCircuitBreaker(contentLength)) { | ||
// Abort this response to avoid OOM crash of dashboards. | ||
response.destroy() | ||
return onConnectionError( | ||
new RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed heap memory limit.`, result) | ||
) | ||
} | ||
@@ -308,2 +316,9 @@ } | ||
} | ||
// Helper function to check if memory circuit breaker enabled and the response payload is too large to fit into available heap memory. | ||
const shouldApplyCircuitBreaker = (contentLength) => { | ||
if (!this.memoryCircuitBreaker || !this.memoryCircuitBreaker.enabled) return false | ||
const maxPercentage = validateMemoryPercentage(this.memoryCircuitBreaker.maxPercentage) | ||
const heapUsed = process.memoryUsage().heapUsed | ||
return contentLength + heapUsed > HEAP_SIZE_LIMIT * maxPercentage | ||
} | ||
@@ -644,2 +659,7 @@ const onBody = (err, payload) => { | ||
function validateMemoryPercentage (percentage) { | ||
if (percentage < 0 || percentage > 1) return 1.0 | ||
return percentage | ||
} | ||
module.exports = Transport | ||
@@ -646,0 +666,0 @@ module.exports.internals = { |
@@ -14,3 +14,3 @@ { | ||
"homepage": "https://www.opensearch.org/", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"versionCanary": "7.10.0-canary.6", | ||
@@ -17,0 +17,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1026553
21249
3