Changing the config to make the land service client work

Summary:
It (1) adds the repo in the Land Service, (2) includes Remote Land Service and remote land service with local fallback, (2) get the address from tier or host and calls the client in the unbundle processing

The Static analysis failed in the FBTHRIFTCOMPAT1 because i added a new field in the land_changesets method in the impl LandService (land_service_impl.rs). It does not break anything since we do not have the server in production. I mean, changing the id does not influence on previous versions of the server since there is no land service server in production.

Reviewed By: yancouto

Differential Revision: D39553570

fbshipit-source-id: bb1f09c2ab2c111734b9026109fc39e14c514516
This commit is contained in:
Gustavo Andrade Do Vale 2022-09-22 04:28:36 -07:00 committed by Facebook GitHub Bot
parent 83de9cf049
commit dfc568ff36
7 changed files with 123 additions and 58 deletions

View File

@ -1,4 +1,4 @@
// @generated SignedSource<<9a296dd7297d049023a0bac9d0c54f8a>> // @generated SignedSource<<a89c66cbf8ba16f5a0c2dc5851b8b078>>
// DO NOT EDIT THIS FILE MANUALLY! // DO NOT EDIT THIS FILE MANUALLY!
// This file is a mechanical copy of the version in the configerator repo. To // This file is a mechanical copy of the version in the configerator repo. To
// modify it, edit the copy in the configerator repo instead and copy it over by // modify it, edit the copy in the configerator repo instead and copy it over by
@ -445,6 +445,8 @@ union RawPushrebaseRemoteMode {
1: RawPushrebaseRemoteModeLocal local; 1: RawPushrebaseRemoteModeLocal local;
2: RawPushrebaseRemoteModeRemote remote_scs; 2: RawPushrebaseRemoteModeRemote remote_scs;
3: RawPushrebaseRemoteModeRemote remote_scs_local_fallback; 3: RawPushrebaseRemoteModeRemote remote_scs_local_fallback;
4: RawPushrebaseRemoteModeRemote remote_land_service;
5: RawPushrebaseRemoteModeRemote remote_land_service_local_fallback;
} }
struct RawPushrebaseParams { struct RawPushrebaseParams {

View File

@ -38,6 +38,9 @@ struct LandChangesetRequest {
/// What kind of bookmark can be pushed. /// What kind of bookmark can be pushed.
5: BookmarkKindRestrictions bookmark_restrictions = BookmarkKindRestrictions.ANY_KIND; 5: BookmarkKindRestrictions bookmark_restrictions = BookmarkKindRestrictions.ANY_KIND;
/// The name of the repository.
6: string repo_name;
} (rust.exhaustive) } (rust.exhaustive)
struct BonsaiHashPairs { struct BonsaiHashPairs {

View File

@ -257,6 +257,12 @@ impl Convert for RawPushrebaseRemoteMode {
Self::remote_scs_local_fallback(addr) => Ok( Self::remote_scs_local_fallback(addr) => Ok(
PushrebaseRemoteMode::RemoteScsWithLocalFallback(addr.convert()?), PushrebaseRemoteMode::RemoteScsWithLocalFallback(addr.convert()?),
), ),
Self::remote_land_service(addr) => {
Ok(PushrebaseRemoteMode::RemoteLandService(addr.convert()?))
}
Self::remote_land_service_local_fallback(addr) => Ok(
PushrebaseRemoteMode::RemoteLandServiceWithLocalFallback(addr.convert()?),
),
Self::UnknownField(e) => anyhow::bail!("Unknown field: {}", e), Self::UnknownField(e) => anyhow::bail!("Unknown field: {}", e),
} }
} }

View File

