-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add skeleton for DLBlob function. Fix typo Randomize DLBlob timer trigger Stringify blob json List blobs with prefix Refactor. Add DLBlob function implementation. Delete processed DL blob Fixes. Add DLBlob test skeleton Add DLBlob readme section. Fixes. Unit tests unfinished. * Change the way processed and skipped records are calculated. * Append unprocessed records. * Stringify DL. Add common ehub collector skeleton. * Add more DLBlob function tests * Address comments * Dedup tests.
- Loading branch information
kkuzmin
authored
Jan 29, 2019
1 parent
630d478
commit dc7a482
Showing
22 changed files
with
630 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "AlertlogicDLBlobTimer", | ||
"type": "timerTrigger", | ||
"direction": "in", | ||
"schedule": "0 */15 * * * *" | ||
} | ||
], | ||
"disabled": false | ||
} |
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,89 @@ | ||
/* ---------------------------------------------------------------------------- | ||
* @copyright (C) 2018, Alert Logic, Inc | ||
* @doc | ||
* | ||
* The purpose of this function is to process dead letter blobs generated by | ||
* EHubActivityLogs and EhubGeneral functions. | ||
* Dead letter blobs are located in 'alertlogic-dl' container located in the | ||
* web application storage account. | ||
* | ||
* @end | ||
* ---------------------------------------------------------------------------- | ||
*/ | ||
|
||
const async = require('async'); | ||
const azure = require('azure'); | ||
|
||
const ehubCollector = require('../common/ehub_collector'); | ||
const ehubActivityLogsFormat = require('../EHubActivityLogs/format').logRecord; | ||
const ehubGeneralFormat = require('../EHubGeneral/format').logRecord; | ||
|
||
const CONCURRENT_BLOB_PROCESS_NUM = 20; | ||
|
||
function getCollectorFunName(blobName) { | ||
return blobName.split('/')[1]; | ||
} | ||
|
||
var collectorProcessError = function(context, err, messages) { | ||
context.log.error('Error processing batch:', err); | ||
var skipped = messages.records ? messages.records.length : messages.length; | ||
return skipped; | ||
}; | ||
|
||
function processDLBlob(blobService, context, blob, callback) { | ||
context.log.verbose('Processing blob: ', blob.name); | ||
var collectorFormatFun; | ||
|
||
switch(getCollectorFunName(blob.name)) { | ||
case 'ehubactivitylogs': | ||
collectorFormatFun = ehubActivityLogsFormat; | ||
break; | ||
default: | ||
collectorFormatFun = ehubGeneralFormat; | ||
break; | ||
} | ||
|
||
async.waterfall([ | ||
function(callback) { | ||
return blobService.getBlobToText(process.env.APP_DL_CONTAINER_NAME, blob.name, callback); | ||
}, | ||
function(blobData, blobReq, blobResp, callback) { | ||
try { | ||
return ehubCollector(context, JSON.parse(blobData), collectorFormatFun, collectorProcessError, callback); | ||
} catch (ex) { | ||
return callback(ex); | ||
} | ||
}, | ||
function(result, callback) { | ||
if (result.skipped === 0) { | ||
return blobService.deleteBlob(process.env.APP_DL_CONTAINER_NAME, blob.name, callback); | ||
} else { | ||
return callback(null, result); | ||
} | ||
} | ||
], callback); | ||
} | ||
|
||
module.exports = function (context, AlertlogicDLBlobTimer) { | ||
const blobService = azure.createBlobService(process.env.AzureWebJobsStorage); | ||
const options = { | ||
maxResults: parseInt(process.env.DL_BLOB_PAGE_SIZE) | ||
}; | ||
blobService.listBlobsSegmentedWithPrefix( | ||
process.env.APP_DL_CONTAINER_NAME, | ||
process.env.WEBSITE_SITE_NAME, | ||
null, options, | ||
function(listErr, data) { | ||
if (listErr) { | ||
context.done(listErr); | ||
} else { | ||
context.log.verbose('Listed blobs: ', data.entries.length); | ||
async.eachLimit(data.entries, CONCURRENT_BLOB_PROCESS_NUM, function(blob, callback) { | ||
return processDLBlob(blobService, context, blob, callback); | ||
}, function(processErr) { | ||
context.done(processErr); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
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,29 @@ | ||
/* ----------------------------------------------------------------------------- | ||
* @copyright (C) 2018, Alert Logic, Inc | ||
* @doc | ||
* | ||
* The function to format records from 'insights-operational-logs' | ||
* @end | ||
* ----------------------------------------------------------------------------- | ||
*/ | ||
|
||
const parse = require('../common/parse'); | ||
|
||
const logRecord = function(msg) { | ||
const ts = parse.getMsgTs(msg); | ||
const typeId = parse.getMsgTypeId(msg); | ||
return { | ||
messageTs: ts.sec, | ||
priority: 11, | ||
progName: 'EHubActivityLogs', | ||
pid: undefined, | ||
message: JSON.stringify(msg), | ||
messageType: 'json/azure.ehub', | ||
messageTypeId: typeId, | ||
messageTsUs: ts.usec | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
logRecord: logRecord | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ----------------------------------------------------------------------------- | ||
* @copyright (C) 2018, Alert Logic, Inc | ||
* @doc | ||
* | ||
* The function to format 'alertlogic-log' records. | ||
* | ||
* @end | ||
* ----------------------------------------------------------------------------- | ||
*/ | ||
|
||
const parse = require('../common/parse'); | ||
|
||
const logRecord = function(msg) { | ||
const ts = parse.getMsgTs(msg); | ||
const typeId = parse.getMsgTypeId(msg); | ||
return { | ||
messageTs: ts.sec, | ||
priority: 11, | ||
progName: 'EHubGeneral', | ||
pid: undefined, | ||
message: JSON.stringify(msg), | ||
messageType: 'json/azure.ehub', | ||
messageTypeId: typeId, | ||
messageTsUs: ts.usec | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
logRecord: logRecord | ||
}; | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
$date = Get-Date | ||
$min = ($date.Minute + 1) % 15 | ||
$sec = $date.Second | ||
$new_schedule = "$sec $min-59/15 * * * *" | ||
Write-Output "Updating DLBlob timer trigger with ($new_schedule)." | ||
$dlblob_function = Get-Content '..\\wwwroot\\DLBlob\\function.json' -raw | ConvertFrom-Json | ||
$dlblob_function.bindings | % {if($_.name -eq 'AlertlogicDLBlobTimer'){$_.schedule=$new_schedule}} | ||
$dlblob_function | ConvertTo-Json | set-content '..\\wwwroot\\DLBlob\\function.json' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,11 @@ Collected JSON objects are wrapped into the protobuf [structure](https://github. | |
The `EHubGeneral` function listens to `alertlogic-log` which is created during [collector setup](#deploy-with-the-custom-arm-template-in-an-azure-subscription). The `alertlogicloghub` event hub can be used for integration with, for example, [diagnostic logs](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-logs-stream-event-hubs) or [Azure AD logs](https://docs.microsoft.com/en-us/azure/active-directory/reports-monitoring/tutorial-azure-monitor-stream-logs-to-event-hub). | ||
Collected JSON objects are wrapped into the protobuf [structure](https://github.com/alertlogic/al-collector-js/blob/master/proto/common_proto.piqi.proto) and then are forwarded to the Alert Logic Ingestion service. | ||
## DLBlob Function | ||
Both `EHubActivityLogs` and `EHubGeneral` may not be able to process incoming event hub records. If that happens then unprocessed messages are saved as blobs to the `alertlogic-dl` container so that collection can be retried at a later time. The `alertlogic-dl` container is located in the collector web application storage account which is created durign collector setup. | ||
The `DLBlob` function processes dead letter blobs very 15 minutes. The `DLBlob` function lists all blobs located in `alertlogic-dl` container and processes them according to the function which dead letter blob belongs to. Once a blob is processed it gets removed from the container. | ||
# Local Development | ||
1. Clone the repo `git clone [email protected]:alertlogic/ehub-collector.git`. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,6 @@ | |
"nyc": "^11.3.0", | ||
"pre-commit": "^1.2.2", | ||
"rewire": "^2.5.2", | ||
"sinon": "^3.3.0" | ||
"sinon": "^7.2.3" | ||
} | ||
} |
Oops, something went wrong.