-
Notifications
You must be signed in to change notification settings - Fork 13
chore(logging): add time to graphql log #258
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
Conversation
src/server/es/index.js
Outdated
| log.error(`[ES.query] error during querying: ${err.message}`); | ||
| throw new Error(err.message); | ||
| }); | ||
| var end = new Date().getTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.client.search is async so this end time won't reflect when the request ends, just when it was sent.
you'll want to add a call to finally after the .then and add this and the code below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll fix it. Is it obvious I don't with Javascript very often? 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this
var searchResult = this.client.search({
index: esIndex,
body: validatedQueryBody,
}).then((resp) => resp.body, (err) => {
log.error(`[ES.query] error during querying: ${err.message}`);
throw new Error(err.message);
}).finally(() => {
var end = new Date().getTime();
var durationInMS = end - start;
log.info('[ES.query] DurationInMS:' + durationInMS + '. index, type, query body: ', esIndex, esType, JSON.stringify(validatedQueryBody));
return searchResult;
})
and no worries i almost commented on the log.info asking you to use f strings before realizing this was javascript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also if you really want to squeeze performance (and look like a JS pro), use Date.now() instead of new Date().getTime()
they're functionally the same though
src/server/es/index.js
Outdated
| var durationInMS = end - start; | ||
|
|
||
| log.info('[ES.query] DurationInMS:' + durationInMS + '. index, type, query body: ', esIndex, esType, JSON.stringify(validatedQueryBody)); | ||
| return searchResult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't return from the finally - you can actually get rid of searchResult assignment and return this.client.search(...) like it was before. This function needs to return the Promise for the async call so callers of the functions can do their own async response handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'll push and then I'm going to test in my dev env
New Features
Breaking Changes
Bug Fixes
Improvements
Dependency updates
Deployment changes