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

[GH-84] Do not rewrite messages from bots #98

Conversation

vespian
Copy link
Contributor

@vespian vespian commented Mar 7, 2020

Summary

This PR makes autolink plugin not rewrite messages from other bots as discussed in #94

Ticket Link

Fixes #94

@vespian vespian changed the title Do not rewrite messgaes from bots [GH-84] Do not rewrite messgaes from bots Mar 7, 2020
@hanzei hanzei requested review from levb and hanzei March 9, 2020 08:24
@hanzei hanzei added the 2: Dev Review Requires review by a core committer label Mar 9, 2020
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

Thanks for also adding a test 👍

server/autolinkplugin/plugin.go Outdated Show resolved Hide resolved
server/autolinkplugin/plugin.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@hanzei hanzei added the 3: QA Review Requires review by a QA tester label Mar 9, 2020
@vespian vespian force-pushed the prozlach/GH-94_no_rewriting_for_bots branch from a9ce2b4 to d0d75bc Compare March 9, 2020 19:56
@codecov-io
Copy link

codecov-io commented Mar 9, 2020

Codecov Report

Merging #98 into master will increase coverage by 1.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
+ Coverage   36.43%   37.47%   +1.04%     
==========================================
  Files           6        6              
  Lines         538      547       +9     
==========================================
+ Hits          196      205       +9     
  Misses        320      320              
  Partials       22       22
Impacted Files Coverage Δ
server/autolinkplugin/plugin.go 60.41% <100%> (+4.09%) ⬆️

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 5e53e3f...34e1a57. Read the comment docs.

@vespian vespian force-pushed the prozlach/GH-94_no_rewriting_for_bots branch 2 times, most recently from 75d2539 to 34e1a57 Compare March 9, 2020 20:01
@vespian
Copy link
Contributor Author

vespian commented Mar 9, 2020

@hanzei Ready for another pass.

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

One non blocking comment 👍

