44// Non-evaluation use of Artillery on Azure requires a commercial license
55
66const { QueueClient } = require ( '@azure/storage-queue' ) ;
7+ const { BlobServiceClient } = require ( '@azure/storage-blob' ) ;
78const { DefaultAzureCredential } = require ( '@azure/identity' ) ;
9+ const { randomUUID } = require ( 'node:crypto' ) ;
810
911function getAQS ( ) {
1012 return new QueueClient (
@@ -13,16 +15,65 @@ function getAQS() {
1315 ) ;
1416}
1517
16- function sendMessage ( queue , body , tags ) {
18+ // Azure Queue Storage has a 64KB message limit
19+ // Use 60KB threshold to leave margin for encoding overhead
20+ const AQS_SIZE_LIMIT = 60 * 1024 ;
21+
22+ let blobContainerClient = null ;
23+
24+ function getBlobClient ( ) {
25+ if ( ! blobContainerClient ) {
26+ const storageAccount = process . env . AZURE_STORAGE_ACCOUNT ;
27+ const containerName = process . env . AZURE_STORAGE_BLOB_CONTAINER ;
28+ if ( ! storageAccount || ! containerName ) {
29+ throw new Error (
30+ 'AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_BLOB_CONTAINER must be set'
31+ ) ;
32+ }
33+ const blobServiceClient = new BlobServiceClient (
34+ `https://${ storageAccount } .blob.core.windows.net` ,
35+ new DefaultAzureCredential ( )
36+ ) ;
37+ blobContainerClient = blobServiceClient . getContainerClient ( containerName ) ;
38+ }
39+ return blobContainerClient ;
40+ }
41+
42+ async function sendMessage ( queue , body , tags ) {
1743 const payload = JSON . stringify ( {
1844 payload : body ,
19- // attributes: this.tags
2045 attributes : tags . reduce ( ( acc , tag ) => {
2146 acc [ tag . key ] = tag . value ;
2247 return acc ;
2348 } , { } )
2449 } ) ;
2550
51+ // Check if payload exceeds Azure Queue Storage limit
52+ if ( Buffer . byteLength ( payload , 'utf8' ) > AQS_SIZE_LIMIT ) {
53+ // Upload to blob storage and send reference
54+ const testId = tags . find ( ( t ) => t . key === 'testId' ) ?. value ;
55+ const workerId = tags . find ( ( t ) => t . key === 'workerId' ) ?. value ;
56+ const messageId = randomUUID ( ) ;
57+ const blobName = `tests/${ testId } /overflow/${ workerId } /${ messageId } .json` ;
58+
59+ const blobClient = getBlobClient ( ) . getBlockBlobClient ( blobName ) ;
60+ await blobClient . upload ( payload , Buffer . byteLength ( payload , 'utf8' ) ) ;
61+
62+ // Send reference message
63+ const refPayload = JSON . stringify ( {
64+ payload : {
65+ _overflowRef : blobName ,
66+ event : body . event
67+ } ,
68+ attributes : tags . reduce ( ( acc , tag ) => {
69+ acc [ tag . key ] = tag . value ;
70+ return acc ;
71+ } , { } )
72+ } ) ;
73+
74+ return queue . sendMessage ( refPayload ) ;
75+ }
76+
2677 return queue . sendMessage ( payload ) ;
2778}
2879
0 commit comments