Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit caf5173

Browse files
committed
Logs command fails for packaged actions.
Fixes #111
1 parent 1820f1e commit caf5173

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

logs/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,19 @@ class OpenWhiskLogs {
8080
});
8181
}
8282

83+
// activation log annotations have a { key: 'path, value: 'namespace/actioname' } member.
84+
hasPathAnnotationWithName (annotations, name) {
85+
return annotations.filter(an => an.key === 'path')
86+
.map(an => an.value.split('/').slice(1).join('/'))
87+
.some(value => value === name)
88+
}
89+
8390
filterFunctionLogs (logs) {
8491
const functionObject = this.serverless.service.getFunction(this.options.function);
8592
const actionName = functionObject.name || `${this.serverless.service.service}_${this.options.function}`
8693

8794
// skip activations for other actions or that we have seen before
88-
const filtered = logs.filter(log => log.name === actionName
95+
const filtered = logs.filter(log => this.hasPathAnnotationWithName((log.annotations || []), actionName)
8996
&& !this.previous_activations.has(log.activationId))
9097

9198
// allow regexp filtering of log messages

logs/tests/index.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ require('chai').use(chaiAsPromised);
1515
describe('OpenWhiskLogs', () => {
1616
let sandbox;
1717

18-
const CLI = function () { this.log = function () {};};
19-
const serverless = {config: () => {}, pluginManager: { getPlugins: () => []}, classes: {Error, CLI}, service: {getFunction: () => ({}), provider: {}, resources: {}, getAllFunctions: () => []}, getProvider: sinon.spy()};
18+
const CLI = function () { this.log = function () {};};
19+
const serverless = {config: () => {}, pluginManager: { getPlugins: () => []}, classes: {Error, CLI}, service: {getFunction: name => (serverless.service.functions[name]), provider: {}, resources: {}, getAllFunctions: () => []}, getProvider: sinon.spy()};
2020
const options = {
2121
stage: 'dev',
2222
region: 'us-east-1',
@@ -64,7 +64,6 @@ describe('OpenWhiskLogs', () => {
6464
beforeEach(() => {
6565
openwhiskLogs.serverless.service.functions = {
6666
first: {
67-
namespace: 'sample',
6867
handler: true,
6968
},
7069
};
@@ -110,7 +109,6 @@ describe('OpenWhiskLogs', () => {
110109
beforeEach(() => {
111110
openwhiskLogs.serverless.service.functions = {
112111
first: {
113-
namespace: 'sample',
114112
handler: true,
115113
},
116114
};
@@ -153,7 +151,6 @@ describe('OpenWhiskLogs', () => {
153151
beforeEach(() => {
154152
openwhiskLogs.serverless.service.functions = {
155153
first: {
156-
namespace: 'sample',
157154
handler: true,
158155
},
159156
};
@@ -165,16 +162,39 @@ describe('OpenWhiskLogs', () => {
165162
});
166163

167164
it('should filter out different function logs', () => {
168-
const logs = [{name: "new-service_first"}, {name: "new-service_first"}, {name: "new-service_second"}, {name: "new-service_third"}, {name: "new-service_first"}]
165+
const logs = [
166+
{ name: "new-service_first", annotations: [ {key: "path", value: '[email protected]_dev/new-service_first'} ] },
167+
{ name: "new-service_first", annotations: [ {key: "path", value: '[email protected]_dev/new-service_first'} ] },
168+
{ name: "new-service_second", annotations: [ {key: "path", value: '[email protected]_dev/new-service_second'} ] },
169+
{ name: "new-service_third", annotations: [ {key: "path", value: "[email protected]_dev/new-second_third"} ] },
170+
{ name: "new-service_first", annotations: [ {key: "path", value: '[email protected]_dev/new-service_first'} ] }
171+
]
169172
return openwhiskLogs.filterFunctionLogs(logs).then(logs => {
170173
expect(logs.length).to.be.equal(3)
171174
logs.forEach(log => expect(log.name).to.be.equal('new-service_first'))
172175
})
173176
});
174177

178+
it('should filter out different function logs with package function', () => {
179+
openwhiskLogs.serverless.service.functions.first.name = 'packagename/funcname'
180+
const logs = [
181+
{ name: "funcname", annotations:[{ key:"path", value:"[email protected]_dev/packagename/funcname"} ]},
182+
{ name: "funcname", annotations:[{ key:"path", value:"[email protected]_dev/packagename/funcname"} ]},
183+
{ name: "new-service_second", annotations: [ {key: "path", value: '[email protected]_dev/new-service_second'} ] },
184+
{ name: "new-service_third", annotations: [ {key: "path", value: "[email protected]_dev/new-second_third"} ] },
185+
{ name: "funcname", annotations:[{ key:"path", value:"[email protected]_dev/packagename/funcname"} ]}
186+
]
187+
188+
return openwhiskLogs.filterFunctionLogs(logs).then(logs => {
189+
expect(logs.length).to.be.equal(3)
190+
logs.forEach(log => expect(log.name).to.be.equal('funcname'))
191+
})
192+
});
193+
194+
175195
it('should filter out logs lines based upon contents', () => {
176196
openwhiskLogs.options.startTime = moment('2001-01-01')
177-
const logs = [{name: "new-service_first", logs: ["2001-01-02 matching line", "2001-01-01 another matching line", "2000-12-31 should not match"]}]
197+
const logs = [{name: "new-service_first", annotations: [ {key: "path", value: '[email protected]_dev/new-service_first' }], logs: ["2001-01-02 matching line", "2001-01-01 another matching line", "2000-12-31 should not match"]}]
178198
return openwhiskLogs.filterFunctionLogs(logs).then(logs => {
179199
expect(logs.length).to.be.equal(1)
180200
expect(logs[0].logs).to.be.deep.equal(["2001-01-02 matching line"])
@@ -184,7 +204,11 @@ describe('OpenWhiskLogs', () => {
184204

185205
it('should filter out logs lines based upon contents', () => {
186206
openwhiskLogs.options.filter = new RegExp('matching', 'i')
187-
const logs = [{name: "new-service_first", logs: ["matching line", "another matching line", "should not match"]}, {name: "new-service_first", logs: ["does not match"]}]
207+
const logs = [
208+
{name: "new-service_first", annotations: [ {key: "path", value: '[email protected]_dev/new-service_first' }], logs: ["matching line", "another matching line", "should not match"]},
209+
{name: "new-service_first", annotations: [ {key: "path", value: '[email protected]_dev/new-service_first' }], logs: ["does not match"]}
210+
]
211+
188212
return openwhiskLogs.filterFunctionLogs(logs).then(logs => {
189213
expect(logs.length).to.be.equal(2)
190214
expect(logs[0].logs).to.be.deep.equal(["matching line", "another matching line"])
@@ -193,11 +217,14 @@ describe('OpenWhiskLogs', () => {
193217
})
194218
});
195219

196-
197-
198220
it('should filter already seen log messages', () => {
199221
openwhiskLogs.previous_activations = new Set([1, 2, 3, 4, 5])
200-
const logs = [{activationId: 1, name: "new-service_first"}, {activationId: 5, name: "new-service_first"}, {activationId: 6, name: "new-service_first"}]
222+
const logs = [
223+
{activationId: 1, annotations: [ {key: "path", value: '[email protected]_dev/new-service_first' }], name: "new-service_first"},
224+
{activationId: 5, annotations: [ {key: "path", value: '[email protected]_dev/new-service_first' }], name: "new-service_first"},
225+
{activationId: 6, annotations: [ {key: "path", value: '[email protected]_dev/new-service_first' }], name: "new-service_first"}
226+
]
227+
201228
return openwhiskLogs.filterFunctionLogs(logs).then(logs => {
202229
expect(logs.length).to.be.equal(1)
203230
expect(logs[0].name).to.be.equal('new-service_first')
@@ -211,7 +238,6 @@ describe('OpenWhiskLogs', () => {
211238
beforeEach(() => {
212239
openwhiskLogs.serverless.service.functions = {
213240
first: {
214-
namespace: 'sample',
215241
handler: true,
216242
},
217243
};

0 commit comments

Comments
 (0)