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

[tt-1924] Go plugins per method and path #3489

Merged
merged 19 commits into from
Apr 27, 2021

Conversation

joshblakeley
Copy link
Member

@joshblakeley joshblakeley commented Mar 11, 2021

Description

Allows a Tyk user to run a different Go function in every single possible part of their API if they should want to. Can be a high performance replacement for the JSVM virtual endpoints.

Think of it as having either as many native Go lambda style functions inside the Gateway available to you as you want, or if you want, unlike existing JS virtual endpoints, requests pass through to real upstreams and you just get the extra flexibility of this setup.

Related Issue

Internal ticket viewable here https://tyktech.atlassian.net/browse/TT-1924

Motivation and Context

Our virtual endpoints are really well loved by users but have some issues with high performance scenarios. Go plugins are the most native way to inject extra code into the API Gateway. Previous there were set hooks that a plugin function could sit and every request would route through it.

This PR makes it so that the Go plugins can be loaded per path and method using the usual API designer definitions.

Users can utilise this in a few different ways:

  • A single Go plugin file shared object with multiple handlers that can be called from various APIs
  • Many shared objects each referenced from different plugins.

Both cases are handled and users can mix and match depending on their complexity and code ownership.

How This Has Been Tested

See the /test/goplugin folder for function examples.

In your API definition set up your per path/method goplugin functions as an array of config blocks just like any other API designer middleware.

Functions can all be in a single file or be pulled in from various files.

The same rules apply as with the existing go plugins and we recommend using the Go Plugin compiler container to help you create the shared objects that are guaranteed to work with a particular gateway version.

... 
"extended_paths":  {
            "go_plugin": [
                  {
                "plugin_path": "../test/goplugins/goplugins.so",
                "path": "/get",
                "method": "GET",
                "func_name": "MyPluginPerPathFoo"
              }
             ]
          }
...

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
    • If new config option added, ensure that it can be set via ENV variable
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • When updating library version must provide reason/explanation for this update.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

@joshblakeley joshblakeley force-pushed the feature/goplugin-perpath-middleware branch from 6359edc to fc8e7bb Compare March 24, 2021 08:57
@joshblakeley joshblakeley force-pushed the feature/goplugin-perpath-middleware branch from fc8e7bb to 8f46633 Compare March 24, 2021 09:03
@joshblakeley joshblakeley marked this pull request as ready for review March 24, 2021 09:12
gateway/mw_go_plugin.go Outdated Show resolved Hide resolved
gateway/mw_go_plugin.go Outdated Show resolved Hide resolved
@gregdelhon gregdelhon changed the title Go plugins per method and path [tt-1924] Go plugins per method and path Apr 7, 2021
Copy link
Contributor

@sredxny sredxny left a comment

Choose a reason for hiding this comment

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

LGTM! amazing job

Copy link
Contributor

@tbuchaillot tbuchaillot 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!

@tbuchaillot tbuchaillot merged commit bf5ddd0 into master Apr 27, 2021
@tbuchaillot tbuchaillot deleted the feature/goplugin-perpath-middleware branch April 27, 2021 22:41
@tbuchaillot
Copy link
Contributor

/release to release-3

@tykbot
Copy link

tykbot bot commented Apr 27, 2021

Working on it! Note that it can take a few minutes.

tykbot bot pushed a commit that referenced this pull request Apr 27, 2021
* load go plugins per method and path in apispec

* method check against middleware path

* rename struct tag

* tests and handler grabber from url specs

* load go plugins per method and path in apispec

* rename struct tag

* clean up merge conflicts

* more cleanup and remove print log

* removed unused function

* remove unneccesary print

* remove debugging

* go plugin on api and per path level plus tests

* goimports gw

(cherry picked from commit bf5ddd0)
@tykbot
Copy link

tykbot bot commented Apr 27, 2021

@tbuchaillot Succesfully merged bf5ddd0c3a381e97782b734033b80561d439b0d5 to release-3 branch.

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.

4 participants