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

I'm trying to develop an ab-test plugin, how to implement it? #841

Closed
membphis opened this issue Nov 12, 2019 · 11 comments
Closed

I'm trying to develop an ab-test plugin, how to implement it? #841

membphis opened this issue Nov 12, 2019 · 11 comments

Comments

@membphis
Copy link
Member

Hi, I'm trying to develop an ab-test plugin and it will be used for the backend API's URI or params control. The configuration below is my simple design. I'm not sure whether it is a generic feature. Looking forward to your suggestion.

{
    "ab-test-rewrite": {
        "enabled": true,
        "default": {
            "uri": "/test/home.html",
            "scheme": "http",
            "host": "iresty.com",
            "headers": {
                "X-Api-Version": "v1",
                "X-Api-Engine": "apisix",
                "X-Api-useless": ""
            }
        },
        "tests": [
            {
                "condition": [
                    {
                        "proccessor": "mod|7",
                        "field": "userid",
                        "range": "0,4"
                    }
                ],
                "rewrite": {
                    "uri": "/test?group_id=234"
                }
            },
            {
                "condition": [
                    {
                        "proccessor": "mod|7",
                        "field": "userid",
                        "range": "5,6"
                    }
                ],
                "rewrite": {
                    "uri": "/test?group_id=83838"
                }
            }
        ]
    }
}
@membphis
Copy link
Member Author

You can make a try with this way:

curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
    "uri": "/index.html",
    "filter_func": "function(vars) return vars.arg_id and (vars.arg_id % 7 <= 4) end",
    "plugins": {
        "redirect": {
            "uri": "/test?group_id=234"
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "39.97.63.215:80": 1
        }
    }
}'


curl -i http://127.0.0.1:9080/apisix/admin/routes/2 -X PUT -d '
{
    "uri": "/index.html",
    "filter_func": "function(vars) return vars.arg_id and (vars.arg_id % 7 > 4) end",
    "plugins": {
        "redirect": {
            "uri": "/test?group_id=83838"
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "39.97.63.215:80": 1
        }
    }
}'

@membphis
Copy link
Member Author

membphis commented Nov 12, 2019

Better way: we can support more operator like mod for lua-resty-radixtree.

Here is the operator list of current:
https://github.com/iresty/lua-resty-radixtree#operator-list

It may be like this:

curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
    "uri": "/index.html",
    "vars": [
        {"arg_id", "%", "7", "<=", 4}
    ]
    "plugins": {
        "redirect": {
            "uri": "/test?group_id=234"
        }
    }
}'

@Beckjiang
Copy link
Contributor

This way basically can solve my problem and is graceful. I will think about it.

@membphis
Copy link
Member Author

feel happy to help you.

@soulsoul
Copy link
Member

i think we should implement a rule engine .we can compute by the express. like >, <, mod etc.

@membphis
Copy link
Member Author

i think we should implement a rule engine .we can compute by the express. like >, <, mod etc.

#841 (comment)

how about this way?

@moonming
Copy link
Member

we can add doc and examples for the powerful route

@soulsoul
Copy link
Member

i think we should implement a rule engine .we can compute by the express. like >, <, mod etc.

#841 (comment)

how about this way?

i like this, but is the support limited?

@membphis
Copy link
Member Author

membphis commented Nov 27, 2019

i like this, but is the support limited?

"vars": [
        {"arg_id", "%", "7", "<=", 4}
    ]

it means: ngx.var.arg_id % 7 <= 4. I create a new issue: api7/lua-resty-radixtree#32 , lua-resty-radixtree not support operator % now.

@moonming
Copy link
Member

I think we should write this into doc.

@membphis
Copy link
Member Author

I think we should write this into doc.

This is still a todo thing.

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

No branches or pull requests

4 participants