Skip to content

Commit

Permalink
Update dependencies; use promises from AWS SDK; drop Bluebird
Browse files Browse the repository at this point in the history
  • Loading branch information
timdp committed Jun 12, 2016
1 parent 77e0557 commit 3005b48
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 49 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
global.Promise = global.Promise || require('pinkie')

module.exports = require('./lib/').default
43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,40 @@
"node": ">=0.10.0"
},
"dependencies": {
"aws-sdk": "^2.1.45",
"babel-runtime": "^6.3.19",
"bluebird": "^3.1.1",
"bottleneck": "^1.8.1",
"aws-sdk": "^2.3.19",
"babel-runtime": "^6.9.2",
"bottleneck": "^1.12.0",
"debug": "^2.2.0",
"defaults": "^1.0.2",
"lodash.find": "^4.1.0",
"lodash.isempty": "^4.1.1",
"winston": "^2.1.1"
"defaults": "^1.0.3",
"lodash.find": "^4.4.0",
"lodash.isempty": "^4.2.1",
"winston": "^2.2.0"
},
"devDependencies": {
"babel-eslint": "^6.0.4",
"babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-3": "^6.5.0",
"babel-register": "^6.8.0",
"chai": "^3.0.0",
"chai-as-promised": "^5.1.0",
"del": "^2.0.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"del": "^2.2.0",
"delay": "^1.3.1",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-coveralls": "^0.1.4",
"gulp-if": "^2.0.1",
"gulp-istanbul": "^1.0.0",
"gulp-load-plugins": "^1.1.0",
"gulp-mocha": "^2.1.3",
"gulp-load-plugins": "^1.2.4",
"gulp-mocha": "^2.2.0",
"gulp-notify": "^2.2.0",
"gulp-plumber": "^1.0.1",
"gulp-plumber": "^1.1.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-standard": "^7.0.1",
"isparta": "^4.0.0",
"run-sequence": "^1.2.0",
"sinon": "^1.15.4",
"pinkie": "^2.0.4",
"run-sequence": "^1.2.1",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0"
},
"main": "index.js",
Expand Down
12 changes: 5 additions & 7 deletions src/lib/cloudwatch-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import _debug from 'debug'
const debug = _debug('winston-aws-cloudwatch:CloudWatchClient')

import AWS from 'aws-sdk'
import Promise from 'bluebird'
import defaults from 'defaults'
import find from 'lodash.find'
import CloudWatchEventFormatter from './cloudwatch-event-formatter'
Expand All @@ -22,8 +21,7 @@ export default class CloudWatchClient {
createLogStream: false
})
this._sequenceTokenInfo = null
const client = new AWS.CloudWatchLogs(this._options.awsConfig)
this._client = Promise.promisifyAll(client)
this._client = new AWS.CloudWatchLogs(this._options.awsConfig)
this._initializing = null
}

Expand All @@ -50,7 +48,7 @@ export default class CloudWatchClient {
const params = {
logGroupName: this._logGroupName
}
return this._client.createLogGroupAsync(params)
return this._client.createLogGroup(params).promise()
.catch((err) => this._allowResourceAlreadyExistsException(err))
}

Expand All @@ -62,7 +60,7 @@ export default class CloudWatchClient {
logGroupName: this._logGroupName,
logStreamName: this._logStreamName
}
return this._client.createLogStreamAsync(params)
return this._client.createLogStream(params).promise()
.catch((err) => this._allowResourceAlreadyExistsException(err))
}

Expand All @@ -80,7 +78,7 @@ export default class CloudWatchClient {
logEvents: batch.map(this._options.formatLogItem),
sequenceToken
}
return this._client.putLogEventsAsync(params)
return this._client.putLogEvents(params).promise()
}

