Skip to content

Commit

Permalink
Replaced hardcoded paragraph execution time with real running time (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
chloe-zh authored Mar 1, 2021
1 parent d0e1487 commit ef0da23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions kibana-notebooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"devDependencies": {
"cypress": "^5.0.0",
"eslint": "^6.8.0"
"eslint": "^6.8.0",
"performance-now": "^2.1.0"
},
"dependencies": {
"@babel/cli": "^7.10.5",
Expand Down Expand Up @@ -53,4 +54,4 @@
"node": "10.23.1",
"yarn": "^1.21.1"
}
}
}
20 changes: 11 additions & 9 deletions kibana-notebooks/server/adaptors/default_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DefaultOutput,
} from '../helpers/default_notebook_schema';
import { formatNotRecognized, inputIsQuery } from '../helpers/query_helpers';
import now from "performance-now";

export class DefaultBackend implements NotebookAdaptor {
backend = 'Default Backend';
Expand Down Expand Up @@ -277,7 +278,7 @@ export class DefaultBackend implements NotebookAdaptor {
}
if (paragraphInput.substring(0, 3) === '%sql' || paragraphInput.substring(0, 3) === '%ppl') {
paragraphType = 'QUERY';
}
}
const inputObject = {
inputType: paragraphType,
inputText: paragraphInput,
Expand Down Expand Up @@ -312,6 +313,7 @@ export class DefaultBackend implements NotebookAdaptor {
const updatedParagraphs = [];
let index = 0;
for (index = 0; index < paragraphs.length; ++index) {
const startTime = now();
const updatedParagraph = { ...paragraphs[index] };
if (paragraphs[index].input.inputType === 'MARKDOWN' && paragraphs[index].id === paragraphId) {
updatedParagraph.dateModified = new Date().toISOString();
Expand All @@ -320,35 +322,35 @@ export class DefaultBackend implements NotebookAdaptor {
{
outputType: 'QUERY',
result: paragraphs[index].input.inputText.substring(4, paragraphs[index].input.inputText.length),
execution_time: '0s',
execution_time: `${(now() - startTime).toFixed(3)} ms`,
},
];
} else if (paragraphs[index].input.inputText.substring(0, 3) === '%md') {
updatedParagraph.output = [
{
outputType: 'MARKDOWN',
result: paragraphs[index].input.inputText.substring(4, paragraphs[index].input.inputText.length),
execution_time: '0s',
execution_time: `${(now() - startTime).toFixed(3)} ms`,
},
];
];
} else if (paragraphs[index].input.inputType === 'VISUALIZATION' && paragraphs[index].id === paragraphId) {
updatedParagraph.dateModified = new Date().toISOString();
updatedParagraph.output = [
{
outputType: 'VISUALIZATION',
result: '',
execution_time: '0s',
execution_time: `${(now() - startTime).toFixed(3)} ms`,
},
];
} else if (formatNotRecognized(paragraphs[index].input.inputText)) {
} else if (formatNotRecognized(paragraphs[index].input.inputText)) {
updatedParagraph.output = [
{
outputType: 'MARKDOWN',
result: 'Please select an input type (%sql, %ppl, or %md)',
execution_time: '0s',
execution_time: `${(now() - startTime).toFixed(3)} ms`,
},
];
}
];
}
}
updatedParagraphs.push(updatedParagraph);
}
Expand Down

0 comments on commit ef0da23

Please sign in to comment.