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

LiveQueryEvent Error Logging Improvements #6951

Merged
merged 9 commits into from
Oct 21, 2020

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Oct 20, 2020

Minor changes to #6859 that I've realised should've been added.

-Throwing in an afterLiveQueryEvent trigger logs properly, instead of "Matching ACL error".
-New sendEvent parameter to afterLiveQueryEvent request payload.

I've been thinking about how the afterLiveQueryEvent should handle not firing events. In the specs, I previously did it by throwing an error in the afterLiveQueryEvent, but I don't think that makes much sense, and also will fill up the logs. Hence, I've added a property "sendEvent" to the afterLiveQueryEvent request payload. If the afterLiveQueryEvent trigger sets that to false, the LiveQuery won't push to the client.

That's all the changes in this PR. I was also thinking about what happens when afterLiveQueryEvent throws an error. Should this be sent to the client as a "error" event, or should it just log on the server (as current behaviour), and no LQ event triggered?

Thank you!

@ghost
Copy link

ghost commented Oct 20, 2020

Danger run resulted in 1 fail and 1 markdown; to find out more, see the checks page.

Generated by 🚫 dangerJS

@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #6951 into master will increase coverage by 0.02%.
The diff coverage is 62.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6951      +/-   ##
==========================================
+ Coverage   93.78%   93.80%   +0.02%     
==========================================
  Files         169      169              
  Lines       12252    12260       +8     
==========================================
+ Hits        11491    11501      +10     
+ Misses        761      759       -2     
Impacted Files Coverage Δ
src/cloud-code/Parse.Cloud.js 98.59% <ø> (ø)
src/LiveQuery/ParseLiveQueryServer.js 94.63% <62.50%> (-0.49%) ⬇️
src/StatusHandler.js 99.27% <0.00%> (+0.01%) ⬆️
src/RestWrite.js 93.98% <0.00%> (+0.16%) ⬆️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 93.58% <0.00%> (+0.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8873cfe...d51a3f5. Read the comment docs.

};
return maybeRunAfterEventTrigger('afterEvent', className, res);
})
.then(() => {
if (!res.sendEvent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed no?

Copy link
Member Author

@dblythy dblythy Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is in relation to preventing events from firing, which was previously achieved by throwing in the trigger. Setting request.sendEvent = false in LQ trigger returns before the events are pushed to the LQ.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since maybeRunAfterEventTrigger is the only code that can throw an error this block will be skipped.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @dplewis, I'm not sure what the issue is, what would you like me to change? 😊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an error handles events from firing. sendEvent can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no worries. I added sendEvent because if you are using a highly restrictive LQ, you'll end up with afterEvent events filling up your logs, which I'm not sure is desired.

For example, only passing LQ update on "foo" change:

Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
      if (req.object.get('foo') != req.original.get('foo')) {
          // if TestObject has a lot of fields, this will throw often
          throw 'Foo was not updated';
      }
});

Would log on every single LQ event for TestObject, and pass a subscription.on('error') event. The idea behind the sendEvent is a way to stop events firing, without it sending errors to the client, and without it filling up logLevel: 'error' logs. However happy to remove it if you see it unnecessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see

src/LiveQuery/ParseLiveQueryServer.js Outdated Show resolved Hide resolved
@dblythy dblythy requested a review from davimacedo October 21, 2020 07:44
Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.

@dplewis dplewis merged commit ef2e54c into parse-community:master Oct 21, 2020
@dblythy
Copy link
Member Author

dblythy commented Oct 21, 2020

Thanks gents!

@dblythy dblythy deleted the liveQueryEvent branch October 22, 2020 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants