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

[Bugfix] set proxy_pass_request_body off when redirect to FE #303

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions pkg/sub_controller/feproxy/feproxy_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func (controller *FeProxyController) SyncConfigMap(ctx context.Context, src *sra
}
httpPort := rutils.GetPort(config, rutils.HTTP_PORT)

feServiceName := service.ExternalServiceName(src.Name, src.Spec.StarRocksFeSpec)
proxyPass := fmt.Sprintf("http://%s:%d", feServiceName, httpPort)
feSearchServiceName := service.SearchServiceName(src.Name, feSpec)
feExternalServiceName := service.ExternalServiceName(src.Name, feSpec)
proxyPass := fmt.Sprintf("http://%s:%d", feExternalServiceName, httpPort)

resolver := feProxySpec.Resolver
if resolver == "" {
Expand Down Expand Up @@ -74,7 +75,7 @@ http {

server {
listen 8080;
resolver %v;
resolver %[1]s;
proxy_intercept_errors on;
recursive_error_pages on;

Expand All @@ -84,7 +85,7 @@ http {
}

location / {
proxy_pass %v;
proxy_pass %[2]s;
proxy_set_header Expect $http_expect;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand All @@ -93,7 +94,7 @@ http {
}

location /api/transaction/load {
proxy_pass %v;
proxy_pass %[2]s;
proxy_pass_request_body off;
proxy_set_header Expect $http_expect;
proxy_set_header Host $host;
Expand All @@ -103,7 +104,7 @@ http {
}

location ~ ^/api/.*/.*/_stream_load$ {
proxy_pass %v;
proxy_pass %[2]s;
proxy_pass_request_body off;
proxy_set_header Expect $http_expect;
proxy_set_header Host $host;
Expand All @@ -113,6 +114,26 @@ http {
}

location @handle_redirect {
if ($upstream_http_location ~ "%[3]s") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about

set $pass_body on;
if ( xxx ) {
    set $pass_body off;
}

proxy_pass_request_body $pass_body;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if can be used in rewrite context. See https://nginx.org/en/docs/http/ngx_http_rewrite_module.html

Copy link
Collaborator

Choose a reason for hiding this comment

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

just need to check if it is a FE redirect and set $pass_body accordingly, no need to do rewrite.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, I tried. if is not allowed to use without rewrite.

rewrite ^ /_redirect_to_fe last;
}
if ($upstream_http_location !~ "%[3]s") {
rewrite ^ /_redirect_to_others last;
}
}

location /_redirect_to_fe {
set $redirect_uri '$upstream_http_location';
proxy_pass $redirect_uri;
proxy_set_header Expect $http_expect;
proxy_pass_request_body off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
error_page 307 = @handle_redirect;
}

location /_redirect_to_others {
set $redirect_uri '$upstream_http_location';
proxy_pass $redirect_uri;
proxy_set_header Expect $http_expect;
Expand All @@ -124,7 +145,7 @@ http {
}
}
}
`, resolver, proxyPass, proxyPass, proxyPass),
`, resolver, proxyPass, feSearchServiceName),
},
}

Expand Down