Add stub handler for Suffix query

Summary: This Diff implements a stub handler for handling suffix queries on  EdenAPI. The stub handler only returns a static message. It will be implemented in a followup diff

Reviewed By: liubov-dmitrieva

Differential Revision: D56275449

fbshipit-source-id: 3234d7d1fe48744bde3e0c4c7eead75cbd482075
This commit is contained in:
Chris Dinh 2024-05-03 14:28:19 -07:00 committed by Facebook GitHub Bot
parent 36b74fcb5b
commit 16b877be6b
4 changed files with 85 additions and 0 deletions

View File

@ -73,6 +73,7 @@ mod land;
mod lookup;
mod pull;
mod repos;
mod suffix_query;
mod trees;
pub(crate) use handler::EdenApiHandler;
pub(crate) use handler::HandlerResult;
@ -86,6 +87,7 @@ const REPORTING_LOOP_WAIT: u64 = 5;
/// Used to identify the handler for logging and stats collection.
#[derive(Copy, Clone)]
pub enum EdenApiMethod {
SuffixQuery,
Blame,
Capabilities,
Files2,
@ -123,6 +125,7 @@ pub enum EdenApiMethod {
impl fmt::Display for EdenApiMethod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
Self::SuffixQuery => "suffix_query",
Self::Blame => "blame",
Self::Capabilities => "capabilities",
Self::Files2 => "files2",
@ -443,6 +446,7 @@ pub fn build_router(ctx: ServerContext) -> Router {
Handlers::setup::<commit_cloud::CommitCloudWorkspace>(route);
Handlers::setup::<commit_cloud::CommitCloudReferences>(route);
Handlers::setup::<commit_cloud::CommitCloudUpdateReferences>(route);
Handlers::setup::<suffix_query::SuffixQueryHandler>(route);
route.get("/:repo/health_check").to(health_handler);
route
.get("/:repo/capabilities")

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
use std::num::NonZeroU64;
use async_trait::async_trait;
use edenapi_types::SuffixQueryRequest;
use edenapi_types::SuffixQueryResponse;
use futures::stream;
use futures::StreamExt;
use types::RepoPathBuf;
use super::handler::EdenApiContext;
use super::EdenApiHandler;
use super::EdenApiMethod;
use super::HandlerResult;
pub struct SuffixQueryHandler;
#[async_trait]
impl EdenApiHandler for SuffixQueryHandler {
type Request = SuffixQueryRequest;
type Response = SuffixQueryResponse;
const HTTP_METHOD: hyper::Method = hyper::Method::POST;
const API_METHOD: EdenApiMethod = EdenApiMethod::SuffixQuery;
const ENDPOINT: &'static str = "/suffix_query";
fn sampling_rate(_request: &Self::Request) -> NonZeroU64 {
nonzero_ext::nonzero!(100u64)
}
async fn handler(
_ectx: EdenApiContext<Self::PathExtractor, Self::QueryStringExtractor>,
_request: Self::Request,
) -> HandlerResult<'async_trait, Self::Response> {
// Stub function
let result = vec![
Ok(SuffixQueryResponse {
file_path: RepoPathBuf::new(),
}),
Ok(SuffixQueryResponse {
file_path: RepoPathBuf::new(),
}),
];
Ok(stream::iter(result).boxed())
}
}

View File

@ -28,6 +28,7 @@ define_stats! {
failure_4xx: dynamic_timeseries("{}.failure_4xx", (method: String); Rate, Sum),
failure_5xx: dynamic_timeseries("{}.failure_5xx", (method: String); Rate, Sum),
response_bytes_sent: dynamic_histogram("{}.response_bytes_sent", (method: String); 1_500_000, 0, 150_000_000, Average, Sum, Count; P 50; P 75; P 95; P 99),
suffix_query_duration_ms: histogram(100, 0, 5000, Average, Sum, Count; P 50; P 75; P 95; P 99),
blame_duration_ms: histogram(100, 0, 5000, Average, Sum, Count; P 50; P 75; P 95; P 99),
capabilities_duration_ms: histogram(100, 0, 5000, Average, Sum, Count; P 50; P 75; P 95; P 99),
files2_duration_ms: histogram(100, 0, 5000, Average, Sum, Count; P 50; P 75; P 95; P 99),
@ -91,6 +92,7 @@ fn log_stats(state: &mut State, status: StatusCode) -> Option<()> {
}
CloudReferences => STATS::cloud_references_duration_ms.add_value(dur_ms),
CloudWorkspace => STATS::cloud_workspace_duration_ms.add_value(dur_ms),
SuffixQuery => STATS::suffix_query_duration_ms.add_value(dur_ms),
Blame => STATS::blame_duration_ms.add_value(dur_ms),
Capabilities => STATS::capabilities_duration_ms.add_value(dur_ms),
Files2 => STATS::files2_duration_ms.add_value(dur_ms),

View File

@ -0,0 +1,27 @@
# 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"
$ setup_common_config
$ setconfig experimental.edenapi-suffixquery=true
$ start_and_wait_for_mononoke_server
$ hgmn_init repo
$ cd repo
$ drawdag << EOS
> D # D/bar = zero\nuno\ntwo\n
> |
> C # C/bar = zero\none\ntwo\n (renamed from foo)
> |
> B # B/foo = one\ntwo\n
> |
> A # A/foo = one\n
> EOS
Test suffix query output:
$ hgedenapi debugapi -e suffix_query -i "{'Hg': 'e9ace545f925b6f62ae34087895fdc950d168e5f'}" -i "['.txt']"
[{"file_path": ""},
{"file_path": ""}]