Skip to content

feat: auto failover APIs with LK Cloud#1196

Merged
davidzhao merged 13 commits into
mainfrom
dz/api-failover
Jul 3, 2026
Merged

feat: auto failover APIs with LK Cloud#1196
davidzhao merged 13 commits into
mainfrom
dz/api-failover

Conversation

@davidzhao

Copy link
Copy Markdown
Member

retries in alternative datacenters on 5xx and transport failures

@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Changeset

The following package versions will be affected by this PR:

Package Bump
livekit patch
livekit-api minor
livekit-ffi patch

@xianshijing-lk xianshijing-lk requested review from 1egoman and jhugman July 2, 2026 01:40
};
}

#[tokio::test]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(non-blocking): If capturing log output from these tests is desired, the test_log macro can be added: #[test_log::test(tokio::test)].

Comment thread livekit-api/src/services/sip.rs
region_urls: &mut Option<Vec<String>>,
attempted: &[String],
) -> Option<Url> {
if region_urls.is_none() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using pattern matching to avoid unwrap:

let region_urls = match region_urls {
    Some(urls) => urls,
    None => region_urls.insert(failover::region_urls(original, forward).await),
};
failover::pick_next(region_urls, attempted)

Comment thread livekit-api/src/services/failover.rs Outdated
Comment thread .changeset/feat_auto_failover_apis_with_lk_cloud.md Outdated
Comment thread livekit-api/src/services/failover.rs Outdated
Comment thread livekit-api/src/services/twirp_client.rs Outdated
Comment thread livekit-api/src/services/connector.rs
Comment thread livekit-api/src/services/failover.rs Outdated

@jhugman jhugman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by review looking at idiomaticity. Feel free to ignore.

}
}

/// Enables or disables region failover (enabled by default). Failover only

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idiomatic: consider derive_builder here.

Comment thread livekit-api/src/services/failover.rs Outdated
const DISCOVERY_TIMEOUT: Duration = Duration::from_secs(2);

struct CacheEntry {
urls: Vec<String>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idiomatic: consider using a Url, or at least a newtype for Url.

Comment thread livekit-api/src/services/failover.rs
Comment on lines +471 to +493
let request = proto::CreateSipParticipantRequest {
sip_trunk_id: sip_trunk_id.to_owned(),
trunk: outbound_trunk_config,
sip_call_to: call_to.to_owned(),
sip_number: options.sip_number.to_owned().unwrap_or_default(),
room_name: room_name.to_owned(),
participant_identity: options.participant_identity.to_owned(),
participant_name: options.participant_name.to_owned().unwrap_or_default(),
participant_metadata: options.participant_metadata.to_owned().unwrap_or_default(),
participant_attributes: options.participant_attributes.to_owned().unwrap_or_default(),
dtmf: options.dtmf.to_owned().unwrap_or_default(),
wait_until_answered,
play_ringtone: options.play_dialtone.unwrap_or(false),
play_dialtone: options.play_dialtone.unwrap_or(false),
hide_phone_number: options.hide_phone_number.unwrap_or(false),
max_call_duration: Self::duration_to_proto(options.max_call_duration),
ringing_timeout: Self::duration_to_proto(ringing_timeout),
krisp_enabled: options.enable_krisp.unwrap_or(false),
headers: options.headers.unwrap_or_default(),
include_headers: options.include_headers.map(|h| h as i32).unwrap_or_default(),
media_encryption: options.media_encryption.map(|e| e as i32).unwrap_or_default(),
..Default::default()
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow

Comment thread livekit-api/src/services/twirp_client.rs Outdated
Comment thread livekit-api/src/services/failover.rs
@davidzhao davidzhao merged commit 8ead5c3 into main Jul 3, 2026
24 checks passed
@davidzhao davidzhao deleted the dz/api-failover branch July 3, 2026 11:42
@knope-bot knope-bot Bot mentioned this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants