Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/trusted-server-adapter-fastly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ async fn route_request(
false,
),
(m, path) if integration_registry.has_route(&m, path) => {
let fastly_req = compat::to_fastly_request(req);
let result = integration_registry
.handle_proxy(ProxyDispatchInput {
method: &m,
Expand All @@ -556,15 +555,14 @@ async fn route_request(
kv: kv_graph.as_ref(),
ec_context: &mut ec_context,
services: runtime_services,
req: fastly_req,
req,
})
.await
.unwrap_or_else(|| {
Err(Report::new(TrustedServerError::BadRequest {
message: format!("Unknown integration route: {path}"),
}))
})
.map(compat::from_fastly_response);
});
(result, true)
}

Expand Down
19 changes: 14 additions & 5 deletions crates/trusted-server-adapter-fastly/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl PlatformHttpClient for FastlyPlatformHttpClient {
.map(PlatformPendingRequest::new)
.collect();

let ready = match result {
let (ready, failed_backend_name) = match result {
Ok(fastly_resp) => {
let backend_name = fastly_resp
.get_backend_name()
Expand All @@ -340,15 +340,24 @@ impl PlatformHttpClient for FastlyPlatformHttpClient {
""
})
.to_string();
fastly_response_to_platform(fastly_resp, backend_name)
(fastly_response_to_platform(fastly_resp, backend_name), None)
}
Err(e) => {
Err(Report::new(PlatformError::HttpClient)
.attach(format!("fastly select error: {e}")))
let failed_name = e.backend_name().to_string();
(
Err(Report::new(PlatformError::HttpClient).attach(format!(
"fastly select error for backend '{failed_name}': {e}"
))),
Some(failed_name),
)
}
};

Ok(PlatformSelectResult { ready, remaining })
Ok(PlatformSelectResult {
ready,
remaining,
failed_backend_name,
})
}
}

Expand Down
24 changes: 17 additions & 7 deletions crates/trusted-server-core/src/auction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ The auction orchestration system allows you to:
┌─────────────────────────────────────────────────────────┐
│ AuctionProvider Trait │
│ - request_bids() │
│ - request_bids() async │
│ - parse_response() │
│ - provider_name() │
│ - timeout_ms() │
│ - is_enabled() │
Expand Down Expand Up @@ -479,6 +480,7 @@ timeout_ms = 500
use async_trait::async_trait;
use crate::auction::provider::AuctionProvider;
use crate::auction::types::{AuctionContext, AuctionRequest, AuctionResponse};
use crate::platform::{PlatformPendingRequest, PlatformResponse};

pub struct YourAuctionProvider {
config: YourConfig,
Expand All @@ -494,11 +496,19 @@ impl AuctionProvider for YourAuctionProvider {
&self,
request: &AuctionRequest,
_context: &AuctionContext<'_>,
) -> Result<AuctionResponse, Report<TrustedServerError>> {
) -> Result<PlatformPendingRequest, Report<TrustedServerError>> {
// 1. Transform AuctionRequest to your provider's format
// 2. Make HTTP request to your provider
// 3. Parse response
// 4. Return AuctionResponse with bids
// 2. Launch HTTP request through services.http_client().send_async(...)
// 3. Return PlatformPendingRequest for the orchestrator to await
todo!()
}

async fn parse_response(
&self,
response: PlatformResponse,
Comment thread
prk-Jr marked this conversation as resolved.
response_time_ms: u64,
) -> Result<AuctionResponse, Report<TrustedServerError>> {
// 4. Parse PlatformResponse into AuctionResponse
todo!()
}

Expand Down Expand Up @@ -534,7 +544,7 @@ let orchestrator = AuctionOrchestrator::new(config);
orchestrator.register_provider(Arc::new(PrebidAuctionProvider::try_new(prebid_config)?));
orchestrator.register_provider(Arc::new(ApsAuctionProvider::new(aps_config)));

let result = orchestrator.run_auction(&request, &context).await?;
let result = orchestrator.run_auction(&request, &context, &services).await?;

// Check results
assert_eq!(result.winning_bids.len(), 2);
Expand All @@ -543,7 +553,7 @@ assert!(result.total_time_ms < 2000);

## Performance Considerations

- **Parallel Execution**: Currently runs sequentially in Fastly Compute (no tokio runtime), but structured for easy parallelization
- **Parallel Execution**: Providers are launched concurrently via `select()` over `PendingRequest`s; responses are processed as they become ready within the auction deadline
- **Timeouts**: Each provider has independent timeout; global timeout enforced at flow level
- **Error Handling**: Provider failures don't fail entire auction; partial results returned

Expand Down
7 changes: 1 addition & 6 deletions crates/trusted-server-core/src/auction/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use error_stack::{Report, ResultExt};
use http::{header, Request, Response, StatusCode};
use serde_json::Value as JsonValue;

use crate::compat;

use crate::auction::formats::AdRequest;
use crate::consent::gate_eids_by_consent;
use crate::constants::COOKIE_TS_EIDS;
Expand Down Expand Up @@ -157,13 +155,10 @@ pub async fn handle_auction(
log::warn!("Auction EIDs stripped by TCF consent gating");
}

// Provider context only needs request metadata.
let fastly_req = compat::to_fastly_request_ref(&http_req);

// Create auction context
let context = AuctionContext {
settings,
request: &fastly_req,
request: &http_req,
timeout_ms: settings.auction.timeout_ms,
provider_responses: None,
services,
Expand Down
2 changes: 1 addition & 1 deletion crates/trusted-server-core/src/auction/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn convert_tsjs_to_auction_request(
.get(header::USER_AGENT)
.and_then(|value| value.to_str().ok())
.map(str::to_string),
ip: services.client_info.client_ip.map(|ip| ip.to_string()),
ip: services.client_info().client_ip.map(|ip| ip.to_string()),
geo,
});

Expand Down
Loading
Loading