Forum Discussion
F5 iRUule not working
This is API Application rather than web browser.
Source URL:
Destination URL:
tccog2 – azure openai instance name
irule Requirements:
1) destination host translation (prepend openai.azure.com with azure openai instance name) Immediate resource after the host name in the source url is extracted and prepended in the dest host name. As shown in the example above tccog2 is extracted from source url and prepended in the dest host name tccog2.openai.azure.com.
2) uri path translation (remove the azure openai instance name from uri path) Rest of the uri path (/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01) after the first resource from the host name is extracted and send us the destination uri path after the host name.
Following irule is not working to satisfy the above requirements:
when HTTP_REQUEST {
if { [HTTP::host] equals "mule-dev-openai-lb.ucsf.edu"} {
if { [HTTP::path] equals "/tccog2" } {
set newUri [string range [HTTP::uri] [string first / [HTTP::uri] 1] end]
set HTTP::uri ${newUri}
HTTP::redirect "https://tccog2.openai.azure.com[HTTP::uri]"
}
}
}
Hello msaud
Please remove the "set" in the "set HTTP::uri ${newUri}" command so it reads "HTTP::uri ${newUri}". I usually don't have the brackets but I doubt that makes a difference.
Scott
[edit] Ignore this, ScottE had the proper advice below 🙂
What's not working for you exactly - what behaviour are you seeing?
I did a quick test in the lab and I see the behaviour you'd expect (a 302 redirect) - obviously I've set the IP for mule-dev-openai-lb.ucsf.edu to the VIP in my lab here:
$ curl -kv 'http://mule-dev-openai-lb.ucsf.edu/tccog2/openai/deployments/tccognitivedeployment/completi ons?api-version=2022-12-01' * Trying 10.10.16.10:80... * Connected to mule-dev-openai-lb.ucsf.edu (10.10.16.10) port 80 (#0) > GET /tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 HTTP/1.1 > Host: mule-dev-openai-lb.ucsf.edu > User-Agent: curl/7.81.0 > Accept: */* > * Mark bundle as not supporting multiuse * HTTP 1.0, assume close after body < HTTP/1.0 302 Moved Temporarily < Location: https://tccog2.openai.azure.com/tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 < Server: BigIP * HTTP/1.0 connection set to keep alive! < Connection: Keep-Alive < Content-Length: 0 < * Connection #0 to host mule-dev-openai-lb.ucsf.edu left intact
Hello msaud
Please remove the "set" in the "set HTTP::uri ${newUri}" command so it reads "HTTP::uri ${newUri}". I usually don't have the brackets but I doubt that makes a difference.
Scott
Whoops, I missed that my test hadn't rewritten the URI - I can confirm as well, remove the 'set' and it works for me:
$ curl -kv 'http://mule-dev-openai-lb.ucsf.edu/tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01' * Trying 10.10.16.10:80... * Connected to mule-dev-openai-lb.ucsf.edu (10.10.16.10) port 80 (#0) > GET /tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 HTTP/1.1 > Host: mule-dev-openai-lb.ucsf.edu > User-Agent: curl/7.81.0 > Accept: */* > * Mark bundle as not supporting multiuse * HTTP 1.0, assume close after body < HTTP/1.0 302 Moved Temporarily < Location: https://tccog2.openai.azure.com/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 < Server: BigIP * HTTP/1.0 connection set to keep alive! < Connection: Keep-Alive < Content-Length: 0 < * Connection #0 to host mule-dev-openai-lb.ucsf.edu left intact
- msaudCirrus
Hi Aaron,
Look like iRule is working but we are getting below errors when trying to connect VIP-
"error":{"code":"404","message": "Resource not found"}}
Is there other things that we need to check?
10:48:45.455 06/19/2023 Worker-0 [MuleRuntime].uber.05: [stagegw-its-azure-openai-proxy].proxy.CPU_LITE @7e88db99 DEBUG
event:898e3e00-0ec9-11ee-a321-02a4b434dd63 REQUESTER POST /tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 HTTP/1.1 x-ssl-client-verify: NONE x-real-ip: 64.54.198.22 user-agent: PostmanRuntime/7.32.2 accept: */* cache-control: no-cache postman-token: bb49fc79-8441-4426-b4ea-c7b2de2835c7 accept-encoding: gzip, deflate, br authorization: Basic MDYxNzgyMjM5YjA3NDRlNDg3Y2U0ZWI0MTEzMmE0NTA6RDJhMTQ4MDQ1MEM0NDQzQTg0MzE4MTUyNGMwZUMxNjA= x-forwarded-for: 64.54.198.22, 10.225.46.165 x-forwarded-host: /10.225.46.190:60294 api-key: 03308343f0004146bc35159c0b624c3c x-anypnt-app-worker: A802BD108B50D526A4D3F6A5B49CDA97 x-correlation-id: 898e3e00-0ec9-11ee-a321-02a4b434dd63 Host: mule-stage-openai-lb.ucsf.edu:443 Connection: keep-alive Content-Type: application/json Content-Length: 53 { "prompt": "Once upon a time", "max_tokens": 5 }
10:48:45.564 06/19/2023 Worker-0 [stagegw-its-azure-openai-proxy].http.requester.http-request-config.01 SelectorRunner DEBUG
event:898e3e00-0ec9-11ee-a321-02a4b434dd63 REQUESTER HTTP/1.1 404 Resource Not Found Date: Mon, 19 Jun 2023 17:48:45 GMT Content-Type: application/json Content-Length: 56 Connection: keep-alive apim-request-id: a7f2e0b9-fd83-4d2e-a36b-71729cc18a4f Strict-Transport-Security: max-age=31536000; includeSubDomains; preload x-content-type-options: nosniff {"error":{"code":"404","message": "Resource not found"}}
Hello msaud
For source link: https://mule-dev-openai-lb.ucsf.edu/tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01
HTTP::path (path and filename in request) = /tccog2/openai/deployments/tccognitivedeployment/completions
so the following test
if { [HTTP::path] equals "/tccog2" } {
will not be true. Hopefully you can change that "equals" to "starts_with" and then you should be able to get to your setting of the newUri. If that is not behaving then you can log the current uri and the newUri to see ensure it is behaving as expected.
Scott
- msaudCirrus
Hi Scotte,
Thank you for your support on this. I did try below as well but still not working.
when HTTP_REQUEST {
if { [HTTP::host] equals "mule-dev-openai-lb.ucsf.edu"} {
if { [HTTP::path] starts_with "/tccog2" } {
set newUri [string range [HTTP::uri] [string first / [HTTP::uri] 1] end]
set HTTP::uri ${newUri}
HTTP::redirect "https://tccog2.openai.azure.com[HTTP::uri]"
}
}
}
[edit] Ignore this, ScottE had the proper advice below 🙂
What's not working for you exactly - what behaviour are you seeing?
I did a quick test in the lab and I see the behaviour you'd expect (a 302 redirect) - obviously I've set the IP for mule-dev-openai-lb.ucsf.edu to the VIP in my lab here:
$ curl -kv 'http://mule-dev-openai-lb.ucsf.edu/tccog2/openai/deployments/tccognitivedeployment/completi ons?api-version=2022-12-01' * Trying 10.10.16.10:80... * Connected to mule-dev-openai-lb.ucsf.edu (10.10.16.10) port 80 (#0) > GET /tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 HTTP/1.1 > Host: mule-dev-openai-lb.ucsf.edu > User-Agent: curl/7.81.0 > Accept: */* > * Mark bundle as not supporting multiuse * HTTP 1.0, assume close after body < HTTP/1.0 302 Moved Temporarily < Location: https://tccog2.openai.azure.com/tccog2/openai/deployments/tccognitivedeployment/completions?api-version=2022-12-01 < Server: BigIP * HTTP/1.0 connection set to keep alive! < Connection: Keep-Alive < Content-Length: 0 < * Connection #0 to host mule-dev-openai-lb.ucsf.edu left intact
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com