Skip to content

Commit bd019da

Browse files
authored
[azure] Add max sockets configuration (#760)
* add max sockets configuration * up default max sockets to align with maximum SNAT port allocations * add keep alive and update documentation
1 parent 1a5d1db commit bd019da

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

azure/activity_logs_monitoring/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ const DD_PARSE_DEFENDER_LOGS = process.env.DD_PARSE_DEFENDER_LOGS; // Boolean wh
3232
const MAX_RETRIES = 4; // max number of times to retry a single http request
3333
const RETRY_INTERVAL = 250; // amount of time (milliseconds) to wait before retrying request, doubles after every retry
3434

35+
/*
36+
The MAX_SOCKETS setting is to help prevent intermittent outbound connection errors due to SNAT port exhaustion.
37+
The default pre-allocated amount from Azure is 128. We have set it here to 1024 to avoid
38+
degrading customers who have different Azure App Service plans that may have higher limits.
39+
40+
For more information, see these resources:
41+
https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-intermittent-outbound-connection-errors#cause
42+
https://learn.microsoft.com/en-us/azure/azure-functions/manage-connections?tabs=javascript#connection-limit
43+
https://azure.microsoft.com/en-us/blog/azure-load-balancer-to-become-more-efficient/
44+
45+
*/
46+
const MAX_SOCKETS = Number(process.env.MAX_SOCKETS || 1024); // max number of sockets to use for http requests
47+
const KEEP_ALIVE_AGENT = new https.Agent({
48+
keepAlive: true,
49+
maxSockets: MAX_SOCKETS,
50+
});
51+
3552
// constants relating to Defender for Cloud logs
3653
const MSFT_DEFENDER_FOR_CLOUD = 'Microsoft Defender for Cloud';
3754
const AZURE_SECURITY_CENTER = 'Azure Security Center';
@@ -163,7 +180,8 @@ class HTTPClient {
163180
'DD-API-KEY': DD_API_KEY,
164181
'DD-EVP-ORIGIN': 'azure'
165182
},
166-
timeout: DD_REQUEST_TIMEOUT_MS
183+
timeout: DD_REQUEST_TIMEOUT_MS,
184+
agent: KEEP_ALIVE_AGENT
167185
};
168186
this.scrubber = new Scrubber(this.context, SCRUBBER_RULE_CONFIGS);
169187
this.batcher = new Batcher(

0 commit comments

Comments
 (0)