send user-agent to fallback server

Summary: This way the fallback server know which traffic is coming from mononoke

Reviewed By: krallin

Differential Revision: D27946019

fbshipit-source-id: 8c13ae641ba340ba55322871ca30fb6accb3f007
This commit is contained in:
Mateusz Kwapich 2021-04-22 15:15:56 -07:00 committed by Facebook GitHub Bot
parent bc85aade21
commit d268af99cd
2 changed files with 18 additions and 4 deletions

View File

@ -27,7 +27,7 @@ use http::{
header::HeaderMap,
uri::{Authority, Parts, PathAndQuery, Scheme, Uri},
};
use hyper::{Body, Request};
use hyper::{header, Body, Request};
use permission_checker::{ArcPermissionChecker, MononokeIdentitySet};
use slog::Logger;
use tokio::runtime::Handle;
@ -48,6 +48,8 @@ pub type HttpsHyperClient = Client<HttpsConnector<HttpConnector>>;
// For some reason Source Control uses the read action to decide if a user can write to a repo...
const ACL_CHECK_ACTION: &str = "read";
// The user agent string presented to upstream
const CLIENT_USER_AGENT: &str = "mononoke-lfs-server/0.1.0 git/2.15.1";
struct LfsServerContextInner {
repositories: HashMap<String, (BlobRepo, ArcPermissionChecker, RepoConfig)>,
@ -294,7 +296,7 @@ impl RepositoryRequestContext {
pub async fn dispatch(
&self,
request: Request<Body>,
mut request: Request<Body>,
) -> Result<HttpClientResponse<impl Stream<Item = Result<Bytes, Error>>>, Error> {
#[allow(clippy::infallible_destructuring_match)]
let client = match self.client {
@ -303,6 +305,10 @@ impl RepositoryRequestContext {
HttpClient::Disabled => panic!("HttpClient is disabled in test"),
};
request.headers_mut().insert(
header::USER_AGENT,
header::HeaderValue::from_static(CLIENT_USER_AGENT),
);
let res = client.request(request);
// NOTE: We spawn the request on an executor because we'd like to read the response even if

View File

@ -14,8 +14,9 @@
# Start a LFS server (lfs_upstream is an upstream of lfs_proxy)
$ log_proxy="$TESTTMP/lfs_proxy.log"
$ log_upstream="$TESTTMP/lfs_upstream.log"
$ SCUBA="$TESTTMP/scuba.json"
$ lfs_upstream="$(lfs_server --log "$log_upstream")/lfs_upstream"
$ lfs_upstream="$(lfs_server --log "$log_upstream" --scuba-log-file "$SCUBA")/lfs_upstream"
$ lfs_proxy="$(lfs_server --always-wait-for-upstream --upstream "$lfs_upstream" --log "$log_proxy")/lfs_proxy"
# Upload data to upstream only
@ -64,7 +65,8 @@
IN > POST /lfs_upstream/objects/batch -
OUT < POST /lfs_upstream/objects/batch 200 OK
$ truncate -s 0 "$log_proxy" "$log_upstream"
$ wait_for_json_record_count "$SCUBA" 6
$ truncate -s 0 "$log_proxy" "$log_upstream" "$SCUBA"
# Uploading should make data available in both locations
$ yes B 2>/dev/null | head -c 2KiB | hg --config extensions.lfs= debuglfssend "$lfs_proxy"
@ -85,6 +87,12 @@
IN > PUT /lfs_upstream/upload/a1bcf2c963bec9588aaa30bd33ef07873792e3ec241453b0d21635d1c4bbae84/2048 -
OUT < PUT /lfs_upstream/upload/a1bcf2c963bec9588aaa30bd33ef07873792e3ec241453b0d21635d1c4bbae84/2048 200 OK
# Proper user agent should be sent to proxy.
$ wait_for_json_record_count "$SCUBA" 3
$ format_single_scuba_sample < "$SCUBA" | grep agent
"http_user_agent": "mononoke-lfs-server/0.1.0 git/2.15.1",
"http_user_agent": "mononoke-lfs-server/0.1.0 git/2.15.1",
"http_user_agent": "mononoke-lfs-server/0.1.0 git/2.15.1",
$ truncate -s 0 "$log_proxy" "$log_upstream"
$ hg --config extensions.lfs= debuglfsreceive a1bcf2c963bec9588aaa30bd33ef07873792e3ec241453b0d21635d1c4bbae84 2048 "$lfs_proxy" | sha256sum