Skip to content

Commit

Permalink
Populate x-fb-product-log header in Mononoke Git
Browse files Browse the repository at this point in the history
Summary: `x-fb-product-log` header is a special header that is used by all of traffic infra for E2E traceability of HTTP requests. We often face traffic/network related issues in our Git, Mononoke and LFS setup so having this header would help with debugging such issues.

Reviewed By: mzr, lmvasquezg

Differential Revision: D64069628

fbshipit-source-id: 22fc41ed0b9931e281802a128375b414d9768c4f
  • Loading branch information
RajivTS authored and facebook-github-bot committed Oct 9, 2024
1 parent c669d66 commit 3337111
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
13 changes: 13 additions & 0 deletions eden/mononoke/gotham_ext/src/middleware/scuba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ use crate::middleware::PostResponseInfo;
use crate::response::HeadersMeta;
use crate::state_ext::StateExt;

const X_FB_PRODUCT_LOG_HEADER: &str = "x-fb-product-log";

/// Common HTTP-related Scuba columns that the middlware will set automatically.
/// Applications using the middleware are encouraged to follow a similar pattern
/// when adding application-specific columns to the `ScubaMiddlewareState`.
Expand Down Expand Up @@ -83,6 +85,8 @@ pub enum HttpScubaKey {
ConfigStoreVersion,
/// The config store last update time at the time of the request.
ConfigStoreLastUpdatedAt,
/// Request correlator ID that is recognized and standardized across all traffic infra for E2E tracebility.
XFBProductLog,
}

impl AsRef<str> for HttpScubaKey {
Expand Down Expand Up @@ -111,6 +115,7 @@ impl AsRef<str> for HttpScubaKey {
RequestBytesReceived => "request_bytes_received",
ConfigStoreVersion => "config_store_version",
ConfigStoreLastUpdatedAt => "config_store_last_updated_at",
XFBProductLog => "x_fb_product_log",
}
}
}
Expand Down Expand Up @@ -231,6 +236,14 @@ fn populate_scuba(scuba: &mut MononokeScubaSampleBuilder, state: &mut State) {
header::USER_AGENT,
|header| header.to_string(),
);

add_header(
scuba,
headers,
HttpScubaKey::XFBProductLog,
X_FB_PRODUCT_LOG_HEADER,
|header| header.to_string(),
);
}

if let Some(metadata_state) = MetadataState::try_borrow_from(state) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License found in the LICENSE file in the root
# directory of this source tree.

$ . "${TEST_FIXTURES}/library.sh"
$ REPOTYPE="blob_files"
$ setup_common_config $REPOTYPE
$ GIT_REPO_ORIGIN="${TESTTMP}/origin/repo-git"
$ GIT_REPO="${TESTTMP}/repo-git"
$ SCUBA="$TESTTMP/scuba.json"

# Setup git repository
$ mkdir -p "$GIT_REPO_ORIGIN"
$ cd "$GIT_REPO_ORIGIN"
$ git init -q
$ echo "this is file1" > file1
$ git add file1
$ git commit -qam "Add file1"
$ git tag -a -m "new tag" first_tag
$ echo "this is file2" > file2
$ git add file2
$ git commit -qam "Add file2"
$ master_commit=$(git rev-parse HEAD)

$ cd "$TESTTMP"
$ git clone --mirror "$GIT_REPO_ORIGIN" repo-git
Cloning into bare repository 'repo-git'...
done.

# Import it into Mononoke
$ cd "$TESTTMP"
$ quiet gitimport "$GIT_REPO" --derive-hg --generate-bookmarks full-repo

# Set Mononoke as the Source of Truth
$ set_mononoke_as_source_of_truth_for_git

# Start up the Mononoke Git Service
$ mononoke_git_service
# Clone the Git repo from Mononoke
$ git_client clone $MONONOKE_GIT_SERVICE_BASE_URL/$REPONAME.git
Cloning into 'repo'...
$ cd repo

# Add some new commits to the master branch
$ echo "Just another file" > another_file
$ git add .
$ git commit -qam "Another commit on master"

# Push all the changes made so far
$ git_client push origin master
To https://localhost:$LOCAL_PORT/repos/git/ro/repo.git
e8615d6..4981a25 master -> master

# Wait for the warm bookmark cache to catch up with the latest changes
$ wait_for_git_bookmark_move HEAD $master_commit

# Verify the push validation errors got recorded in scuba
$ jq -S .normal "$SCUBA" | grep product | wc -l
25

0 comments on commit 3337111

Please sign in to comment.