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

Support global plugin #820

Closed
juzhiyuan opened this issue Nov 18, 2020 · 15 comments · Fixed by #1106
Closed

Support global plugin #820

juzhiyuan opened this issue Nov 18, 2020 · 15 comments · Fixed by #1106
Assignees
Milestone

Comments

@juzhiyuan
Copy link
Member

juzhiyuan commented Nov 18, 2020

Background

The global plugin acts on every request and it is not bound to any Service, Route, or Consumer, which reduces the need to set up the same plugin configuration repeatedly for multiple resources.

Solution

Frontend

In the plug-in module, we will first support the global plugin, and in-scope plugin in the future. In this proposal, the focus will be on the global plugin.

3 pages are involved:

  1. The plugin enabled list page;
  2. Plugin list page;
  3. The plugin configuration page.

In this revision, the plugin list page and plugin configuration page will be adjusted, and the following are the changes:

  1. The plugin list page is only used to select plug-ins;
  2. Plugin configuration from the original drawer, changed to a separate plugin configuration page, mainly to be compatible with the increase in the number of fields behind, resulting in the drawer can not well carry more content.

image

Use process

  1. Users in the plugin module, click the Add Plugin button to jump to the plug-in list page;
  2. The user in the plugin list page, find the target plugin, then click the configuration button to enter the plugin configuration page;
  3. Users in the plugin configuration page, you can choose to enable or disable the plugin, you can choose the scope of the plugin: global or with scope (Service, Route), currently only supports the global;
  4. The user enters data in the plugin data editor (form or code editor, currently only the latter is supported) and returns to the enabled plugins list page after successful saving.

NOTE
We will modify 3 modules:

  1. Add Plugins module;
  2. Update Route, Consumer with the latest plugin component mentioned above.

Backend

refer to https://github.com/apache/apisix/blob/5de6ee467f83c38f31eff6cfd683736b441ac9c2/doc/zh-cn/architecture-design.md#global-rule

API: set global plugins

PUT /apisix/admin/global_rules/{FIXED_GLOBAL_RULE_ID}
{
        "plugins": {
            "limit-count": {
                "time_window": 60,
                "policy": "local",
                "count": 2,
                "key": "remote_addr",
                "rejected_code": 503
            }
        }
    }

API: get global plugins

GET /apisix/admin/global_rules/{FIXED_GLOBAL_RULE_ID}
{
        "plugins": {
            "limit-count": {
                "time_window": 60,
                "policy": "local",
                "count": 2,
                "key": "remote_addr",
                "rejected_code": 503
            }
        }
    }

Reference

@juzhiyuan juzhiyuan added this to the 2.1 milestone Nov 18, 2020
@juzhiyuan juzhiyuan self-assigned this Nov 18, 2020
@moonming
Copy link
Member

We need to list the plug-in as an object separately, at this time etcd may not be convenient to use directly

@juzhiyuan
Copy link
Member Author

got it

@moonming
Copy link
Member

why remove from MS?

@juzhiyuan juzhiyuan added this to the 2.3 milestone Dec 11, 2020
@membphis
Copy link
Member

@juzhiyuan you need to submit your design for this issue and update the title

@juzhiyuan
Copy link
Member Author

Of course, the proposal would be finished and discuss completed no longer than next week.

@juzhiyuan juzhiyuan added wait for update 1. Solution 2. Due date 3. Assignees if needed and removed wait for update 1. Solution 2. Due date 3. Assignees if needed labels Dec 12, 2020
@juzhiyuan juzhiyuan changed the title [DRAFT] Support global plugin Support global plugin Dec 13, 2020
@juzhiyuan
Copy link
Member Author

Please take a look at this proposal, to check if there have any improvements about Global Plugin.

cc @nic-chen @liuxiran @ShiningRush @tokers @LiteSun @Miss-you @membphis

@membphis
Copy link
Member

@juzhiyuan the Admin API has implemented the global rule API: https://github.com/apache/apisix/blob/5de6ee467f83c38f31eff6cfd683736b441ac9c2/doc/zh-cn/architecture-design.md#global-rule

So I think we'd better use the existing APIs.

@membphis
Copy link
Member

image

@juzhiyuan
Copy link
Member Author

juzhiyuan commented Dec 13, 2020

@membphis np, I just updated the proposal about the API part.

Global Plugin is easier to understand than Global Rule IMHO 🤔 Let's wait for others feedback.

@nic-chen
Copy link
Member

I think the APIs should be consistent with the existing, refer to:

API: set global rule

