Skip to content

Commit 3967fc3

Browse files
authored
[LoadTesting][Tooling] Support load testing via config (#460)
## Summary Support load testing via config
1 parent b6ea454 commit 3967fc3

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

protocol/shannon/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ type (
7373
GatewayPrivateKeyHex string `yaml:"gateway_private_key_hex"`
7474
OwnedAppsPrivateKeysHex []string `yaml:"owned_apps_private_keys_hex"`
7575
ServiceFallback []ServiceFallback `yaml:"service_fallback"`
76+
// Optional.
77+
// Puts the Gateway in LoadTesting mode if specified.
78+
// All relays will be sent to a fixed URL.
79+
// Allows measuring performance of PATH and full node(s) in isolation.
80+
LoadTestingConfig *LoadTestingConfig `yaml:"load_testing_config"`
7681
}
7782

7883
// TODO_TECHDEBT(@adshmh): Make configuration and implementation explicit:
@@ -88,6 +93,18 @@ type (
8893
// regardless of the health of the protocol endpoints.
8994
SendAllTraffic bool `yaml:"send_all_traffic"`
9095
}
96+
97+
// Load testing configuration.
98+
// Used to track Gateway's performance when using "perfect" endpoints.
99+
// If specified:
100+
// - Directs all relays to the specified backend service URL
101+
// - No protocol or fallback endpoint used.
102+
// - Assumes high throughput backend service (e.g. nginx with a fixed response)
103+
LoadTestingConfig struct {
104+
// The URL to use for sending relays.
105+
BackendServiceURL string `yaml:"backend_service_url"`
106+
// TODO_UPNEXT(@adshmh): Support using a fixed URL for a Shannon endpoint/RelayMiner during load testing.
107+
}
91108
)
92109

93110
func (gc GatewayConfig) Validate() error {

protocol/shannon/context.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 {

protocol/shannon/protocol.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ type Protocol struct {
7474
// Each service can have a SendAllTraffic flag to send all traffic to
7575
// fallback endpoints, regardless of the health of the protocol endpoints.
7676
serviceFallbackMap map[protocol.ServiceID]serviceFallback
77+
78+
// Optional.
79+
// Puts the Gateway in LoadTesting mode if specified.
80+
// All relays will be sent to a fixed URL.
81+
// Allows measuring performance of PATH and full node(s) in isolation.
82+
loadTestingConfig *LoadTestingConfig
7783
}
7884

7985
// serviceFallback holds the fallback information for a service,
@@ -123,6 +129,9 @@ func NewProtocol(
123129

124130
// serviceFallbacks contains the fallback information for each service.
125131
serviceFallbackMap: config.getServiceFallbackMap(),
132+
133+
// load testing config, if specified.
134+
loadTestingConfig: config.LoadTestingConfig,
126135
}
127136

128137
return protocolInstance, nil
@@ -334,6 +343,7 @@ func (p *Protocol) BuildHTTPRequestContextForEndpoint(
334343
relayRequestSigner: permittedSigner,
335344
httpClient: p.httpClient,
336345
fallbackEndpoints: fallbackEndpoints,
346+
loadTestingConfig: p.loadTestingConfig,
337347
}, protocolobservations.Observations{}, nil
338348
}
339349

0 commit comments

Comments
 (0)