haproxytech / kubernetes-ingress

HAProxy Kubernetes Ingress Controller
https://www.haproxy.com/documentation/kubernetes/
Apache License 2.0
684 stars 195 forks source link

FR: http-request set-priority-class #624

Open ShadowJonathan opened 4 months ago

ShadowJonathan commented 4 months ago

We have a bunch of different traffic flowing through our application, all of them with different characteristics (latency tolerance, retry resilience, impact on user experience, criticality to proper application functioning, etc.), all of them are identifiable through a variety of different matchings on the request itself.

We have a kubernetes cluster, where currently an nginx ingress controller distributes requests across a variety of api servers. Upstream to that we have another nginx server (frontend) doing the matching, and sending traffic into the kubernetes cluster. We use kubernetes for this, as the volume of traffic ebbs and floods over the day, and auto-scaling on web worker usage and queue length has proven to be an effective method of handling with this.

We want to switch over to using the haproxy ingress controller to take advantage of request prioritisation, as this fits our usecase for managing the above mentioned different traffic patterns. For simplification, the plan was to have the upstream nginx ingress "mark" the requests as such before sending them along, so that a simple haproxy priority class matcher could assign it priority in the queue.

However, it appears that the haproxy ingress controller has not implemented the priority mechanism, as I couldn't find any mention of it in this repository, nor in documentation.

ivanmatmati commented 4 months ago

Hi @ShadowJonathan , Indeed we didn't implement this possibility. But there's always the possibility to inject your own configuration through config snippets as documented here. If you have already worked out the configuration you can post it there so we can discuss its integration. If you don't know how to do it, please ask the Haproxy Slack channel.

ShadowJonathan commented 4 months ago

I haven't yet spotted the config snippet option, when I do get it working i'll add the snippet here for anyone else to use, thank you for mentioning it! 💚

ShadowJonathan commented 3 months ago

Here's the config snippet:

    haproxy.org/backend-config-snippet: |
      acl traffic_ap_g req.hdr(x-traffic-class) -m str AP_G
      acl traffic_ap_p req.hdr(x-traffic-class) -m str AP_P
      acl traffic_ua_g req.hdr(x-traffic-class) -m str UA_G
      acl traffic_ua_p req.hdr(x-traffic-class) -m str UA_P
      acl traffic_anon req.hdr(x-traffic-class) -m str ANON
      acl traffic_admi req.hdr(x-traffic-class) -m str ADMI

      http-request set-priority-class int(2) if traffic_ap_g
      http-request set-priority-class int(1) if traffic_ap_p
      http-request set-priority-class int(0) if traffic_anon
      http-request set-priority-class int(-1) if traffic_ua_g
      http-request set-priority-class int(-2) if traffic_ua_p

      http-request set-priority-class int(-10) if traffic_admi

The header is set upstream at the aforementioned nginx proxy.

Here's an example of some graphs of how this stacks the traffic patterns;

image image

It fits our usecase perfectly. :)

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ShadowJonathan commented 2 months ago

Oh nice, another repo to add to the list: https://nostalebots.xyz

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ShadowJonathan commented 1 month ago

Thanks for reminding me to add it to the list.

stale[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ShadowJonathan commented 3 weeks ago

No.