Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Create log groups when missing #184

Merged
merged 2 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/cloudwatch-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ lib.upload = function(aws, groupName, streamName, logEvents, retentionInDays, op
// InvalidSequenceToken means we need to do a describe to get another token
// also do the same if ResourceNotFound as that will result in the last token
// for the group being set to null
if (err.code === 'InvalidSequenceTokenException' || err.code === 'ResourceNotFoundException') {
if (err.name === 'InvalidSequenceTokenException' || err.name === 'ResourceNotFoundException') {
debug(err.name + ', retrying', true);
lib.submitWithAnotherToken(aws, groupName, streamName, payload, retentionInDays, options, cb)
} else {
Expand Down Expand Up @@ -162,7 +162,7 @@ lib.ensureGroupPresent = function ensureGroupPresent(aws, name, retentionInDays,
var params = { logGroupName: name };
aws.describeLogStreams(params, function(err, data) {
// TODO we should cb(err, false) if there's an error?
if (err && err.code == 'ResourceNotFoundException') {
if (err && err.name == 'ResourceNotFoundException') {
debug('create group');
return aws.createLogGroup(params, lib.ignoreInProgress(function(err) {
if(!err) lib.putRetentionPolicy(aws, name, retentionInDays);
Expand Down Expand Up @@ -219,8 +219,8 @@ lib.getStream = function getStream(aws, groupName, streamName, cb) {

lib.ignoreInProgress = function ignoreInProgress(cb) {
return function(err, data) {
if (err && (err.code == 'OperationAbortedException' ||
err.code == 'ResourceAlreadyExistsException')) {
if (err && (err.name == 'OperationAbortedException' ||
err.name == 'ResourceAlreadyExistsException')) {
debug('ignore operation in progress', err.message);
cb(null, data);
} else {
Expand Down
16 changes: 8 additions & 8 deletions test/cloudwatch-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('cloudwatch-integration', function() {
});

it('gets another token if InvalidSequenceTokenException', function(done) {
aws.putLogEvents.yields({ code: 'InvalidSequenceTokenException' });
aws.putLogEvents.yields({ name: 'InvalidSequenceTokenException' });
lib.upload(aws, 'group', 'stream', Array(20), 0, {
ensureGroupPresent: true
}, function(err) {
Expand All @@ -186,7 +186,7 @@ describe('cloudwatch-integration', function() {
});

it('gets another token if ResourceNotFoundException', function(done) {
aws.putLogEvents.yields({ code: 'InvalidSequenceTokenException' });
aws.putLogEvents.yields({ name: 'InvalidSequenceTokenException' });
lib.upload(aws, 'group', 'stream', Array(20), 0, {
ensureGroupPresent: true
}, function(err) {
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('cloudwatch-integration', function() {
});

it('creates a group if it is not present', function(done) {
var err = { code: 'ResourceNotFoundException' };
var err = { name: 'ResourceNotFoundException' };
aws.describeLogStreams = sinon.stub().yields(err);
aws.createLogGroup = sinon.stub().yields(null);

Expand All @@ -337,7 +337,7 @@ describe('cloudwatch-integration', function() {
});

it('errors if creating a group errors', function(done) {
var err = { code: 'ResourceNotFoundException' };
var err = { name: 'ResourceNotFoundException' };
aws.describeLogStreams = sinon.stub().yields(err);
aws.createLogGroup = sinon.stub().yields('err');

Expand Down Expand Up @@ -411,7 +411,7 @@ describe('cloudwatch-integration', function() {
logStreamName: 'another-stream'
}]
});
var err = { code: 'OperationAbortedException' };
var err = { name: 'OperationAbortedException' };
aws.createLogStream = sinon.stub().yields(err);

lib.getStream(aws, 'group', 'stream', function(err, stream) {
Expand All @@ -432,7 +432,7 @@ describe('cloudwatch-integration', function() {
logStreamName: 'another-stream'
}]
});
err = { code: 'ResourceAlreadyExistsException' };
err = { name: 'ResourceAlreadyExistsException' };
aws.createLogStream = sinon.stub().yields(err);

lib.getStream(aws, 'group', 'stream', function(err, stream) {
Expand Down Expand Up @@ -460,7 +460,7 @@ describe('cloudwatch-integration', function() {

it('ignores a OperationAbortedException', function(done) {
function runner(cb) {
var err = { code: 'OperationAbortedException' };
var err = { name: 'OperationAbortedException' };
cb(err);
}

Expand All @@ -472,7 +472,7 @@ describe('cloudwatch-integration', function() {

it('ignores a ResourceAlreadyExistsException', function(done) {
function runner(cb) {
var err = { code: 'ResourceAlreadyExistsException' };
var err = { name: 'ResourceAlreadyExistsException' };
cb(err);
}

Expand Down