PUT /apisix/admin/global_rules/1
{
        "plugins": {
            "limit-count": {
                "time_window": 60,
                "policy": "local",
                "count": 2,
                "key": "remote_addr",
                "rejected_code": 503
            }
        }
    }

API: get global rule

GET /apisix/admin/global_rules/1
{
        "plugins": {
            "limit-count": {
                "time_window": 60,
                "policy": "local",
                "count": 2,
                "key": "remote_addr",
                "rejected_code": 503
            }
        }
    }

API: get global rule list(new)

GET /apisix/admin/global_rules?page=1&page_size=10
{
    "code": 0,
    "message": "",
    "data": {
        "rows": [
            {
                "id": 1,
                "plugins": {
                    "limit-count": {
                        "time_window": 60,
                        "policy": "local",
                        "count": 2,
                        "key": "remote_addr",
                        "rejected_code": 503
                    }
                }
            }
        ]
    }
}

@juzhiyuan

This comment has been minimized.

@moonming
Copy link
Member

There is a more obvious problem in this design:
The plugin menu bar on the left is not just for global plugins. It can also become a universal plug-in object like service and upstream. For example, a limit count plugin and configuration can be referenced by multiple routes.

The global plug-in is just an attribute of the plug-in, and it is not worth a separate menu.

@juzhiyuan
Copy link
Member Author

after discussion with @membphis @moonming @nic-chen, we have reached an agreement in the general direction, I will update the proposal today:

  • UE
  • features in the future

@juzhiyuan
Copy link
Member Author

Hello, I just updated this proposal, kindly review when you are free 😊

cc @nic-chen @liuxiran @membphis @moonming

@juzhiyuan juzhiyuan assigned LiteSun and unassigned juzhiyuan Dec 18, 2020
This was referenced Dec 25, 2020
@sampy2518
Copy link

I have a peculiar situation in my project where I am trying to replace my existing old Proxy code with APISIX. my current proxy backtrack the versions apis and services in a different way. for example.
API Versions available : V1, V2, V3

Routes should be created in below format
V1
API1
Service1
Service2
API2
Service3
Service4
API3
Service5

V2
API2
Service4
API4
Service6
V3
API2
Service4
API5
Service7

API routing, fallback and backtracking rules to follow
case 1:
APP A : current Version used V2. All any API from the frontend will be called with V2

Invoke V2/API1/Service1/ will be redirected to V1/API1/Service1, As it is not present in current version V2, so it will backtrack or fallback to previous version which is V1 and search for the Service1 in API1.

Invoke V2/API1/Service2/ will be redirected to V1/API1/Service2, As it is not present in current version V2, so it will backtrack or fallback to previous version which is V1 and search for the Service2 in API1.

Invoke V2/API2/Service3/ will be redirected to V1/API2/Service3, As it is not present in current version V2, so it will backtrack or fallback to previous version which is V1 and search for the Service3 in API2.

Invoke V2/API2/Service4/ will be redirected to V2/API2/Service4, As it is present in V2

Invoke V2/API3/Service5/ will be redirected to V1/API3/Service5, As it is not present in current version V2, so it will backtrack or fallback to previous version which is V1 and search for the Service5 in API3.

Invoke V2/API4/Service6/ will be redirected to V2/API4/Service6, As it is present in V2

case 2:
APP b : current Version used V3. All any API from the frontend will be called with V3

Invoke V3/API1/Service1/ will be redirected to V1/API1/Service1, As it is not present in current version V3, so it will backtrack or fallback to previous version which is V1 and search for the Service1 in API1.

Invoke V3/API1/Service2/ will be redirected to V1/API1/Service2, As it is not present in current version V3, so it will backtrack or fallback to previous version which is V1 and search for the Service2 in API1.

Invoke V3/API2/Service3/ will be redirected to V1/API2/Service3, As it is not present in current version V3, so it will backtrack or fallback to previous version which is V1 and search for the Service3 in API2.

Invoke V3/API2/Service4/ will be redirected to V3/API2/Service4, As it is present in V3

Invoke V3/API3/Service5/ will be redirected to V1/API3/Service5, As it is not present in current version V3, so it will backtrack or fallback to previous version which is V1 and search for the Service5 in API3.

Invoke V3/API4/Service6/ will be redirected to V2/API4/Service6, As it is not present in current version V3, so it will backtrack or fallback to previous version which is V2 and search for the Service6 in API4.

Invoke V3/API4/Service7/ will be redirected to V3/API5/Service7, As it is present in V3

I would like to ask how can i define a customer global plugin which is work when for any incoming request from client and rewrite the URL as per above rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants