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

Commit a3792fc

Browse files
author
Chris Wiechmann
authored
Merge pull request #2 from cwiechmann/master
ago filter was not working
2 parents f85d42a + 625218e commit a3792fc

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

elk-traffic-monitor-api/flows/monitoringApiApi-getRouterServiceOpsSearchByServiceID.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
{
249249
"name": "code",
250250
"type": "string",
251-
"value": "\"var queryFilters = data.queryFilters;\\n if(data.params.ago) {\\n var ago = data.params.ago;\\n var now = Date.now()\\n var diff = convertAgo(ago);\\n var filter = {\\n range: {\\n \\\"timestampOriginal\\\": {\\n gt: now\\n }\\n }\\n };\\n queryFilters.push(filter);\\n return queryFilters;\\n }\\n \\n function convertAgo(ago) {\\n if(ago.endsWith('m')) {\\n return ago.substring(0, ago.length-1) * 60000;\\n } else if(ago.endsWith('h')) {\\n return ago.substring(0, ago.length-1) * 3600 * 1000;\\n }\\n console.log(`ERRRRO ${ago}`);\\n }\"",
251+
"value": "\"var queryFilters = data.queryFilters;\\n if(data.params.ago) {\\n var ago = data.params.ago;\\n var diff = convertAgo(ago);\\n var filter = {\\n range: {\\n \\\"timestampOriginal\\\": {\\n gt: diff\\n }\\n }\\n };\\n queryFilters.push(filter);\\n return queryFilters;\\n }\\n \\n function convertAgo(ago) {\\n var diff = ago.substring(0, ago.length-1);\\n var now = new Date();\\n if(ago.endsWith('m')) {\\n return now.setMinutes(now.getMinutes() - diff);\\n } else if(ago.endsWith('h')) {\\n return now.setMinutes(now.getHours() - diff);\\n }\\n console.log(`ERRRRO ${ago}`);\\n }\"",
252252
"metaName": "code",
253253
"metaDescription": "A JavaScript function body. Supports `await` and returning promises"
254254
}

elk-traffic-monitor-api/test/documents/basic/search_test_documents.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const getDate = require('../util');
2+
13
module.exports = [
24
{
35
"processInfo": {
@@ -150,7 +152,7 @@ module.exports = [
150152
}
151153
},
152154
"correlationId": "c8705e5ecc00adca32be7472",
153-
"timestampOriginal": "2020-03-03T14:59:20.467Z",
155+
"timestampOriginal": getDate('8m'),
154156
"transactionSummary": {
155157
"serviceContexts": [
156158
{
@@ -234,7 +236,7 @@ module.exports = [
234236
}
235237
},
236238
"correlationId": "c9705e5ecd000322778d2ec4",
237-
"timestampOriginal": "2020-03-03T14:59:21.273Z",
239+
"timestampOriginal": getDate('15m'),
238240
"transactionSummary": {
239241
"serviceContexts": [],
240242
"path": "/favicon.ico",
@@ -301,7 +303,7 @@ module.exports = [
301303
}
302304
},
303305
"correlationId": "fc705e5ede00654de6d15daf",
304-
"timestampOriginal": "2020-03-03T15:00:12.175Z",
306+
"timestampOriginal": getDate('120h'),
305307
"transactionSummary": {
306308
"serviceContexts": [],
307309
"path": "/v2/pet/findByStatus",
@@ -375,7 +377,7 @@ module.exports = [
375377
"leg": 0
376378
}
377379
},
378-
"timestampOriginal": "2020-03-03T14:06:06.351Z",
380+
"timestampOriginal": getDate('65m'),
379381
"processInfo": {
380382
"groupName": "QuickStart Group",
381383
"hostname": "api-env",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function getDate(ago) {
2+
var now = new Date();
3+
var diff = ago.substring(0, ago.length-1);
4+
if(ago.endsWith('m')) {
5+
now.setMinutes(now.getMinutes() - diff);
6+
} else if(ago.endsWith('h')) {
7+
now.setHours(now.getHours() - diff);
8+
}
9+
return now.toISOString();
10+
}
11+
12+
module.exports = getDate;

elk-traffic-monitor-api/test/endpoints.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('Endpoints', function () {
136136
};
137137
return requestAsync({
138138
method: 'GET',
139-
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=120h`,
139+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=5m`, // The first entry is generated with 8 minutes in the past
140140
auth: auth,
141141
json: true
142142
}).then(({ response, body }) => {
@@ -370,6 +370,60 @@ describe('Endpoints', function () {
370370
expect(body.data[0].uri).to.equals('/v2/pet/123');
371371
});
372372
});
373+
it('[Endpoint-0019] Should return 1 entry in the last 10 minutes (ago=10m)', () => {
374+
const auth = {
375+
user: server.apibuilder.config.apikey || 'test',
376+
password: ''
377+
};
378+
return requestAsync({
379+
method: 'GET',
380+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=10m`,
381+
auth: auth,
382+
json: true
383+
}).then(({ response, body }) => {
384+
expect(response.statusCode).to.equal(200);
385+
expect(body).to.be.an('Object');
386+
expect(body).to.have.property('data');
387+
expect(body.data).to.have.lengthOf(1);
388+
expect(body.data[0].uri).to.equals('/v2/pet/123');
389+
});
390+
});
391+
it('[Endpoint-0020] Should return 2 entries in the last 30 minutes (ago=30m)', () => {
392+
const auth = {
393+
user: server.apibuilder.config.apikey || 'test',
394+
password: ''
395+
};
396+
return requestAsync({
397+
method: 'GET',
398+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=30m`,
399+
auth: auth,
400+
json: true
401+
}).then(({ response, body }) => {
402+
expect(response.statusCode).to.equal(200);
403+
expect(body).to.be.an('Object');
404+
expect(body).to.have.property('data');
405+
expect(body.data).to.have.lengthOf(2);
406+
expect(body.data[0].uri).to.equals('/v2/pet/123');
407+
});
408+
});
409+
it('[Endpoint-0020] Should only 2 entries in the last 2 hours (ago=120h)', () => {
410+
const auth = {
411+
user: server.apibuilder.config.apikey || 'test',
412+
password: ''
413+
};
414+
return requestAsync({
415+
method: 'GET',
416+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=120h`,
417+
auth: auth,
418+
json: true
419+
}).then(({ response, body }) => {
420+
expect(response.statusCode).to.equal(200);
421+
expect(body).to.be.an('Object');
422+
expect(body).to.have.property('data');
423+
expect(body.data).to.have.lengthOf(3);
424+
expect(body.data[0].uri).to.equals('/v2/pet/123');
425+
});
426+
});
373427
});
374428
});
375429

0 commit comments

Comments
 (0)