Skip to content

Commit c08444f

Browse files
author
kkuzmin
authored
Report DL stats during checkin (#16)
* Report DL stats during checkin * Use 0 for initial max blob size * Bump package version
1 parent cc9029a commit c08444f

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

dlblob.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@ class AlAzureDlBlob {
5252
return this._blobService;
5353
};
5454

55+
_findMaxDlBlobSize(dlblobs) {
56+
var len = dlblobs.length, max = 0;
57+
while (len--) {
58+
const contentLen = Number(dlblobs[len].contentLength);
59+
if (contentLen > max) {
60+
max = contentLen;
61+
}
62+
}
63+
return max;
64+
}
65+
66+
/**
67+
* @function Retrievs the first page (5000) of dead letter blobs and finds the one with the maximum size.
68+
*
69+
* @param callback
70+
* @returns callback
71+
*/
72+
getDlBlobStats(callback) {
73+
var dlblob = this;
74+
return dlblob._blobService.listBlobsSegmentedWithPrefix(
75+
dlblob._dlContainerName,
76+
process.env.WEBSITE_SITE_NAME,
77+
null, function(listErr, dlblobList) {
78+
if (listErr) {
79+
return callback(listErr);
80+
} else {
81+
const dlstats = {
82+
dl_stats: {
83+
dl_count: dlblobList.entries.length,
84+
max_dl_size: dlblob._findMaxDlBlobSize(dlblobList.entries)
85+
}
86+
};
87+
return callback(null, dlstats);
88+
}
89+
});
90+
};
91+
5592
processDlBlobs(timer, callback) {
5693
var dlblob = this;
5794
const options = {

master.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const alcollector = require('@alertlogic/al-collector-js');
2020
const m_util = require('./util');
2121
const AzureWebAppStats = require('./appstats').AzureWebAppStats;
2222
const AzureCollectionStats = require('./appstats').AzureCollectionStats;
23+
const AlAzureDlBlob = require('./dlblob').AlAzureDlBlob;
2324

2425
const MASTER_RETRY_OPTS = {
2526
factor: 2,
@@ -133,6 +134,7 @@ class AlAzureMaster {
133134
this._azureWebsiteClient = new azureArmWebsite(this._azureCreds, this._subscriptionId);
134135
this._appStats = new AzureWebAppStats(collectorAzureFunNames);
135136
this._collectionStats = new AzureCollectionStats(azureContext, {outputQueueBinding: OutputStatsBinding});
137+
this._alAzureDlBlob = new AlAzureDlBlob(azureContext, null);
136138
}
137139

138140
getApplicationTokenCredentials(){
@@ -330,6 +332,9 @@ class AlAzureMaster {
330332
}
331333
return callback(err, result);
332334
});
335+
}),
336+
async.reflect(function(callback) {
337+
return master._alAzureDlBlob.getDlBlobStats(callback);
333338
})
334339
],
335340
function(err, results){

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alertlogic/al-azure-collector-js",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Alert Logic Azure Collector Common Library",
55
"license": "MIT",
66
"repository": {

test/master_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ describe('Master tests', function() {
380380
.times(100)
381381
.reply(204,'');
382382

383+
// List blobs
384+
nock('https://testappo365.blob.core.windows.net:443', {'encodedQueryParams':true})
385+
.get('/alertlogic-dl')
386+
.query(true)
387+
.times(5)
388+
.reply(200, mock.LIST_CONTAINER_BLOBS());
389+
383390
// Mock Alert Logic HTTP calls
384391
fakePost = sinon.stub(alcollector.AlServiceC.prototype, 'post').callsFake(
385392
function fakeFn(path, extraOptions) {
@@ -402,6 +409,7 @@ describe('Master tests', function() {
402409
process.env.APP_AZCOLLECT_ENDPOINT = 'existing-azcollect-endpoint';
403410
process.env.COLLECTOR_HOST_ID = 'existing-host-id';
404411
process.env.COLLECTOR_SOURCE_ID = 'existing-source-id';
412+
process.env.APP_DL_CONTAINER_NAME = 'alertlogic-dl';
405413

406414
// Expected Azure parameters
407415
process.env.WEBSITE_SITE_NAME = 'kktest11-name';
@@ -434,6 +442,7 @@ describe('Master tests', function() {
434442
host_id: 'existing-host-id',
435443
source_id: 'existing-source-id',
436444
statistics: [{ 'Master': { 'errors': 0, 'invocations': 2 } }, { 'Collector': { 'errors': 1, 'invocations': 10 } }, { 'Updater': { 'errors': 0, 'invocations': 0 } }],
445+
dl_stats: { dl_count: 6, max_dl_size: 4257 },
437446
status: 'ok',
438447
details: []
439448
}
@@ -466,6 +475,7 @@ describe('Master tests', function() {
466475
host_id: 'existing-host-id',
467476
source_id: 'existing-source-id',
468477
statistics: [{ 'Master': { 'errors': 0, 'invocations': 2 } }, { 'Collector': { 'errors': 1, 'invocations': 10 } }, { 'Updater': { 'errors': 0, 'invocations': 0 } }],
478+
dl_stats: { dl_count: 6, max_dl_size: 4257 },
469479
status: 'error',
470480
details: ['Azure Web Application status is not OK. {\"availabilityState\":\"Limited\"}'],
471481
error_code: 'ALAZU00001'
@@ -498,6 +508,7 @@ describe('Master tests', function() {
498508
host_id: 'existing-host-id',
499509
source_id: 'existing-source-id',
500510
statistics: [{ 'Master': { 'errors': 0, 'invocations': 2 } }, { 'Collector': { 'errors': 1, 'invocations': 10 } }, { 'Updater': { 'errors': 0, 'invocations': 0 } }],
511+
dl_stats: { dl_count: 6, max_dl_size: 4257 },
501512
status: 'ok',
502513
details: []
503514
}
@@ -528,6 +539,7 @@ describe('Master tests', function() {
528539
host_id: 'existing-host-id',
529540
source_id: 'existing-source-id',
530541
statistics: [{ 'Master': { 'errors': 0, 'invocations': 2 } }, { 'Collector': { 'errors': 1, 'invocations': 10 } }, { 'Updater': { 'errors': 0, 'invocations': 0 } }],
542+
dl_stats: { dl_count: 6, max_dl_size: 4257 },
531543
status: 'error',
532544
details: ['Custom Error'],
533545
error_code: 'ALAZU000004'

0 commit comments

Comments
 (0)