Skip to content

Commit

Permalink
New overall entity time query
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Sep 25, 2024
1 parent 507b86e commit 1f9ea63
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/model/query/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,17 @@ JOIN audits ON audits.id = "auditId"
WHERE action = 'submission.create'
`);

const measureElapsedEntityTime = () => ({ one }) => one(sql`
SELECT
MAX(ed."createdAt" - sd."createdAt") as max_wait,
AVG(ed."createdAt" - sd."createdAt") as avg_wait
FROM entity_defs as ed
JOIN entity_def_sources as eds
ON ed."sourceId" = eds."id"
JOIN submission_defs as sd
ON eds."submissionDefId" = sd.id;
`);

// Other
const getProjectsWithDescriptions = () => ({ all }) => all(sql`
select id as "projectId", length(trim(description)) as description_length from projects where coalesce(trim(description),'')!=''`);
Expand Down Expand Up @@ -819,5 +830,6 @@ module.exports = {
countOfflineBranches,
countInterruptedBranches,
countSubmissionReprocess,
measureEntityProcessingTime
measureEntityProcessingTime,
measureElapsedEntityTime
};
20 changes: 20 additions & 0 deletions test/integration/other/analytics-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,10 @@ describe('analytics task queries', function () {
let waitTime = await container.Analytics.measureEntityProcessingTime();
waitTime.should.eql({ max_wait: null, avg_wait: null });

// wait 100ms
// eslint-disable-next-line no-promise-executor-return
await new Promise(resolve => setTimeout(resolve, 100));

// Toggle approvalRequired flag
await asAlice.patch('/v1/projects/1/datasets/people?convert=true')
.send({ approvalRequired: false })
Expand All @@ -1778,6 +1782,12 @@ describe('analytics task queries', function () {

const processTimes2 = await container.one(sql`select "claimed", "processed", "loggedAt" from audits where action = 'submission.create'`);
processTimes1.should.eql(processTimes2);

// Overall time from submission creation to entity version creation should be higher
// because it includes delay from dataset approval flag toggle
const entityTime = await container.Analytics.measureElapsedEntityTime();
entityTime.max_wait.should.be.greaterThan(waitTime.max_wait + 0.1);
entityTime.avg_wait.should.be.greaterThan(waitTime.avg_wait + 0.1);
}));

it('should not see a delay for submissions held in backlog and then force-processed', testService(async (service, container) => {
Expand Down Expand Up @@ -1808,6 +1818,10 @@ describe('analytics task queries', function () {
let waitTime = await container.Analytics.measureEntityProcessingTime();
waitTime.should.eql({ max_wait: null, avg_wait: null });

// wait 100ms
// eslint-disable-next-line no-promise-executor-return
await new Promise(resolve => setTimeout(resolve, 100));

// force processing the backlog
await container.Entities.processBacklog(true);

Expand All @@ -1822,6 +1836,12 @@ describe('analytics task queries', function () {

const processTimes2 = await container.one(sql`select "claimed", "processed", "loggedAt" from audits where action = 'submission.create'`);
processTimes1.should.eql(processTimes2);

// Overall time for entity creation should be higher because it includes the delay
// from waiting in the backlog before being force-processed
const entityTime = await container.Analytics.measureElapsedEntityTime();
entityTime.max_wait.should.be.greaterThan(waitTime.max_wait + 0.1);
entityTime.avg_wait.should.be.greaterThan(waitTime.avg_wait + 0.1);
}));
});

Expand Down

0 comments on commit 1f9ea63

Please sign in to comment.