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

add traceid for event model #236

Merged
merged 4 commits into from
Jan 8, 2019
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
8 changes: 8 additions & 0 deletions app/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const EventSchema = new Schema({
enum: Facilities.list()
}
},
traceid: {type: String},
id: {type: String}, // e.g. PID of the process
msgid: {type: String, enum: MsgIds.list()}, // pre-defined ID's
tag: {type: String},
Expand All @@ -125,6 +126,13 @@ const EventSchema = new Schema({
spare: {type: Mixed}
});

// this avoids accidentally uploading duplicate events
EventSchema.index({msgid: 1, traceid: 1}, {
unique: true,
partialFilterExpression: {traceid: {$exists: true}}
});


EventSchema.virtual('priorityStr')
.get(function getPriority() {
return `${this.priority.facility}.${this.priority.level}`;
Expand Down
41 changes: 12 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "OpenTMI",
"description": "OpenTMI - Open Source Test Management Infrastructure",
"version": "0.7.1",
"version": "0.7.2",
"author": {
"name": "Jussi Vatjus-Anttila",
"email": "[email protected]"
Expand Down
18 changes: 12 additions & 6 deletions test/tests_api/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Events', function () {
});
it('can calculate utilization', function () {
const resourceId = '5825bb7afe7545132c88c761';
const create = (timestamp, msgid) => {
const create = (timestamp, msgid, traceid) => {
const payload = {
priority: {
level: 'info',
Expand All @@ -176,7 +176,8 @@ describe('Events', function () {
cre: {
date: timestamp
},
msgid
msgid,
traceid
};
return createEvent(payload)
.then((body) => {
Expand All @@ -189,14 +190,19 @@ describe('Events', function () {
.end()
.then(response => response.body);
return Promise.mapSeries([
create('1995-12-17T00:00:00', 'ALLOCATED'),
create('1995-12-17T01:00:00', 'RELEASED'),
create('1995-12-18T00:00:00', 'RELEASED')
create('1995-12-17T00:00:00', 'ALLOCATED', '123'),
create('1995-12-17T01:00:00', 'RELEASED', '123'),
create('1995-12-17T01:00:00', 'RELEASED', '123')
.reflect()
.then((promise) => {
expect(promise.isRejected()).to.be.true;
}),
create('1995-12-18T00:00:00', 'ALLOCATED', '1234')
], () => {})
.then(getUtilization)
.then((stats) => {
expect(stats.count).to.be.equal(3);
expect(stats.summary.allocations.count).to.be.equal(1);
expect(stats.summary.allocations.count).to.be.equal(2);
expect(stats.summary.allocations.time).to.be.equal(3600);
expect(stats.summary.allocations.utilization).to.be.at.least(4);
expect(stats.summary.allocations.utilization).to.be.below(4.2);
Expand Down