Skip to content

Commit 29f0bce

Browse files
Aaron Hometa-codesync[bot]
authored andcommitted
Add BTD graph cache Scuba logging subcommand
Summary: Adds a new `supertd log-graph-cache` CLI command that reads the metadata JSON file produced by BTDCachedGraphDownloaderScriptController.php and logs it as a BTD_GRAPH_CACHE_LOOKUP event to the supertd_events Scuba dataset. This enables tracking of BTD graph cache hit/miss metrics for analysis and dashboarding. Differential Revision: D90788251 fbshipit-source-id: 3d70d4ffb712c353964a0dd9e8bc61c5fd727264
1 parent 8957458 commit 29f0bce

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

supertd/bin/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum Args {
3535
#[cfg(fbcode_build)]
3636
GraphCompressor(graph_compressor::Args),
3737
#[cfg(fbcode_build)]
38+
LogGraphCache(td_util::btd_graph_cache::Args),
39+
#[cfg(fbcode_build)]
3840
MetadataFetcher(metadata_fetcher::Args),
3941
#[cfg(fbcode_build)]
4042
VerifiableMatcher(verifiable_matcher::Args),
@@ -94,6 +96,8 @@ pub async fn main(fb: FacebookInit) -> ExitCode {
9496
#[cfg(fbcode_build)]
9597
Args::GraphCompressor(args) => graph_compressor::main(args),
9698
#[cfg(fbcode_build)]
99+
Args::LogGraphCache(args) => td_util::btd_graph_cache::main(args),
100+
#[cfg(fbcode_build)]
97101
Args::MetadataFetcher(args) => metadata_fetcher::main(args).await,
98102
#[cfg(fbcode_build)]
99103
Args::VerifiableMatcher(args) => verifiable_matcher::main(args).await,

td_util/src/btd_graph_cache.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is dual-licensed under either the MIT license found in the
5+
* LICENSE-MIT file in the root directory of this source tree or the Apache
6+
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
7+
* of this source tree. You may select, at your option, one of the
8+
* above-listed licenses.
9+
*/
10+
11+
//! CLI command to log BTD graph cache lookup metadata to Scuba.
12+
//!
13+
//! Reads the JSON metadata file produced by BTDCachedGraphDownloaderScriptController.php
14+
//! and logs it as a BTD_GRAPH_CACHE_LOOKUP event.
15+
16+
use std::path::PathBuf;
17+
18+
use clap::Parser;
19+
20+
use crate::workflow_error::WorkflowError;
21+
22+
/// CLI arguments for the log-graph-cache subcommand.
23+
#[derive(Parser, Debug)]
24+
pub struct Args {
25+
/// Path to the metadata JSON file produced by BTDCachedGraphDownloaderScriptController
26+
#[arg(long)]
27+
pub metadata_file: PathBuf,
28+
}
29+
30+
/// Read graph cache lookup metadata from a file and log it to Scuba.
31+
pub fn main(args: Args) -> Result<(), WorkflowError> {
32+
let start = std::time::Instant::now();
33+
34+
let contents = std::fs::read_to_string(&args.metadata_file).map_err(|e| {
35+
anyhow::anyhow!(
36+
"Failed to read metadata file {:?}: {}",
37+
args.metadata_file,
38+
e
39+
)
40+
})?;
41+
42+
let metadata: serde_json::Value = serde_json::from_str(&contents)
43+
.map_err(|e| anyhow::anyhow!("Failed to parse metadata JSON: {}", e))?;
44+
45+
crate::scuba!(
46+
event: BTD_GRAPH_CACHE_LOOKUP,
47+
duration: start.elapsed(),
48+
data: metadata
49+
);
50+
51+
Ok(())
52+
}

td_util/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#![forbid(unsafe_code)]
12+
pub mod btd_graph_cache;
1213
pub mod cli;
1314
pub mod command;
1415
pub mod executor;

td_util/src/supertd_events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub enum Event {
4141
TARGETS_WITHOUT_BUDGET_ENTITY,
4242
SCUBA_TARGET_LOGGING_FAILURE,
4343
XGBOOST_SIZING_PACKING_FAILURE,
44+
BTD_GRAPH_CACHE_LOOKUP,
4445
}
4546

4647
#[derive(Debug)]

0 commit comments

Comments
 (0)