Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
{
"name": "code",
"type": "string",
"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 }\"",
"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 }\"",
"metaName": "code",
"metaDescription": "A JavaScript function body. Supports `await` and returning promises"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const getDate = require('../util');

module.exports = [
{
"processInfo": {
Expand Down Expand Up @@ -150,7 +152,7 @@ module.exports = [
}
},
"correlationId": "c8705e5ecc00adca32be7472",
"timestampOriginal": "2020-03-03T14:59:20.467Z",
"timestampOriginal": getDate('8m'),
"transactionSummary": {
"serviceContexts": [
{
Expand Down Expand Up @@ -234,7 +236,7 @@ module.exports = [
}
},
"correlationId": "c9705e5ecd000322778d2ec4",
"timestampOriginal": "2020-03-03T14:59:21.273Z",
"timestampOriginal": getDate('15m'),
"transactionSummary": {
"serviceContexts": [],
"path": "/favicon.ico",
Expand Down Expand Up @@ -301,7 +303,7 @@ module.exports = [
}
},
"correlationId": "fc705e5ede00654de6d15daf",
"timestampOriginal": "2020-03-03T15:00:12.175Z",
"timestampOriginal": getDate('120h'),
"transactionSummary": {
"serviceContexts": [],
"path": "/v2/pet/findByStatus",
Expand Down Expand Up @@ -375,7 +377,7 @@ module.exports = [
"leg": 0
}
},
"timestampOriginal": "2020-03-03T14:06:06.351Z",
"timestampOriginal": getDate('65m'),
"processInfo": {
"groupName": "QuickStart Group",
"hostname": "api-env",
Expand Down
12 changes: 12 additions & 0 deletions elk-traffic-monitor-api/test/documents/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function getDate(ago) {
var now = new Date();
var diff = ago.substring(0, ago.length-1);
if(ago.endsWith('m')) {
now.setMinutes(now.getMinutes() - diff);
} else if(ago.endsWith('h')) {
now.setHours(now.getHours() - diff);
}
return now.toISOString();
}

module.exports = getDate;
56 changes: 55 additions & 1 deletion elk-traffic-monitor-api/test/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('Endpoints', function () {
};
return requestAsync({
method: 'GET',
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=120h`,
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
auth: auth,
json: true
}).then(({ response, body }) => {
Expand Down Expand Up @@ -370,6 +370,60 @@ describe('Endpoints', function () {
expect(body.data[0].uri).to.equals('/v2/pet/123');
});
});
it('[Endpoint-0019] Should return 1 entry in the last 10 minutes (ago=10m)', () => {
const auth = {
user: server.apibuilder.config.apikey || 'test',
password: ''
};
return requestAsync({
method: 'GET',
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=10m`,
auth: auth,
json: true
}).then(({ response, body }) => {
expect(response.statusCode).to.equal(200);
expect(body).to.be.an('Object');
expect(body).to.have.property('data');
expect(body.data).to.have.lengthOf(1);
expect(body.data[0].uri).to.equals('/v2/pet/123');
});
});
it('[Endpoint-0020] Should return 2 entries in the last 30 minutes (ago=30m)', () => {
const auth = {
user: server.apibuilder.config.apikey || 'test',
password: ''
};
return requestAsync({
method: 'GET',
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=30m`,
auth: auth,
json: true
}).then(({ response, body }) => {
expect(response.statusCode).to.equal(200);
expect(body).to.be.an('Object');
expect(body).to.have.property('data');
expect(body.data).to.have.lengthOf(2);
expect(body.data[0].uri).to.equals('/v2/pet/123');
});
});
it('[Endpoint-0020] Should only 2 entries in the last 2 hours (ago=120h)', () => {
const auth = {
user: server.apibuilder.config.apikey || 'test',
password: ''
};
return requestAsync({
method: 'GET',
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?ago=120h`,
auth: auth,
json: true
}).then(({ response, body }) => {
expect(response.statusCode).to.equal(200);
expect(body).to.be.an('Object');
expect(body).to.have.property('data');
expect(body.data).to.have.lengthOf(3);
expect(body.data[0].uri).to.equals('/v2/pet/123');
});
});
});
});

Expand Down