_getSequenceToken () {
Expand Down Expand Up @@ -111,7 +109,7 @@ export default class CloudWatchClient {
logStreamNamePrefix: this._logStreamName,
nextToken
}
return this._client.describeLogStreamsAsync(params)
return this._client.describeLogStreams(params).promise()
.then(({logStreams, nextToken}) => {
const match = find(logStreams,
({logStreamName}) => (logStreamName === this._logStreamName))
Expand Down
1 change: 0 additions & 1 deletion src/lib/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import _debug from 'debug'
const debug = _debug('winston-aws-cloudwatch:Relay')

import Promise from 'bluebird'
import Bottleneck from 'bottleneck'
import defaults from 'defaults'
import Queue from './queue'
Expand Down
34 changes: 18 additions & 16 deletions test/unit/test-cloudwatch-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const logStreamName = 'testStream'
let tokens = 0
let streams = 0

const withPromise = (res) => ({promise: () => res})

const mapRequest = (stub, includeExpected, token, nextToken) => {
const suffixes = [++streams, ++streams, includeExpected ? '' : ++streams]
const res = Promise.resolve({
Expand All @@ -19,9 +21,9 @@ const mapRequest = (stub, includeExpected, token, nextToken) => {
})
if (token) {
stub.withArgs(sinon.match({nextToken: token}))
.returns(res)
.returns(withPromise(res))
} else {
stub.returns(res)
stub.returns(withPromise(res))
}
}

Expand Down Expand Up @@ -57,17 +59,17 @@ const createClient = (options) => {
})
const client = new CloudWatchClient(logGroupName, logStreamName,
options.clientOptions)
sinon.stub(client._client, 'putLogEventsAsync')
.returns(Promise.resolve({nextSequenceToken: 'token42'}))
sinon.stub(client._client, 'createLogGroupAsync')
.returns(options.groupErrorCode
sinon.stub(client._client, 'putLogEvents')
.returns(withPromise(Promise.resolve({nextSequenceToken: 'token42'})))
sinon.stub(client._client, 'createLogGroup')
.returns(withPromise(options.groupErrorCode
? Promise.reject(createErrorWithCode(options.groupErrorCode))
: Promise.resolve())
sinon.stub(client._client, 'createLogStreamAsync')
.returns(options.streamErrorCode
: Promise.resolve()))
sinon.stub(client._client, 'createLogStream')
.returns(withPromise(options.streamErrorCode
? Promise.reject(createErrorWithCode(options.streamErrorCode))
: Promise.resolve())
const stub = sinon.stub(client._client, 'describeLogStreamsAsync')
: Promise.resolve()))
const stub = sinon.stub(client._client, 'describeLogStreams')
options.streamsStrategy(stub)
return client
}
Expand All @@ -87,7 +89,7 @@ describe('CloudWatchClient', () => {
const batch = createBatch(1)
return expect(
client.submit(batch)
.then(() => client._client.putLogEventsAsync.calledOnce)
.then(() => client._client.putLogEvents.calledOnce)
).to.eventually.equal(true)
})

Expand All @@ -98,7 +100,7 @@ describe('CloudWatchClient', () => {
const batch = createBatch(1)
return expect(
client.submit(batch)
.then(() => client._client.describeLogStreamsAsync.callCount)
.then(() => client._client.describeLogStreams.callCount)
).to.eventually.equal(3)
})

Expand Down Expand Up @@ -131,7 +133,7 @@ describe('CloudWatchClient', () => {
return expect(
client.submit(createBatch(1))
.then(() => client.submit(createBatch(1)))
.then(() => client._client.describeLogStreamsAsync.calledOnce)
.then(() => client._client.describeLogStreams.calledOnce)
).to.eventually.equal(true)
})
})
Expand Down Expand Up @@ -163,7 +165,7 @@ describe('CloudWatchClient', () => {
const batch = createBatch(1)
return expect(
client.submit(batch)
.then(() => client._client.createLogGroupAsync.calledOnce)
.then(() => client._client.createLogGroup.calledOnce)
).to.eventually.equal(true)
})

Expand Down Expand Up @@ -198,7 +200,7 @@ describe('CloudWatchClient', () => {
const batch = createBatch(1)
return expect(
client.submit(batch)
.then(() => client._client.createLogStreamAsync.calledOnce)
.then(() => client._client.createLogStream.calledOnce)
).to.eventually.equal(true)
})

Expand Down
8 changes: 4 additions & 4 deletions test/unit/test-relay.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

import Promise from 'bluebird'
import sinon from 'sinon'
import delay from 'delay'
import Relay from '../../src/lib/relay'

class TestClient {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('Relay', () => {
for (const item of items) {
relay.submit(item)
}
await Promise.delay(submissionInterval * 1.1)
await delay(submissionInterval * 1.1)
expect(client.submitted).to.deep.equal(items)
})

Expand All @@ -61,7 +61,7 @@ describe('Relay', () => {

const counts = []
for (let i = 0; i < batches; ++i) {
await Promise.delay(submissionInterval * 1.1)
await delay(submissionInterval * 1.1)
counts.push(client.submitted.length)
}

Expand All @@ -83,7 +83,7 @@ describe('Relay', () => {
relay.on('error', spy)
relay.start()
relay.submit({})
await Promise.delay(submissionInterval * (failures + retries) * 1.1)
await delay(submissionInterval * (failures + retries) * 1.1)
expect(spy.callCount).to.equal(failures)
})
})
Expand Down

0 comments on commit 3005b48

Please sign in to comment.