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

lua: Add per filter config for Lua filter #11235

Merged
merged 20 commits into from
Jul 1, 2020
Merged

Conversation

wbpcode
Copy link
Member

@wbpcode wbpcode commented May 18, 2020

Commit Message: Add per filter config support for Lua filter.

This allows Lua filter to support per-route configuration. This patch enables the configured Lua filter to have multiple registered codes that can be referenced from each per-route config. Disabling running the global Lua filter for a route is also supported.

Risk Level: Low
Testing: Added.
Docs Changes: Added.
Release Notes: Added.
Fixes: #9279 #3124

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/.
CC @envoyproxy/api-watchers: FYI only for changes made to api/.

🐱

Caused by: #11235 was opened by wbpcode.

see: more, trace.

string name = 2 [(validate.rules).string = {min_bytes: 1}];

// Lua source code from RDS directly.
config.core.v3.DataSource code = 3;
Copy link
Member

Choose a reason for hiding this comment

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

Should name and code be in a oneof?

Copy link
Member Author

Choose a reason for hiding this comment

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

The name is used to refer to a Lua script in the global configuration, and the code is used to configure a Lua script directly in the Route. They should not be configured repeatedly.

Copy link
Member

Choose a reason for hiding this comment

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

I kinda agree with @htuch, what is the expected behavior when we set both?

Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot set the name and code at the same time. If you need to use the same script in different routes, you can send the script through LDS, and then set the name field in the route configuration. When the script is large, a part of redundant configuration can be reduced. The code is for better flexibility, to avoid all scripts must be issued using LDS.

Copy link
Member

Choose a reason for hiding this comment

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

I suggest a oneof for this.

Copy link
Member

Choose a reason for hiding this comment

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

OK, it seems like it is. One of disabled, name, or code.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good, but nit, rename s/code/source_code/ for consistency with source_codes.

Copy link
Member

Choose a reason for hiding this comment

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

@wbpcode could you rename this to source_code as per @htuch's comment?

@wbpcode wbpcode force-pushed the lua branch 2 times, most recently from 4a85e30 to 480f466 Compare May 19, 2020 12:12
@wbpcode
Copy link
Member Author

wbpcode commented May 19, 2020

This PR is based on @dio 's work.
Lua per route config allows users to execute different Lua scripts in different routes. It also allows users to directly reference a Lua script in the global configuration. The following is a typical configuration.

          http_filters:
          - name: envoy.lua
            config:
              inline_code: |
                function envoy_on_response(request_handle)
                  request_handle:headers():add("Global catchall","Delivery catch all")
                end
              source_codes:
                route1.lua:
                  inline_string: |
                    function envoy_on_request(request_handle)
                      request_handle:headers():add("Requested","route 1")
                    end
                    function envoy_on_response(response_handle)
                      response_handle:headers():add("Handled","route 1")
                    end
                route2.lua:
                  inline_string: |
                    function envoy_on_request(request_handle)
                      request_handle:headers():add("Requested","route 2")
                    end
                    function envoy_on_response(response_handle)
                      response_handle:headers():add("Handled","route 2")
                    end

              routes:
              - match:
                  prefix: "/route1"
                route:
                  prefix_rewrite: /anything
                  cluster: httpbin
                per_filter_config:
                  envoy.lua:
                    name: route1.lua        # Ref 'route1.lua' in global configuration.
              - match:
                  prefix: "/route2"         # No config and GLOBAL Lua script will be loaded.
                route:
                  prefix_rewrite: /anything
                  cluster: httpbin
              - match:
                  prefix: "/route4"
                route:
                  prefix_rewrite: /anything
                  cluster: httpbin
                per_filter_config:
                  envoy.lua:
                    disabled: true           # Lua filter is disabled
              - match:
                  prefix: "/route5"
                route:
                  prefix_rewrite: /anything
                  cluster: httpbin
                per_filter_config:
                  envoy.lua:
                    code:                     # Lua script embedded in the route
                      inline_string: |
                        function envoy_on_request(request_handle)
                          request_handle:headers():add("Requested","route in route")
                        end
                        function envoy_on_response(response_handle)
                          response_handle:headers():add("Handled","route in route")
                        end

@jmarantz
Copy link
Contributor

@wbpcode please do not force-push in Envoy PRs. It makes reviewing your PR impossible.

Also, can you fix format errors? That will unblock the rest of CI.

Thank you!

Signed-off-by: wbpcode <comems@msn.com>
@wbpcode
Copy link
Member Author

wbpcode commented May 19, 2020

