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

Use state file for updating N+ upstreams #2897

Merged
merged 4 commits into from
Dec 13, 2024
Merged

Conversation

sjberman
Copy link
Contributor

Problem: When splitting the data and control plane, we want to be able to maintain the ability to dynamically update upstreams without a reload if using NGINX Plus. With the current process, we write the upstreams into the nginx conf but don't reload, then call the API to actually do the update. Writing into the conf will trigger a reload from the agent once we split, however.

There were also two bugs:

  • if metrics were disabled, the nginx plus client was not initialized, preventing API calls from occuring and instead a reload occurred
  • stream upstreams were not updated with the API

Solution: Don't write the upstream servers into the nginx conf anymore when using NGINX Plus. Instead, utilize the state file option that the NGINX Plus API will populate with the upstream servers. This way we can just call the API and don't unintentionally reload by writing servers into the conf.

Also added support for updating stream upstreams, and fixed the initialization bug.

Testing: Verified that the state file is set and populated when using NGINX Plus. With OSS, servers are still written to the config.

Closes #2841

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Fix an issue where updating upstreams with the NGINX Plus API would not occur if metrics were disabled.

Support updating stream upstreams with the NGINX Plus API instead of reloading NGINX.

Use state files for NGINX Plus upstream servers instead of the NGINX config.

Problem: When splitting the data and control plane, we want to be able to maintain the ability to dynamically update upstreams without a reload if using NGINX Plus. With the current process, we write the upstreams into the nginx conf but don't reload, then call the API to actually do the update. Writing into the conf will trigger a reload from the agent once we split, however.

There were also two bugs:
- if metrics were disabled, the nginx plus client was not initialized, preventing API calls from occuring and instead a reload occurred
- stream upstreams were not updated with the API

Solution: Don't write the upstream servers into the nginx conf anymore when using NGINX Plus. Instead, utilize the `state` file option that the NGINX Plus API will populate with the upstream servers. This way we can just call the API and don't unintentionally reload by writing servers into the conf.

Also added support for updating stream upstreams, and fixed the initialization bug.
@sjberman sjberman requested a review from a team as a code owner December 12, 2024 16:53
@github-actions github-actions bot added the enhancement New feature or request label Dec 12, 2024
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 91.91176% with 11 lines in your changes missing coverage. Please review.

Project coverage is 89.74%. Comparing base (0cbb726) to head (ddc1ebb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/mode/static/manager.go 0.00% 5 Missing ⚠️
internal/mode/static/handler.go 95.52% 2 Missing and 1 partial ⚠️
internal/mode/static/nginx/runtime/manager.go 88.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2897      +/-   ##
==========================================
+ Coverage   89.71%   89.74%   +0.03%     
==========================================
  Files         109      109              
  Lines       11091    11150      +59     
  Branches       50       50              
==========================================
+ Hits         9950    10007      +57     
- Misses       1082     1083       +1     
- Partials       59       60       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sjberman sjberman added the bug Something isn't working label Dec 12, 2024
@bjee19
Copy link
Contributor

bjee19 commented Dec 12, 2024

I thought we want to have the Separate Data and Control Plane work merged into a feature branch, was I mistaken?

@sjberman
Copy link
Contributor Author

I thought we want to have the Separate Data and Control Plane work merged into a feature branch, was I mistaken?

This is technically independent of that work, it's just something that has to be done before the split is complete. But it's not a part of that work.

internal/mode/static/handler.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/runtime/manager.go Show resolved Hide resolved
@github-actions github-actions bot removed the bug Something isn't working label Dec 12, 2024
internal/mode/static/handler.go Show resolved Hide resolved
@sjberman sjberman enabled auto-merge (squash) December 12, 2024 22:41
@sjberman sjberman added the bug Something isn't working label Dec 12, 2024
@github-actions github-actions bot removed the bug Something isn't working label Dec 12, 2024
@sjberman sjberman added the bug Something isn't working label Dec 12, 2024
@sjberman sjberman merged commit 8e2e2d8 into main Dec 13, 2024
40 checks passed
@sjberman sjberman deleted the feat/nplus-state-file branch December 13, 2024 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request release-notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update Upstreams with State Files for Dynamic Upstream Configuration
3 participants