server/autolinkplugin/plugin.go Outdated Show resolved Hide resolved
@vespian vespian force-pushed the prozlach/GH-94_no_rewriting_for_bots branch from 34e1a57 to 2c0ad05 Compare March 10, 2020 17:43
func (p *Plugin) ProcessPost(c *plugin.Context, post *model.Post) (*model.Post, string) {
isBot, appErr := p.isBotUser(post.UserId)
Copy link
Contributor

Choose a reason for hiding this comment

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

It is likely considerably more expensive to go back to the server to get the user record than first evaluating to see if any links apply. 3/5 we should move this check after an applicable link is found.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@levb I am curious - what does 3/5, 0/5 mean? I often see it in reviews.

Copy link
Contributor Author

@vespian vespian Mar 10, 2020

Choose a reason for hiding this comment

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

Wrt. your comment - we do not really have data on how big/how numerous the rules can get, and how much traffic we may need to rewrite and how the plugin system and querying the server performs under load. The rewriting rules also already call p.API.GetChannel and p.API.GetTeam api calls which may be heavier than the p.API.GetUser that we are adding and actually having isBot check early may save CPU cycles.

I believe optimizing it now is a bit early. Would you mind if we ask @hanzei to add his two cents as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@levb @hanzei Ping.

Copy link
Contributor

Choose a reason for hiding this comment

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

(waiting for @hanzei also cc @lieut-data) A single RPC/post is too expensive, anywhere in a plugin, period. We should move the RPCs to after the match, so we only execute them when needed.

Now, I see the argument that if this PR follows the existing pattern, we should stick with it as is, and have a separate ticket to optimize. I'm 1/5 that we shouldn't - let's at least make sure this PR doesn't add overhead.

https://docs.mattermost.com/process/training.html#id8

Copy link
Contributor

Choose a reason for hiding this comment

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

@levb, based on @ali-farooq0's preliminary analysis of the RPC overhead on community, it /seems/ like RPC, itself, isn't that expensive. The real cost is borne by the database queries to resolve this information, but I'm assuming we're already doing one or more of those to post the message in the first place.

That being said, no objections to moving this check below and wrapping in a post.Message != postText test first. Agree we should have a ticket to optimize regardless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the discussion! Requested changes can be found in Do not rewrite messgaes from bots - review fixes #1 commit.

@lieut-data lieut-data changed the title [GH-84] Do not rewrite messgaes from bots [GH-84] Do not rewrite messages from bots Mar 16, 2020
@vespian
Copy link
Contributor Author

vespian commented Mar 16, 2020

@levb Ready for another pass!

Copy link
Contributor

@levb levb left a comment

Choose a reason for hiding this comment

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

LGTM.

I think we should not modify the message when isBot fails.

@@ -131,7 +141,23 @@ func (p *Plugin) ProcessPost(c *plugin.Context, post *model.Post) (*model.Post,

return true
})
post.Message = postText
if post.Message != postText {
isBot, appErr := p.isBotUser(post.UserId)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that if there is a "system failure" in the process of modifying the message, the right thing to do is to pass it through as is. 0/5 if isBot || appErr != nil {...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by in the process of modifying the message? isBotUser does not modify the message.

@jfrerich jfrerich mentioned this pull request Mar 19, 2020
3 tasks
@jfrerich
Copy link
Contributor

@vespian, can you please merge from master and resolve the conflict in plugin_test.go

@lieut-data, gentle ping for review

@lieut-data
Copy link
Contributor

Thanks, @jfrerich! Happy to defer to @hanzei and @levb's reviews here -- nothing blocking from my side :)

@levb levb added 1: PM Review Requires review by a product manager and removed 2: Dev Review Requires review by a core committer labels Mar 23, 2020
@jfrerich
Copy link
Contributor

@lieut-data thanks for checking back in. I know we already have the two dev reviews and just checking you had no further comments :)

@vespian vespian force-pushed the prozlach/GH-94_no_rewriting_for_bots branch from ce6ce1d to 222fb8f Compare March 23, 2020 18:04
@vespian
Copy link
Contributor Author

vespian commented Mar 23, 2020

@vespian, can you please merge from master and resolve the conflict in plugin_test.go

@jfrerich Done.

@DHaussermann
Copy link

@vespian or @lieut-data can you help me understand the scope of this change? I'm not sure how to validate this and exactly what it should do.

I'm seeing the the Links are still working for posts made the Jira bot or GitHub bot which is great.
When I make a post with a bot I have created the autolink is not applied even when post content matches the pattern.
This seems like the desired behavior but how is it working? Are post from some bots already formatted to contain a link to GitHub, Jira, etc so it's not actually autolink modifying the post contents?

@lieut-data
Copy link
Contributor

@DHaussermann, exactly, GitHub/Jira already knows how to format its own links. The easiest way to truly verify might be to setup the conditions of #94 with an at-mention to yourself on a commit that autolink would have otherwise rewritten. Assuming that stops working, and the normal links stays in place, I think we're good.

Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

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

Tested and passed.

  • Ensured autolink is not formatting bot posts
  • Regression tested posts made from GitHub and Jira
  • Added release testing
    LGTM!
    Thanks @vespian for your effort on this!

@DHaussermann DHaussermann added QA Review Done PR has been approved by QA 1: PM Review Requires review by a product manager and removed 1: PM Review Requires review by a product manager 3: QA Review Requires review by a QA tester labels Mar 30, 2020
@lieut-data
Copy link
Contributor

@aaronrothschild, any objections to this change?

Copy link

@aaronrothschild aaronrothschild left a comment

Choose a reason for hiding this comment

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

LGTM. This makes sense to me. Good addition!

@aaronrothschild aaronrothschild removed the 1: PM Review Requires review by a product manager label Mar 30, 2020
@hanzei hanzei added the 4: Reviews Complete All reviewers have approved the pull request label Mar 31, 2020
@hanzei hanzei added this to the v1.2.0 milestone Mar 31, 2020
@hanzei hanzei merged commit a646d82 into mattermost-community:master Mar 31, 2020
@vespian vespian deleted the prozlach/GH-94_no_rewriting_for_bots branch March 31, 2020 09:59
mo2menelzeiny pushed a commit to mo2menelzeiny/mattermost-plugin-autolink that referenced this pull request Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request QA Review Done PR has been approved by QA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autolink should ignore bot posts. (was: Commit notifications trigger unexpected link preview)
8 participants