@wbpcode please do not force-push in Envoy PRs. It makes reviewing your PR impossible.

Also, can you fix format errors? That will unblock the rest of CI.

Thank you!

Okay.

Signed-off-by: wbpcode <comems@msn.com>
@wbpcode wbpcode changed the title [WIP] Add per filter config for lua filter Add per filter config for lua filter May 20, 2020
@stale
Copy link

stale bot commented May 30, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label May 30, 2020
@stale
Copy link

stale bot commented Jun 6, 2020

This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot closed this Jun 6, 2020
@erikbos
Copy link
Contributor

erikbos commented Jun 10, 2020

Any luck of this one getting reviewed and merged in?

@dio dio reopened this Jun 10, 2020
@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Jun 10, 2020
Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up. Sorry for the super late response. Seems like this one is fell off my radar. Sorry.

Functionally it looks good. However, we need to add docs as well regarding this newly introduced features.

string name = 2 [(validate.rules).string = {min_bytes: 1}];

// Lua source code from RDS directly.
config.core.v3.DataSource code = 3;
Copy link
Member

Choose a reason for hiding this comment

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

I kinda agree with @htuch, what is the expected behavior when we set both?

docs/root/version_history/current.rst Outdated Show resolved Hide resolved
api/envoy/extensions/filters/http/lua/v3/lua.proto Outdated Show resolved Hide resolved
source/extensions/filters/http/lua/lua_filter.cc Outdated Show resolved Hide resolved
source/extensions/filters/http/lua/lua_filter.cc Outdated Show resolved Hide resolved
test/extensions/filters/http/lua/lua_filter_test.cc Outdated Show resolved Hide resolved
test/extensions/filters/http/lua/lua_filter_test.cc Outdated Show resolved Hide resolved
test/extensions/filters/http/lua/lua_filter_test.cc Outdated Show resolved Hide resolved
test/extensions/filters/http/lua/lua_filter_test.cc Outdated Show resolved Hide resolved
source/extensions/filters/http/lua/lua_filter.h Outdated Show resolved Hide resolved
Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Requesting changes for this. 🙂

@dio dio changed the title Add per filter config for lua filter lua: Add per filter config for Lua filter Jun 10, 2020
@dio
Copy link
Member

dio commented Jun 10, 2020

@wbpcode I also appreciate it if you could elaborate on the changes introduced in this PR into a proper commit message. Thanks!

@wbpcode
Copy link
Member Author

wbpcode commented Jun 10, 2020

Thanks for your detailed review and I will try to update this PR ASAP. @dio

@wbpcode
Copy link
Member Author

wbpcode commented Jun 10, 2020

@wbpcode I also appreciate it if you could elaborate on the changes introduced in this PR into a proper commit message. Thanks!

I will.

@dio
Copy link
Member

dio commented Jun 10, 2020

I think you should do "merge master" as well. Thank you!

@wbpcode wbpcode changed the title lua: Add per filter config for Lua filter [WIP] lua: Add per filter config for Lua filter Jun 11, 2020
wbpcode added 2 commits June 30, 2020 15:31
Signed-off-by: wbpcode <comems@msn.com>
Signed-off-by: wbpcode <comems@msn.com>
@wbpcode
Copy link
Member Author

wbpcode commented Jun 30, 2020

A new commit that reduced redundant code and updated integration test.

@wbpcode
Copy link
Member Author

wbpcode commented Jun 30, 2020

/retest

@repokitteh-read-only
Copy link

🐴 hold your horses - no failures detected, yet.

🐱

Caused by: a #11235 (comment) was created by @wbpcode.

see: more, trace.

mattklein123
mattklein123 previously approved these changes Jun 30, 2020
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks, nice work!

@mattklein123
Copy link
Member

Please check CI and merge master.

/wait


// A name of a Lua source code stored in
// :ref:`Lua.source_codes <envoy_v3_api_field_extensions.filters.http.lua.v3.Lua.source_codes>`.
string name = 2 [(validate.rules).string.min_len = 1];
Copy link
Member

Choose a reason for hiding this comment

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

string name = 2 [(validate.rules).string = {min_len: 1}];

@wbpcode
Copy link
Member Author

wbpcode commented Jul 1, 2020

/retest

@repokitteh-read-only
Copy link

🐴 hold your horses - no failures detected, yet.

🐱

Caused by: a #11235 (comment) was created by @wbpcode.

see: more, trace.

@wbpcode
Copy link
Member Author

wbpcode commented Jul 1, 2020

hmmm, look some wrong with this windows ci.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

6 participants