Skip to content

Commit

Permalink
Merge branch 'main' of ../private
Browse files Browse the repository at this point in the history
  • Loading branch information
lunar-devops committed Jan 21, 2025
2 parents e0b8987 + 874c214 commit 34036fb
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Feature: Lunar Proxy - Discovered Endpoint Metrics
And 1 requests to GET http:// mox :8888 /status are made through Lunar Proxy with headers {"lunar-interceptor": "lunar-aiohttp-interceptor/2.1.3", "x-lunar-consumer-tag": "tagB"}
And mox is set to return status code 200 on POST /status
And 5 requests to POST http:// mox :8888 /status are made through Lunar Proxy with headers {"x-lunar-interceptor": "lunar-aiohttp-interceptor:2.1.2", "x-lunar-consumer-tag": "tagA"}
Then Discovered endpoint metrics for GET mox /status has 4 requests ({"201": 3, "402": 1})
And Discovered endpoint metrics for POST mox /status has 5 requests ({"200": 5})
Then Discovered endpoint metrics for GET mox:8888 /status has 4 requests ({"201": 3, "402": 1})
And Discovered endpoint metrics for POST mox:8888 /status has 5 requests ({"200": 5})
And Discovered interceptor metrics has 3 interceptors ({"lunar-aiohttp-interceptor": "2.1.2", "unknown": "unknown", "lunar-direct": "0"})
And Discovered consumer metrics for GET mox /status has consumer tagA with requests ({"201": 3})
And Discovered consumer metrics for POST mox /status has consumer tagA with requests ({"200": 5})
And Discovered consumer metrics for GET mox /status has consumer tagB with requests ({"402": 1})
And Discovered consumer metrics for GET mox:8888 /status has consumer tagA with requests ({"201": 3})
And Discovered consumer metrics for POST mox:8888 /status has consumer tagA with requests ({"200": 5})
And Discovered consumer metrics for GET mox:8888 /status has consumer tagB with requests ({"402": 1})

