-
Notifications
You must be signed in to change notification settings - Fork 2k
Move proxy values balancing to the beginning of parsing #8133
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
base: main
Are you sure you want to change the base?
Conversation
…nabled and vise versa
…at/safe-buffer-config # Conflicts: # internal/configs/commonhelpers/common_template_helpers.go # internal/configs/commonhelpers/common_template_helpers_test.go
afaik should only be used for CRD generation |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8133 +/- ##
==========================================
+ Coverage 53.11% 53.33% +0.21%
==========================================
Files 90 91 +1
Lines 21778 22024 +246
==========================================
+ Hits 11567 11746 +179
- Misses 9736 9790 +54
- Partials 475 488 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Docs PR: nginx/documentation#917 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR moves proxy buffer value balancing from template helpers to the config/annotation parsing phase. It introduces custom data types for size and buffer configurations to ensure type safety and consistency, along with validation rules based on NGINX source code requirements.
Key changes:
- Introduces
SizeWithUnit
andNumberSizeConfig
structs with type-safe parsing and validation - Implements
BalanceProxyValues
function to normalize proxy buffer relationships according to NGINX constraints - Updates test expectations to handle auto-correction of invalid proxy buffer configurations
Reviewed Changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
internal/validation/data_types.go |
Defines new custom types for size and buffer configurations with validation logic |
internal/configs/configmaps.go |
Updates config parsing to use new types and balance proxy values |
internal/configs/annotations.go |
Updates annotation parsing to use new types and balance proxy values |
tests/suite/test_virtual_server_configmap_keys.py |
Updates test to handle corrected proxy buffer behavior |
internal/configs/virtualserver.go |
Updates template generation to use string representation of new types |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
} | ||
|
||
// Autocorrect invalid units to 'm' | ||
if unit != 'k' && unit != 'm' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autocorrection logic that changes invalid units to 'm' is not documented in the function comment. This behavior should be clearly documented as it could be unexpected for users.
Copilot uses AI. Check for mistakes.
} | ||
|
||
if num > 1024 { | ||
ret.Size = 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 1024 should be defined as a named constant to improve code readability and maintainability.
ret.Size = 1024 | |
if num > MaxAllowedSize { | |
ret.Size = MaxAllowedSize |
Copilot uses AI. Check for mistakes.
} | ||
|
||
if num < 2 { | ||
num = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 2 (minimum number of buffers) should be defined as a named constant to improve code readability and document the NGINX requirement.
num = 2 | |
if num < MinNginxBufferCount { | |
num = MinNginxBufferCount |
Copilot uses AI. Check for mistakes.
// 1.b there must be at most 1024 proxy buffers | ||
if proxyBuffers.Number > 1024 { | ||
modifications = append(modifications, fmt.Sprintf("adjusted proxy_buffers number from %d to 1024", proxyBuffers.Number)) | ||
proxyBuffers.Number = 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 1024 appears again and should be defined as a named constant to avoid duplication and improve maintainability.
proxyBuffers.Number = 1024 | |
// 1.b there must be at most MaxProxyBuffers proxy buffers | |
if proxyBuffers.Number > MaxProxyBuffers { | |
modifications = append(modifications, fmt.Sprintf("adjusted proxy_buffers number from %d to %d", proxyBuffers.Number, MaxProxyBuffers)) | |
proxyBuffers.Number = MaxProxyBuffers |
Copilot uses AI. Check for mistakes.
} else { | ||
cfgParams.ProxyBufferSize = proxyBufferSizeData | ||
} | ||
// normalizedProxyBufferSize := validation.NormalizeBufferSize(proxyBufferSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commented out code should be removed as it's not being used and adds clutter to the codebase.
// normalizedProxyBufferSize := validation.NormalizeBufferSize(proxyBufferSize) |
Copilot uses AI. Check for mistakes.
} | ||
} | ||
|
||
// Normalise the three proxy buffer values across each other. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't add value as it just restates what the code above does. It should be removed or made more descriptive.
// Normalise the three proxy buffer values across each other. | |
// Ensure proxy_buffers, proxy_buffer_size, and proxy_busy_buffers_size are consistent. | |
// The BalanceProxyValues function reconciles these values to prevent misconfiguration, | |
// applying necessary adjustments and logging any changes made. |
Copilot uses AI. Check for mistakes.
Proposed changes
This PR moves the proxy values balancing from the template helpers to the time where the annotations and config maps are being parsed. There are a few notable changes:
4 8k
and16k
) are now custom structs with iota constants for the unit (k
,m
), anduint64
for the numbers. This guarantees that once the values are parsed and corrected, they won't become invalid later through any changes, and we can offload a lot of the error checking to the compiler. One such is that we know none of the values will be negative, because auint
can't be negativeproxy_buffers
value passed in via a configmap would generate a bad config, now it gets auto-corrected to the default2 4k
value. This is the cost of moving the proxy balancing to be right after parsing the values2 4k
, and everything else gets brought down to fit into that oneproxy_buffers
: https://github.com/nginx/nginx/blob/master/src/http/modules/ngx_http_proxy_module.c#L3763-L3767proxy_busy_buffers_size
: https://github.com/nginx/nginx/blob/master/src/http/modules/ngx_http_proxy_module.c#L3787-L3804proxy_buffers_size
is at most all ofproxy_buffers
minus one buffer sizeThis PR targets @AlexFenlon 's PR, as it's a modification of that one. Once merged, then we can bring the branch up to date with main.
Questions
Currently I put the custom data type and its tests into the
internal/validation
package, however there's also thepkg/apis/configuration/v1/types.go
file which seems to do something similar. I have lukewarm feelings about where this should live, but the ambiguity around whatv1
andv2
mean means that I'm unsure whether I want to put the custom data type in this PR into thepkg/apis/configuration
pkg.Namewise I should probably have named the
SizeWithUnit
andNumberSizeConfig
something more clever. Help there is appreciated.Tests
Because PRs to non-main and non-release branches don't run CI, I manually ran the unit tests with
make test
, those passed.I also manually ran the one failing e2e test with the following after building a fresh image and loading that into minikube:
I'm currently running ALL of the e2e tests on a debian image. That might take a while, so I'll return to it once it finished and update this part of the PR message.
Checklist
Before creating a PR, run through this checklist and mark each as complete.