nginxinc / ngx-rust

Rust binding for NGINX
Apache License 2.0
719 stars 59 forks source link

Examples on upstream/loadbalancer modules #30

Closed rikatz closed 11 months ago

rikatz commented 1 year ago

Hey folks, thanks for this crate.

I'm looking into testing ngx-rust with ingress-nginx, to replace parts of the code that deals with upstream/balancer (today it uses openresty).

First of all, bare in mind I'm almost null in Rust.

While trying to follow the examples and some module development blogs (in C), I couldn't move forward to implement a LB module for it.

I'm a bit lost on where are the limits of C/bindings and Rust code, and was wondering if it is possible to get an example on a loadbalancer module to check where am I doing the mistakes.

Thank you!

f5yacobucci commented 1 year ago

The coverage varies right now with how much of the total NGINX API this project supports. There are some known gaps and some unknown gaps. This is a good suggestion for an example though. I'll take a look.

ivanitskiy commented 1 year ago

This is an example of a community C module for LB: https://github.com/gnosek/nginx-upstream-fair, but no recent updates though.

rikatz commented 1 year ago

Yeap, I was also reading https://www.evanmiller.org/nginx-modules-guide.html and https://hodo.dev/posts/post-17-nginx-custom-upstream-module/ but not gonna lie I'm having some issues to port the idea to ngx-rust :)

f5yacobucci commented 1 year ago

Status: I'm significantly through an example based on this work: https://github.com/gabihodoroaga/nginx-upstream-module.

The algorithm may change some for example purposes, but the general structure will remain for cross-referencing. I'm hoping to complete and test it soon.

f5yacobucci commented 1 year ago

I opened a WIP PR early to help with your work @rikatz. Hopefully it offers some help before we finalize the structure or annotate it.

rikatz commented 1 year ago

Thanks @f5yacobucci it already helps a lot! I will take a look and play with it during the weekend :)