@ -654,16 +654,10 @@ pub enum PushrebaseRemoteMode {
RemoteScs(Address), RemoteScs(Address),
/// Call SCS and do pushrebase remotely, retrying errors locally /// Call SCS and do pushrebase remotely, retrying errors locally
RemoteScsWithLocalFallback(Address), RemoteScsWithLocalFallback(Address),
} /// Call LandService and do pushrebase remotely, forwarding errors
RemoteLandService(Address),
impl PushrebaseRemoteMode { /// Call LandService and do pushrebase remotely, retrying errors locally
/// SCS address used for pushrebase, if any RemoteLandServiceWithLocalFallback(Address),
pub fn scs_address(&self) -> Option<&Address> {
match self {
Self::RemoteScs(address) | Self::RemoteScsWithLocalFallback(address) => Some(address),
Self::Local => None,
}
}
} }
/// Pushrebase configuration options /// Pushrebase configuration options

View File

@ -17,6 +17,8 @@ use bookmarks_movement::BookmarkMovementError;
use bookmarks_types::BookmarkName; use bookmarks_types::BookmarkName;
use bytes::Bytes; use bytes::Bytes;
#[cfg(fbcode_build)] #[cfg(fbcode_build)]
pub use facebook::land_service::LandServicePushrebaseClient;
#[cfg(fbcode_build)]
pub use facebook::scs::override_certificate_paths; pub use facebook::scs::override_certificate_paths;
#[cfg(fbcode_build)] #[cfg(fbcode_build)]
pub use facebook::scs::ScsPushrebaseClient; pub use facebook::scs::ScsPushrebaseClient;
@ -28,7 +30,7 @@ use pushrebase::PushrebaseOutcome;
#[async_trait::async_trait] #[async_trait::async_trait]
/// This trait provides an abstraction for pushrebase, which can be used to allow /// This trait provides an abstraction for pushrebase, which can be used to allow
/// pushrebase to happen remotely. /// pushrebase to happen remotely.
pub trait PushrebaseClient { pub trait PushrebaseClient: Sync + Send {
/// Pushrebase the given changesets to the given bookmark. /// Pushrebase the given changesets to the given bookmark.
async fn pushrebase( async fn pushrebase(
&self, &self,

View File

@ -25,6 +25,7 @@ use bytes::Bytes;
use context::CoreContext; use context::CoreContext;
use hooks::HookManager; use hooks::HookManager;
use mercurial_mutation::HgMutationStoreRef; use mercurial_mutation::HgMutationStoreRef;
use metaconfig_types::Address;
use metaconfig_types::InfinitepushParams; use metaconfig_types::InfinitepushParams;
use metaconfig_types::PushParams; use metaconfig_types::PushParams;
use metaconfig_types::PushrebaseParams; use metaconfig_types::PushrebaseParams;
@ -32,6 +33,8 @@ use metaconfig_types::PushrebaseRemoteMode;
use mononoke_types::BonsaiChangeset; use mononoke_types::BonsaiChangeset;
use mononoke_types::ChangesetId; use mononoke_types::ChangesetId;
use pushrebase::PushrebaseError; use pushrebase::PushrebaseError;
#[cfg(fbcode_build)]
use pushrebase_client::LandServicePushrebaseClient;
use pushrebase_client::LocalPushrebaseClient; use pushrebase_client::LocalPushrebaseClient;
use pushrebase_client::PushrebaseClient; use pushrebase_client::PushrebaseClient;
#[cfg(fbcode_build)] #[cfg(fbcode_build)]
@ -497,6 +500,70 @@ async fn convert_bookmark_movement_err(
}) })
} }
pub fn maybe_client_from_address<'a>(
remote_mode: &'a PushrebaseRemoteMode,
ctx: &'a CoreContext,
repo: &'a impl Repo,
) -> Option<Box<dyn PushrebaseClient + 'a>> {
match remote_mode {
PushrebaseRemoteMode::RemoteScs(address)
| PushrebaseRemoteMode::RemoteScsWithLocalFallback(address) => {
address_from_scs(address, ctx, repo)
}
PushrebaseRemoteMode::RemoteLandService(address)
| PushrebaseRemoteMode::RemoteLandServiceWithLocalFallback(address) => {
address_from_land_service(address, ctx, repo)
}
PushrebaseRemoteMode::Local => None,
}
}
fn address_from_scs<'a>(
address: &'a Address,
ctx: &'a CoreContext,
repo: &'a impl Repo,
) -> Option<Box<dyn PushrebaseClient + 'a>> {
#[cfg(fbcode_build)]
{
match address {
metaconfig_types::Address::Tier(tier) => Some(Box::new(
ScsPushrebaseClient::from_tier(ctx, tier.clone(), repo).ok()?,
)),
metaconfig_types::Address::HostPort(host_port) => Some(Box::new(
ScsPushrebaseClient::from_host_port(ctx, host_port.clone(), repo).ok()?,
)),
}
}
#[cfg(not(fbcode_build))]
{
let _ = (address, ctx, repo);
unreachable!()
}
}
fn address_from_land_service<'a>(
address: &'a Address,
ctx: &'a CoreContext,
repo: &'a impl Repo,
) -> Option<Box<dyn PushrebaseClient + 'a>> {
#[cfg(fbcode_build)]
{
match address {
metaconfig_types::Address::Tier(tier) => Some(Box::new(
LandServicePushrebaseClient::from_tier(ctx, tier.clone(), repo).ok()?,
)),
metaconfig_types::Address::HostPort(host_port) => Some(Box::new(
LandServicePushrebaseClient::from_host_port(ctx, host_port.clone(), repo).ok()?,
)),
}
}
#[cfg(not(fbcode_build))]
{
let _ = (address, ctx, repo);
unreachable!()
}
}
async fn normal_pushrebase<'a>( async fn normal_pushrebase<'a>(
ctx: &'a CoreContext, ctx: &'a CoreContext,
repo: &'a impl Repo, repo: &'a impl Repo,
@ -516,18 +583,12 @@ async fn normal_pushrebase<'a>(
} else { } else {
&pushrebase_params.remote_mode &pushrebase_params.remote_mode
}; };
let maybe_fallback_scuba: Option<(MononokeScubaSampleBuilder, BookmarkMovementError)> = let maybe_fallback_scuba: Option<(MononokeScubaSampleBuilder, BookmarkMovementError)> = {
if let Some(address) = remote_mode.scs_address() { let maybe_client: Option<Box<dyn PushrebaseClient>> =
#[cfg(fbcode_build)] maybe_client_from_address(&pushrebase_params.remote_mode, ctx, repo);
{
let result = match address { if let Some(client) = maybe_client {
metaconfig_types::Address::Tier(tier) => { let result = client
ScsPushrebaseClient::from_tier(ctx, tier.clone(), repo)?
}
metaconfig_types::Address::HostPort(host_port) => {
ScsPushrebaseClient::from_host_port(ctx, host_port.clone(), repo)?
}
}
.pushrebase( .pushrebase(
bookmark, bookmark,
changesets.clone(), changesets.clone(),
@ -541,10 +602,12 @@ async fn normal_pushrebase<'a>(
return Ok((outcome.head, outcome.rebased_changesets)); return Ok((outcome.head, outcome.rebased_changesets));
} }
// No fallback, propagate error // No fallback, propagate error
(Err(err), metaconfig_types::PushrebaseRemoteMode::RemoteScs(..)) => { (
return Err( Err(err),
convert_bookmark_movement_err(err, hook_rejection_remapper).await? metaconfig_types::PushrebaseRemoteMode::RemoteScs(..)
); | metaconfig_types::PushrebaseRemoteMode::RemoteLandService(..),
) => {
return Err(convert_bookmark_movement_err(err, hook_rejection_remapper).await?);
} }
(Err(err), _) => { (Err(err), _) => {
slog::warn!( slog::warn!(
@ -564,14 +627,9 @@ async fn normal_pushrebase<'a>(
Some((scuba, err)) Some((scuba, err))
} }
} }
}
#[cfg(not(fbcode_build))]
{
let _ignore_only_this_unused_variable = address;
unreachable!()
}
} else { } else {
None None
}
}; };
let authz = AuthorizationContext::new(ctx); let authz = AuthorizationContext::new(ctx);
let result = LocalPushrebaseClient { let result = LocalPushrebaseClient {