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

MM-51188 Use mux.Router #923

Merged
merged 7 commits into from
Apr 3, 2023
Merged

MM-51188 Use mux.Router #923

merged 7 commits into from
Apr 3, 2023

Conversation

srkgupta
Copy link
Contributor

Summary

Migrate JIRA codebase to use mux.Router

Ticket Link

https://mattermost.atlassian.net/browse/MM-51188

@srkgupta srkgupta changed the title Mm 51188 mux router MM-51188 Use mux.Router Mar 17, 2023
@srkgupta srkgupta requested review from hanzei and m1lt0n March 17, 2023 12:56
@srkgupta srkgupta added the 2: Dev Review Requires review by a core committer label Mar 17, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Patch coverage: 76.98% and project coverage change: +1.05 🎉

Comparison is base (a7f0e41) 29.96% compared to head (09fdf38) 31.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #923      +/-   ##
==========================================
+ Coverage   29.96%   31.01%   +1.05%     
==========================================
  Files          49       50       +1     
  Lines        7520     7383     -137     
==========================================
+ Hits         2253     2290      +37     
+ Misses       5078     4907     -171     
+ Partials      189      186       -3     
Impacted Files Coverage Δ
server/atlassian_connect.go 0.00% <ø> (ø)
server/autocomplete_search.go 0.00% <ø> (ø)
server/command.go 16.06% <0.00%> (ø)
server/info.go 62.50% <ø> (+8.92%) ⬆️
server/instances.go 32.90% <ø> (+2.72%) ⬆️
server/issue.go 30.37% <ø> (+0.43%) ⬆️
server/plugin.go 10.99% <0.00%> (+1.51%) ⬆️
server/setup_flow.go 0.00% <0.00%> (ø)
server/user.go 27.12% <ø> (+4.33%) ⬆️
server/user_cloud.go 0.00% <ø> (ø)
... and 6 more

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link

@m1lt0n m1lt0n left a comment

Choose a reason for hiding this comment

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

LGTM! One minor/non-blocking comment: I was torn between the prefixed router or the full route names as approaches, but not a both have their pros and cons, so 0/5 on it.

@hanzei hanzei added the 3: QA Review Requires review by a QA tester label Mar 20, 2023
Copy link
Collaborator

@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.

Neat 🚀

There are some method check accross the repo like in

if r.Method != http.MethodPost {
return respondErr(w, http.StatusMethodNotAllowed,
errors.New("method "+r.Method+" is not allowed, must be POST"))
}
. Can these get removed?

return
}

status, err := fn(w, r, callbackInstanceID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit pick: Can handleResponse be used here with an adapter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hanzei, can you please elaborate?

Copy link
Collaborator

Choose a reason for hiding this comment

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

By replacing this line and the following with

Suggested change
status, err := fn(w, r, callbackInstanceID)
p.handleResponse(func(w http.ResponseWriter, r *http.Request) (int, error) {
return fn(w, r, callbackInstanceID)
})

we estimate the duplicate code that takes care of the status code..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Makes sense 👍 Updated the code now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hanzei the suggested logic would not work, as the underlying functions being called were not getting the expected callbackInstanceID. Hence instead of this, I have now added a common function to parse the status and the error and log them from a single function instead of writing duplicate code. Hope this is fine.

b6ff1d8

Copy link
Contributor

@mickmister mickmister left a comment

Choose a reason for hiding this comment

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

Great improvement here 👍

Just a few suggestions

server/command.go Outdated Show resolved Hide resolved
server/http.go Outdated Show resolved Hide resolved
server/http.go Outdated Show resolved Hide resolved
server/http.go Outdated Show resolved Hide resolved
server/http.go Outdated Show resolved Hide resolved
server/webhook.go Outdated Show resolved Hide resolved
@srkgupta
Copy link
Contributor Author

@hanzei @mickmister, I have implemented the review comments and some additional findings like using checkAuth as part of the router handler. Re-requesting your reviews.

@DHaussermann
Copy link

@srkgupta I may be mistaken but I believe something is broken here. When I try to smoke test by installing a cloud instance, the .json which provides the installation details seem to no longer be reachable and returns a 404. This causes the install from the Jira side to fail.

Please let me know if you can reproduce this or perhaps there is some unrelated cause I have overlooked.

Steps:

  • Install the latest production release and enable the plugin
  • Run /jira instance install cloud https://mmtest.atlassian.net
  • In the ephemeral post note that a link in generated to https://dkh-local.ngrok.io/plugins/jira/instance/aHR0cHM6Ly9tbXRlc3QuYXRsYXNzaWFuLm5ldA==/ac/atlassian-connect.json Your MM URL will differ but clicking the link open a .json object in a new tab with installation details
  • Upgrade to MM-51188_mux-routerbranch
  • Run connect command again (optional as the lik address has not changed)
    Observed the same URL now goes to a 404 when clicked

@srkgupta
Copy link
Contributor Author

Thanks @DHaussermann for catching this issue. I have fixed the issue and pushed a new commit. It should resolve the issue. Can you please specifically check the entire OAuth1 & the Connection flows. The HTTP methods for some of these API endpoints were not clearly defined previously. Hence any HTTP method like GET, POST request would work. However with the new mux.Router approach, since its specifically defined, just want to be sure that these are correctly working now.

Copy link
Collaborator

@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.

Two non-blockin comments: #923 (comment)

server/http.go Outdated Show resolved Hide resolved
@hanzei hanzei added this to the v3.3.0 milestone Mar 30, 2023
@hanzei
Copy link
Collaborator

hanzei commented Mar 30, 2023

Great work @srkgupta 👍

@hanzei hanzei removed the 2: Dev Review Requires review by a core committer label Mar 30, 2023
@DHaussermann
Copy link

@srkgupta I have a strange issue where I don't see any change in behavior. When I upload the build and try again I still see the 404 when I click the link to the .json.

I have made sure I have your commits.

image

Any thoughts on if maybe something is causing a deployment issue? Can you confirm you see this working on the latest?

@srkgupta
Copy link
Contributor Author

Hi @DHaussermann

I looked into this in detail and found that the URLs for certain paths started with /instance/{instance_id} and hence had to be handled in a slightly different way. I have fixed this issue and have tested a basic Jira Cloud setup flow and it is working fine now. Please recheck now and let me know if you see any other issues.

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

  • Issue discussed above has been resolved
  • Did a smoke test covering happy path
  • Install works
  • Create and attach funtionallity works
  • Subscriptions creation and delivery works

LGTM!

Thanks @srkgupta 🎉 If we can get this merged, I can then pull this up into #921 and do a bit more testing on all changes.

@DHaussermann DHaussermann added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester labels Mar 31, 2023
@srkgupta srkgupta merged commit a8167cc into master Apr 3, 2023
@srkgupta srkgupta deleted the MM-51188_mux-router branch April 3, 2023 05:01
@mickmister mickmister mentioned this pull request Sep 14, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants