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 grpc timeouts annotations #11258

Merged
merged 9 commits into from
May 26, 2024

Conversation

Anddd7
Copy link
Contributor

@Anddd7 Anddd7 commented Apr 13, 2024

What this PR does / why we need it:

This PR adds support for grpc timeout settings via annotations. To avoid introducing security issues with server-snippets, we need a more direct way to configure the nginx grpc module.

Types of changes

  • New feature (non-breaking change which adds functionality)

Which issue/s this PR fixes

fixes #11250

How Has This Been Tested?

with unit tests and e2e tests

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 13, 2024
@k8s-ci-robot k8s-ci-robot requested review from puerco and strongjz April 13, 2024 12:39
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 13, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @Anddd7!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 13, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @Anddd7. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 13, 2024
Copy link

netlify bot commented Apr 13, 2024

Deploy Preview for kubernetes-ingress-nginx ready!

Name Link
🔨 Latest commit ee204a7
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/66383e1d9a365e0008f87fd2
😎 Deploy Preview https://deploy-preview-11258--kubernetes-ingress-nginx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Anddd7
Copy link
Contributor Author

Anddd7 commented Apr 13, 2024

@Anddd7 TODO add docs for annoations and configmap

@longwuyuan
Copy link
Contributor

@Anddd7 thanks for this contribution. It helps.

I am not a developer. So can you help me locate where you are creating the pod that runs the grpc server for test backend

@Anddd7 Anddd7 force-pushed the add-grpc-timeouts branch from 2297425 to f1aed2b Compare April 14, 2024 03:07
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/docs and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 14, 2024
@Anddd7
Copy link
Contributor Author

Anddd7 commented Apr 14, 2024

@longwuyuan to avoid bringing big changes, i set the grpc timeouts with existing proxy timeouts when backend protocol is 'grpc/grpcs'. so we can simply reuse proxy-send-timeout - just set backend-protocol=grpc. https://github.com/kubernetes/ingress-nginx/pull/11258/files#diff-cbf382cc05c9f274b5db56a581b335dba8ecb80fd96a8f1a6a068b2594c9b1caR1484

I add 2 more e2e test in test/e2e/annotations/grpc.go, to ensure grpc timeouts are rendered correctly. There are 3 existing tests that will create grpc server/client covered grpc connection test.

@Anddd7 Anddd7 changed the title WIP - feat: Add grpc timeouts annotations feat: Add grpc timeouts annotations Apr 14, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 14, 2024
@@ -700,6 +700,14 @@ In some scenarios is required to have different values. To allow this we provide
- `nginx.ingress.kubernetes.io/proxy-next-upstream-tries`
- `nginx.ingress.kubernetes.io/proxy-request-buffering`

If you indicate [Backend Protocol](#backend-protocol) as `GRPC` or `GRPCS`, the following values will be applied to gRPC connection as well:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you define the defaults or point to the docs of them please :) users may not know what {{ proxy_connect_timeout }} means. Thanks!!!

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe just point to nginx docs to the defaults and say they can be configured somewhere else

Copy link
Contributor

@longwuyuan longwuyuan Apr 16, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, i added the default values (same as proxy_*_timout) and nginx docs

@rikatz
Copy link
Contributor

rikatz commented Apr 15, 2024

/ok-to-test
/approve

So far looks good to me. I am wondering if we want different annotations for gRPC, but it does make sense to follow the same proxy-timeout from backend.

@longwuyuan I will leave the lgtm to you, after fixing the docs

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 15, 2024
@@ -1481,6 +1481,13 @@ stream {
proxy_next_upstream_timeout {{ $location.Proxy.NextUpstreamTimeout }};
proxy_next_upstream_tries {{ $location.Proxy.NextUpstreamTries }};

{{ if or (eq $location.BackendProtocol "GRPC") (eq $location.BackendProtocol "GRPCS") }}
# Grpc settings
Copy link
Contributor

Choose a reason for hiding this comment

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

question: what happens if the user does not set the proxy configuration timeout? I can't remember if there are defaults for connecttimeout, sendtimeout, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rikatz
Copy link
Contributor

rikatz commented Apr 15, 2024

/approve cancel

@Anddd7 just one question on defaults, maybe we just want to set the values if they are defined on annotations, otherwise leave as is.

This would avoid breaking changes (I'm not sure if the default proxy_timeout and others defaults are the same for gRPC, if you can just double check it I appreciate it)

@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 15, 2024
@Anddd7 Anddd7 force-pushed the add-grpc-timeouts branch from 156aef3 to ee204a7 Compare May 6, 2024 02:19
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2024
@Anddd7
Copy link
Contributor Author

Anddd7 commented May 6, 2024

all tests passed after rebase, feel free to review and comment

@tao12345666333
Copy link
Member

Thank you 🙏

I have added this to my list, will finish review this week.

Comment on lines +1486 to +1488
grpc_connect_timeout {{ $location.Proxy.ConnectTimeout }}s;
grpc_send_timeout {{ $location.Proxy.SendTimeout }}s;
grpc_read_timeout {{ $location.Proxy.ReadTimeout }}s;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be interesting to change the data type from Int to time.Duration, allowing the configuration to be done in milliseconds instead only of in seconds.

Even more interesting would be to have explicit configurations for gRPC backends instead of reusing the global proxy settings. Only use the global ones if the specific ones are not set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like as comment in issue

...
annotations:
  nginx.ingress.kubernetes.io/grpc_read_timeout: 3600
  nginx.ingress.kubernetes.io/grpc_send_timeout: 3600
...

https://github.com/kubernetes/ingress-nginx/blob/main/internal/ingress/annotations/proxy/main.go#L29-L31

Copy link
Member

Choose a reason for hiding this comment

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

Changing the default unit may not be something that should be included in this PR. Because modifying the time unit will break many existing configurations.

Copy link
Member

Choose a reason for hiding this comment

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

@msfidelis Would you want to create an issue for tracking this?

Copy link
Member

@tao12345666333 tao12345666333 left a comment

Choose a reason for hiding this comment

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

Thank you for your contributions!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 26, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Anddd7, tao12345666333, YannickZ

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 26, 2024
@k8s-ci-robot k8s-ci-robot merged commit d0e9934 into kubernetes:main May 26, 2024
27 checks passed
@Anddd7 Anddd7 deleted the add-grpc-timeouts branch May 27, 2024 00:26
@flphvlck
Copy link
Contributor

flphvlck commented Aug 19, 2024

Hi @tao12345666333, I wrote here: #11250 (comment) that this is possible breaking change and should be noted in release notes.

@Dunge
Copy link

Dunge commented Nov 26, 2024

For streaming calls we also need to increase client_body_timeout in the server snippet. This value was not ported to annotations?

@longwuyuan
Copy link
Contributor

@Anddd7 can you submit a new PR just to add "client_body_timeout" also . It seems needed but has been left out for gRPC at least. I don't know if its required for HTTP too. Checking.

@longwuyuan
Copy link
Contributor

@Anddd7 "client_body_timeout" seems to be available currently only as configMap option https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#client-body-timeout

And it seems it works in all three contexts ( http, server, location) https://nginx.org/en/docs/http/ngx_http_core_module.html#client_header_timeout

@Dunge
Copy link

Dunge commented Dec 2, 2024

See related issue #12177

@Anddd7
Copy link
Contributor Author

Anddd7 commented Dec 5, 2024

sure, i'll take a look. i saw #12212 , that would be a better way to manage those client-xxx annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/docs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support grpc_read_timeout and grpc_send_timeout in annotations
10 participants