Skip to content

Commit

Permalink
Send the status to collector_status service (#333)
Browse files Browse the repository at this point in the history
Co-authored-by: Rakhi <[email protected]>
  • Loading branch information
rakhimundhada15 and Rakhi authored Jun 22, 2023
1 parent 30edf57 commit 3b86f0e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alertlogic/paws-collector",
"version": "2.1.16",
"version": "2.1.17",
"license": "MIT",
"description": "Alert Logic AWS based API Poll Log Collector Library",
"repository": {
Expand Down Expand Up @@ -32,7 +32,7 @@
"yargs": "^17.6.2"
},
"dependencies": {
"@alertlogic/al-aws-collector-js": "4.1.15",
"@alertlogic/al-aws-collector-js": "4.1.16",
"async": "^3.2.4",
"datadog-lambda-js": "^6.85.0",
"debug": "^4.3.4",
Expand Down
16 changes: 8 additions & 8 deletions paws_collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ class PawsCollector extends AlAwsCollector {
// If stream exist in state then post the error status as part of stream specific ;
// In check-in or self-update we don't get state ,so check collector_streams env variable and post error as part of paws_{applicationId}_status
const streamType = pawsState && pawsState.priv_collector_state.stream ?
process.env.al_application_id + "_" + pawsState.priv_collector_state.stream :
pawsState.priv_collector_state.stream :
process.env.al_application_id;

super.done(error, streamType, sendStatus);
}

Expand Down Expand Up @@ -221,8 +221,8 @@ class PawsCollector extends AlAwsCollector {
return Object.assign(pawsProps, baseProps);
};

prepareErrorStatus(errorString, streamName = 'none', collectorType = this.pawsCollectorType) {
return super.prepareErrorStatus(errorString, streamName, collectorType);
prepareErrorStatus(errorString, collectorType = this.pawsCollectorType) {
return super.setCollectorStatus(collectorType, errorString);
}

setPawsSecret(secretValue){
Expand Down Expand Up @@ -511,14 +511,14 @@ class PawsCollector extends AlAwsCollector {

reportErrorStatus(error, pawsState, callback) {
const streamType = pawsState && pawsState.priv_collector_state.stream ?
process.env.al_application_id + "_" + pawsState.priv_collector_state.stream :
process.env.al_application_id;
pawsState.priv_collector_state.stream :
process.env.al_application_id;
const errorString = this.stringifyError(error);
const status = this.prepareErrorStatus(errorString, 'none', streamType);
const status = this.prepareErrorStatus(errorString, streamType);
// Send the error status to assets only if retry count reached to 5.
// To reduce the status fluctuation from healthy to unhealthy.
if (pawsState.retry_count === MAX_ERROR_RETRIES) {
this.sendStatus(status, (sendError) => {
this.sendCollectorStatus(streamType, status, (sendError) => {
return callback(sendError, errorString);
});
} else {
Expand Down
60 changes: 36 additions & 24 deletions test/paws_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ function setAlServiceStub() {
switch (path) {
case '/residency/default/services/ingest/endpoint':
ret = {
ingest : 'new-ingest-endpoint'
};
ingest: 'new-ingest-endpoint'
};
break;
case '/residency/default/services/azcollect/endpoint':
ret = {
azcollect: 'new-azcollect-endpoint'
};
break;
case '/residency/default/services/collector_status/endpoint':
ret = {
azcollect: 'new-collector-status-endpoint'
};
break;
default:
break;
case '/residency/default/services/azcollect/endpoint':
ret = {
azcollect : 'new-azcollect-endpoint'
};
break;
default:
break;
}
return resolve(ret);
});
Expand All @@ -44,6 +49,12 @@ function setAlServiceStub() {
return resolve();
});
});
alserviceStub.put = sinon.stub(m_alCollector.AlServiceC.prototype, 'put').callsFake(
function fakeFn(path, extraOptions) {
return new Promise(function (resolve, reject) {
return resolve();
});
});
alserviceStub.del = sinon.stub(m_alCollector.AlServiceC.prototype, 'deleteRequest').callsFake(
function fakeFn(path) {
return new Promise(function(resolve, reject) {
Expand All @@ -56,6 +67,7 @@ function restoreAlServiceStub() {
alserviceStub.get.restore();
alserviceStub.post.restore();
alserviceStub.del.restore();
alserviceStub.put.restore();
}


Expand Down Expand Up @@ -691,7 +703,7 @@ describe('Unit Tests', function() {
});
});

it('Check sendStatus method call only after Five failed attempt', function (done) {
it('Check sendCollectorStatus method call only after Five failed attempt', function (done) {
mockDDB();
let ctx = {
invokedFunctionArn: pawsMock.FUNCTION_ARN,
Expand All @@ -700,15 +712,15 @@ describe('Unit Tests', function() {
done();
},
succeed: function () {
sinon.assert.callCount(mockSendStatus, 1);
sinon.assert.callCount(mockSendCollectorStatus, 1);
sinon.assert.calledOnce(mockPawsGetLogs);
mockPawsGetLogs.restore();
mockSendStatus.restore();
mockSendCollectorStatus.restore();
done();
}
};
let mockSendStatus = sinon.stub(m_al_aws.AlAwsCollector.prototype, 'sendStatus').callsFake(
function fakeFn(status, callback) {
let mockSendCollectorStatus = sinon.stub(m_al_aws.AlAwsCollector.prototype, 'sendCollectorStatus').callsFake(
function fakeFn(stream,status, callback) {
return callback(null);
});

Expand All @@ -732,7 +744,7 @@ describe('Unit Tests', function() {
});
});

it('Check sendStatus method not call if failed attempt less < 5', function (done) {
it('Check sendCollectorStatus method not call if failed attempt less < 5', function (done) {
mockDDB();
let ctx = {
invokedFunctionArn: pawsMock.FUNCTION_ARN,
Expand All @@ -741,15 +753,15 @@ describe('Unit Tests', function() {
done();
},
succeed: function () {
sinon.assert.callCount(mockSendStatus, 0);
sinon.assert.callCount(mockSendCollectorStatus, 0);
sinon.assert.calledOnce(mockPawsGetLogs);
mockPawsGetLogs.restore();
mockSendStatus.restore();
mockSendCollectorStatus.restore();
done();
}
};
let mockSendStatus = sinon.stub(m_al_aws.AlAwsCollector.prototype, 'sendStatus').callsFake(
function fakeFn(status, callback) {
let mockSendCollectorStatus = sinon.stub(m_al_aws.AlAwsCollector.prototype, 'sendCollectorStatus').callsFake(
function fakeFn(stream,status, callback) {
return callback(null);
});

Expand All @@ -773,7 +785,7 @@ describe('Unit Tests', function() {
});
});

it('Check if retry_count get added in state for existing collector and it will not call sendStatus method', function (done) {
it('Check if retry_count get added in state for existing collector and it will not call mockSendCollectorStatus method', function (done) {
mockDDB();
let ctx = {
invokedFunctionArn: pawsMock.FUNCTION_ARN,
Expand All @@ -782,15 +794,15 @@ describe('Unit Tests', function() {
done();
},
succeed: function () {
sinon.assert.callCount(mockSendStatus, 0);
sinon.assert.callCount(mockSendCollectorStatus, 0);
sinon.assert.calledOnce(mockPawsGetLogs);
mockPawsGetLogs.restore();
mockSendStatus.restore();
mockSendCollectorStatus.restore();
done();
}
};
let mockSendStatus = sinon.stub(m_al_aws.AlAwsCollector.prototype, 'sendStatus').callsFake(
function fakeFn(status, callback) {
let mockSendCollectorStatus = sinon.stub(m_al_aws.AlAwsCollector.prototype, 'sendCollectorStatus').callsFake(
function fakeFn(stream, status, callback) {
return callback(null);
});

Expand Down

0 comments on commit 3b86f0e

Please sign in to comment.