@@ -100,6 +100,14 @@ type requestContext struct {
100100
101101 // fallbackEndpoints is used to retrieve a fallback endpoint by an endpoint address.
102102 fallbackEndpoints map [protocol.EndpointAddr ]endpoint
103+
104+ // Optional.
105+ // Puts the Gateway in LoadTesting mode if specified.
106+ // All relays will be sent to a fixed URL.
107+ // Allows measuring performance of PATH and full node(s) in isolation.
108+ // Applies to Single Relay ONLY
109+ // No parallel requests for a single relay in load testing mode.
110+ loadTestingConfig * LoadTestingConfig
103111}
104112
105113// HandleServiceRequest:
@@ -338,6 +346,13 @@ func (rc *requestContext) executeRelayRequestStrategy(payload protocol.Payload)
338346 rc .hydrateLogger ("executeRelayRequestStrategy" )
339347
340348 switch {
349+
350+ // ** Priority 0: Load testing mode **
351+ // Use the configured load testing backend server.
352+ case rc .loadTestingConfig != nil :
353+ rc .logger .Debug ().Msg ("LoadTesting Mode: Sending relay to the load test backend server" )
354+ return rc .sendProtocolRelay (payload )
355+
341356 // ** Priority 1: Check Endpoint type **
342357 // Direct fallback endpoint
343358 // - Bypasses protocol validation and Shannon network
@@ -524,14 +539,25 @@ func (rc *requestContext) sendProtocolRelay(payload protocol.Payload) (protocol.
524539 return defaultResponse , fmt .Errorf ("SHOULD NEVER HAPPEN: failed to marshal relay request: %w" , err )
525540 }
526541
542+ // TODO_UPNEXT(@adshmh): parse the LoadTesting server's URL in-advance.
543+ var targetServerURL string
544+ switch {
545+ // LoadTesting mode: use the fixed URL.
546+ case rc .loadTestingConfig != nil :
547+ targetServerURL = rc .loadTestingConfig .BackendServiceURL
548+ // Default: use the selected endoint's URL
549+ default :
550+ targetServerURL = selectedEndpoint .PublicURL ()
551+ }
552+
527553 // TODO_TECHDEBT(@adshmh): Add a new struct to track details about the HTTP call.
528554 // It should contain at-least:
529555 // - endpoint payload
530556 // - HTTP status code
531557 // Use the new struct to pass data around for logging/metrics/etc.
532558 //
533559 // Send the HTTP request to the protocol endpoint.
534- httpRelayResponseBz , httpStatusCode , err := rc .sendHTTPRequest (payload , selectedEndpoint . PublicURL () , relayRequestBz )
560+ httpRelayResponseBz , httpStatusCode , err := rc .sendHTTPRequest (payload , targetServerURL , relayRequestBz )
535561 if err != nil {
536562 return defaultResponse , err
537563 }
@@ -541,6 +567,17 @@ func (rc *requestContext) sendProtocolRelay(payload protocol.Payload) (protocol.
541567 return defaultResponse , fmt .Errorf ("%w %w: %d" , errSendHTTPRelay , errEndpointNon2XXHTTPStatusCode , httpStatusCode )
542568 }
543569
570+ // LoadTesting mode: return the backend server's response as-is.
571+ if rc .loadTestingConfig != nil {
572+ return protocol.Response {
573+ Bytes : httpRelayResponseBz ,
574+ HTTPStatusCode : httpStatusCode ,
575+ // Intentionally leaving the endpoint address empty.
576+ // Ensuring to sanctions/invalidation rules apply to LoadTesting backend server
577+ EndpointAddr : "" ,
578+ }, nil
579+ }
580+
544581 // Validate and process the response
545582 response , err := rc .validateAndProcessResponse (httpRelayResponseBz )
546583 if err != nil {
0 commit comments