4 changes: 2 additions & 2 deletions proxy/integration-tests/features/policies_reload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Policies Reload
Given Lunar Proxy is up
And API Provider is up
When policies.yaml file is updated
And policies.yaml includes a fixed_response remedy for GET mox /json requests with status code 202
And policies.yaml includes a fixed_response remedy for GET mox:8888 /json requests with status code 202
And policies.yaml file is saved
And apply_policies command is run without waiting for Fluent to reload
And A request to http:// mox :8888 /json is made through Lunar Proxy with header 'Early-Response: true'
Expand All @@ -17,7 +17,7 @@ Feature: Policies Reload
And Lunar Proxy is up
And mox is set to respond to GET /json with status 201
When policies.yaml file is updated
And policies.yaml includes a fixed_response remedy for GET mox /json requests with invalid config
And policies.yaml includes a fixed_response remedy for GET mox:8888 /json requests with invalid config
And policies.yaml file is saved
And A local POST request (id apply_policies) is made to port 8081 at path /apply_policies
And A request to http:// mox :8888 /json is made through Lunar Proxy with header 'Early-Response: true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Feature: Lunar Proxy fixed early response remedy
Given API Provider is up
And Lunar Proxy is up
When policies.yaml file is updated
And policies.yaml includes a fixed_response remedy for GET mox /uuid/* requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox /uuid/{someID} requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox /test/* requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/* requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/{someID} requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox:8888 /test/* requests with status code <status>
And policies.yaml file is saved
And apply_policies command is run without waiting for Fluent to reload
When A request to <scheme>:// <host> :<port> <path> is made through Lunar Proxy with header 'Early-Response: true'
Expand All @@ -23,8 +23,8 @@ Feature: Lunar Proxy fixed early response remedy
And Lunar Proxy is up
When policies.yaml file is updated
And policies.yaml includes an accounts section with 2 accounts
And policies.yaml includes a fixed_response remedy for GET mox /uuid requests with status code 418
And policies.yaml includes a disabled account_orchestration remedy for GET mox /uuid requests
And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid requests with status code 418
And policies.yaml includes a disabled account_orchestration remedy for GET mox:8888 /uuid requests
And policies.yaml file is saved
And apply_policies command is run without waiting for Fluent to reload
When A request to http:// mox :8888 /uuid is made through Lunar Proxy with header 'Early-Response: true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Lunar Proxy response-based throttling remedy
And Lunar Proxy is up
And 2 remaining requests until rate limit threshold is reached
When policies.yaml file is updated
And policies.yaml includes a response_based_throttling remedy for GET mox /throttle requests for 429 status using retry-after header as relative_seconds
And policies.yaml includes a response_based_throttling remedy for GET mox:8888 /throttle requests for 429 status using retry-after header as relative_seconds
And policies.yaml file is saved
And apply_policies command is run without waiting for Fluent to reload
And 4 requests to rate limited endpoint http:// mox :8888 /throttle are made via Lunar Proxy
Expand Down
4 changes: 2 additions & 2 deletions proxy/integration-tests/features/remedy_stats.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Lunar Proxy - Remedy Stats
Given API Provider is up

When policies.yaml file is updated
And policies.yaml includes a fixed_response remedy for GET mox /status/* requests with status code 400
And policies.yaml includes a fixed_response remedy for GET mox:8888 /status/* requests with status code 400
And policies.yaml file is saved
And apply_policies command is run

Expand All @@ -29,7 +29,7 @@ Feature: Lunar Proxy - Remedy Stats
And item remedy_stat affected_count is 2

And item remedy_stat has field affected_stats_by_endpoint (marked endpoint_stats)
And item endpoint_stats is an array with item that matches {"method": "GET", "url": "mox/status"} (marked as endpoint_stat)
And item endpoint_stats is an array with item that matches {"method": "GET", "url": "mox:8888/status"} (marked as endpoint_stat)
And item endpoint_stat count is 2
And item endpoint_stat count_by_status_code json is {"400": 2}

Expand Down
4 changes: 2 additions & 2 deletions proxy/integration-tests/features/steps/proxy_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def step_impl(


@when(
"A request to {scheme}:// {host} :{port} {path:Path} is made {is_proxified:IsProxified} with previously returned sequence id"
"A request to {scheme}:// {host} :{port:Int} {path:Path} is made {is_proxified:IsProxified} with previously returned sequence id"
)
@async_run_until_complete
async def step_impl(
Expand Down Expand Up @@ -263,7 +263,7 @@ async def step_impl(


@when(
"A request to {scheme}:// {host} :{port} {path:Path} is made {is_proxified:IsProxified}"
"A request to {scheme}:// {host} :{port:Int} {path:Path} is made {is_proxified:IsProxified}"
)
@async_run_until_complete
async def step_impl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Feature: Validate Lunar Proxy add the x-lunar-generated on modified responses

Scenario Outline: Lunar returns a fixed early response when policy is matched and x-lunar-generated header is true
When policies.yaml file is updated
And policies.yaml includes a fixed_response remedy for GET mox /uuid/* requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox /uuid/{someID} requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox /test/* requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/* requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/{someID} requests with status code <status>
And policies.yaml includes a fixed_response remedy for GET mox:8888 /test/* requests with status code <status>
And policies.yaml file is saved
And apply_policies command is run without waiting for Fluent to reload
When A request to <scheme>:// <host> :<port> <path> is made through Lunar Proxy with header 'Early-Response: true'
Expand Down
19 changes: 9 additions & 10 deletions proxy/integration-tests/utils/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional, Tuple

from toolkit_testing.integration_tests import routing
from toolkit_testing.integration_tests.routing import (
Routing,
RoutingType,
Expand Down Expand Up @@ -56,7 +57,7 @@ async def make_request(
with_routing_type: bool = True,
) -> ClientResponse:
headers = {header_key: header_value} if header_key and header_value else None

host = host.replace(":80", "").replace(":443", "")
requested_host, requested_port = (host, port) if is_proxified else _mock_host(host)
routing_type = (
(
Expand All @@ -70,11 +71,12 @@ async def make_request(

routing = Routing(
requested_host=requested_host,
requested_port=requested_port,
requested_scheme=extract_scheme(scheme),
type=routing_type,
use_x_lunar_host=use_x_lunar_host and header_based_redirection,
)
if requested_port not in [80, 443]:
routing.requested_port = requested_port

if is_proxified:
client = _proxy_clients[proxy_id]
Expand Down Expand Up @@ -115,12 +117,9 @@ async def request(
proxy_id: str = "0",
) -> ClientResponse:
client = _proxy_clients[proxy_id]
response = await client.make_request(
routing=Routing(
requested_host=host,
requested_scheme=extract_scheme(scheme),
requested_port=port,
),
path=path,
)
routing = Routing(requested_host=host, requested_scheme=extract_scheme(scheme))
if port not in [80, 443]:
routing.requested_port = port

response = await client.make_request(routing=routing, path=path)
return response
9 changes: 6 additions & 3 deletions proxy/rootfs/etc/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ frontend http-in

# txn.url is set to the full URL excluding scheme, port and query params (e.g. domain.com/path/to/resource)
http-request set-var(txn.path) path
http-request set-var(txn.url) var(txn.host),host_only,concat(,txn.path)
http-request set-var(txn.url) var(txn.host),concat(,txn.path)

# txn.lunar_interceptor
http-request set-var(txn.interceptor) str("lunar-direct/0") unless { req.hdr(x-lunar-interceptor) -m found }
Expand Down Expand Up @@ -136,8 +136,11 @@ frontend http-in
http-request set-var(txn.error_in_body) str("Could not resolve port") if { var(txn.dst_port) -m int 0 }
http-request deny status 503 content-type text/plain lf-string "Could not resolve port" hdr x-lunar-error 5 if { var(txn.dst_port) -m int 0 }

http-request do-resolve(req.host_ip,resolv-conf,ipv4) var(txn.host),host_only

# Check if the host is an IPv4 address and resolve it if it is not
acl is_host_ipv4 var(txn.host),host_only -i -m reg (\d+)\.(\d+)\.(\d+)\.(\d+)
http-request do-resolve(req.host_ip,resolv-conf,ipv4) var(txn.host),host_only if !is_host_ipv4
http-request set-var(req.host_ip) var(txn.host),host_only if is_host_ipv4

http-request set-var(txn.x_lunar_error) str(5) unless { var(req.host_ip) -m found }
http-request set-var(txn.error_in_body) str("Could not resolve host") unless { var(req.host_ip) -m found }
http-request deny status 503 content-type text/plain lf-string "Could not resolve host" hdr x-lunar-error 5 unless { var(req.host_ip) -m found }
Expand Down

0 comments on commit 34036fb

Please sign in to comment.