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

feat: add try-paths plugins #1598

Closed
wants to merge 0 commits into from
Closed

feat: add try-paths plugins #1598

wants to merge 0 commits into from

Conversation

haifzhu
Copy link
Collaborator

@haifzhu haifzhu commented Dec 17, 2024

Ⅰ. Describe what this PR did

add try-paths wasm go plugin to implement try_files function of nginx。

Ⅱ. Does this pull request fix one issue?

Fix the issue: Add support of try_files usage #840 .

Ⅲ. Why don't you add test cases (unit test/integration test)?

test cases be added in codes.

Ⅳ. Describe how to verify it

enable the plugin on the route, and check its retry function on envoy log or request response.

Ⅴ. Special notes for reviews

no


| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| serviceSource | string | 必填 | - | 支持k8s,nacos,ip,dns |
Copy link
Collaborator

Choose a reason for hiding this comment

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

只支持FQDN格式的serviceName就可以了,这样能简化下配置,不需要配serviceSource

plugins/wasm-go/extensions/try-paths/main.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.52%. Comparing base (ef31e09) to head (58a02c0).
Report is 246 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1598      +/-   ##
==========================================
+ Coverage   35.91%   43.52%   +7.61%     
==========================================
  Files          69       76       +7     
  Lines       11576    12325     +749     
==========================================
+ Hits         4157     5364    +1207     
+ Misses       7104     6626     -478     
- Partials      315      335      +20     

see 69 files with indirect coverage changes

@haifzhu haifzhu requested a review from johnlanni December 18, 2024 04:07

| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| host | string | 必填 | - | FQDN格式的主机名称,比如<bucket name>.oss-cn-hangzhou.aliyuncs.com |
Copy link
Collaborator

Choose a reason for hiding this comment

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

建议两个配置:
serviceHost 配 oss 域名
serviceName 配FQDN格式的服务名称(控制台服务列表看到的名字)

Copy link
Collaborator

Choose a reason for hiding this comment

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

可以参考 ext-auth 里 endpoint 配置项里的 service_host 和 service_name 的概念:https://higress.cn/docs/latest/plugins/authentication/ext-auth/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

建议两个配置: serviceHost 配 oss 域名 serviceName 配FQDN格式的服务名称(控制台服务列表看到的名字)

好的

@haifzhu haifzhu requested a review from rinfx as a code owner December 28, 2024 10:44
@haifzhu haifzhu requested a review from johnlanni December 28, 2024 10:46
@johnlanni
Copy link
Collaborator

这个插件可以改名为 nginx-static-file,以 nginx location 的配置方式实现静态文件的代理(可能是到oss,或者后端的js服务) ,对nginx用户迁移会更有帮助一些:

# 简化处理,按顺序匹配即可
locations:
- location: "~ ^/users/(.+\.(?:gif|jpe?g|png))$"
   # 支持基于 alias 做正则路径改写
   alias: "/data/w3/images/$1"
- location: "/images/"
   # 支持基于 alias 改写目标文件目录
   alias: "/data/w3/images/"
- location: "/images/"
   # 支持基于 root 确定文件根目录
   root: "/data/w3"
- location: "/images/"
   root: "/data/w3"
   # 支持基于 try_files 重试
   try_files: "$uri /images/default.gif"
   # 支持目录路径时,基于index查找文件
   index  index.html index.htm;


| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| `service_name` | string | 必填 | - | 输入重试服务名称,带服务类型的完整 FQDN 名称,例如 `<bucket name>.oss-cn-hangzhou.aliyuncs.com` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

想了下不需要在插件里配置服务,直接获取给路由配置的服务就行了,插件里用 RouteCluster 代替 FQDNCluster:

type RouteCluster struct {

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.

3 participants