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

Add Router to runtime.Params #3458

Merged
merged 1 commit into from May 17, 2021
Merged

Add Router to runtime.Params #3458

merged 1 commit into from May 17, 2021

Conversation

jkbschmid
Copy link
Contributor

All changes to public APIs must be accompanied with
docs. Examples of public APIs include built-in functions,
config fields, and of course, exported Go types/functions/constants/etc.

Not sure how/whether to document a change of runtime.Params

Copy link
Member

@tsandall tsandall left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just one comment on the test. @srenatus might have more input.

Comment on lines 3618 to 3628
r, err := http.NewRequest(http.MethodGet, "/customEndpoint", nil)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
if err := f.executeRequest(r, http.StatusOK, ""); err != nil {
t.Fatalf("Request to custom endpoint failed: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

I can make a guess about the current behaviour but it would be useful to verify that (a) the normal server routes are intact and (b) what happens if the provided router contains routes that overlap w/ the OPA server (e.g., what if the router had been called with "/v1/data"?)

Copy link

Choose a reason for hiding this comment

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

I agree with point a. You might check existing routes are good after you've initialized this new router. It should be ok according to mux docs but knowing for sure is good too.

On point b) are you not testing the behavior of mux if you do that? Mux does not allow duplicate routes afaik but I would expect any behavior of duplicate routes to behave as documented by mux.

Some note on this behavior in the docs though would likely help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points.
a) I added a call to /v1/data to ensure default routes are still available
b) Turns out Gorilla matches routes in registration order, so overriding a route as requested originally in #2777 is possible (I tested this as well). This behaviour is explicitly documented in the Gorilla README, so I think we can expect Gorilla to behave like this even without a test.

@srenatus srenatus self-requested a review May 13, 2021 20:17
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

This looks good so far! 👍

@jkbschmid jkbschmid changed the title [DRAFT] Add Router to runtime.Params Add Router to runtime.Params May 17, 2021
srenatus
srenatus previously approved these changes May 17, 2021
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks, this is a nice contribution 👏

The code looks good to me, there are two small things, with those addressed, I'd happily get this merged:

  1. The "first matching route wins" behaviour is currently only mentioned in review comments on this PR. I think it could be made more apparent, by adding another sentence to the Router comments in runtime.go (or alternatively adding a test case).
  2. If you don't mind, please squash your commits before we merge this. :)

Thanks again! 🎉

  - Allows extending the REST API by creating a custom runtime object
  - Allows overriding existing routes since Router matches routes in order of registration

Signed-off-by: Jakob Schmid <jakob.schmid@sap.com>
@jkbschmid
Copy link
Contributor Author

  • Added a comment
  • squashed commits

Thanks for your reviews :)

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thank you 👏

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.

None yet

4 participants