Skip to content

Commit

Permalink
Make use of new field for metrics
Browse files Browse the repository at this point in the history
Summary: This diff is to make use of the new struct & field as added in D69181178 to allow removal of the prevous field

Reviewed By: andreacampi

Differential Revision: D69182275

fbshipit-source-id: 46c8bbbb3c46d191fc1111f2a0e9003b1f85152b
  • Loading branch information
Clara Rull authored and facebook-github-bot committed Feb 7, 2025
1 parent a93bfe8 commit d1b1fb1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
24 changes: 21 additions & 3 deletions configerator/structs/scm/mononoke/ratelimiting/ratelimits.thrift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @generated SignedSource<<41ef2b9c15ea5e3de6bd2710a291fad9>>
// @generated SignedSource<<2d2949fa8c5121c12983e72a5e6e1321>>
// DO NOT EDIT THIS FILE MANUALLY!
// 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
// running the following in your fbcode directory:
//
// configerator-thrift-updater scm/mononoke/ratelimiting/ratelimits.thrift
# @oncall scm_server_infra
include "thrift/annotation/cpp.thrift"
include "thrift/annotation/rust.thrift"

Expand Down Expand Up @@ -99,8 +100,8 @@ struct RateLimitBody {
1: RateLimitStatus status;
// The limit above which requests will be rate limited
2: double limit;
// Within ratelimits use window within FciMetric struct instead
3: optional i64 window;
// Deprecated
// 3: optional i64 window;
}

@rust.Exhaustive
Expand All @@ -127,6 +128,23 @@ struct LoadShedLimit {
3: optional Target target;
// The limit above which requests will be rate limited
4: i64 limit;
// The metric used to load shed
5: LoadSheddingMetric load_shedding_metric;
}

// The metric used for load shedding.
union LoadSheddingMetric {
// A counter exposed by the binary itself, i.e. starting with "mononoke.".
1: string local_fb303_counter;
// A counter not exposed by the binary.
2: ExternalOdsCounter external_ods_counter;
}
@rust.Exhaustive
struct ExternalOdsCounter {
// The entity of the ODS counter.
1: string entity;
// The key of the ODS counter.
2: string key;
}

@rust.Exhaustive
Expand Down
12 changes: 11 additions & 1 deletion eden/mononoke/rate_limiting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod oss;
pub use facebook::create_rate_limiter;
#[cfg(not(fbcode_build))]
pub use oss::create_rate_limiter;
pub use rate_limiting_config::LoadSheddingMetric;
pub use rate_limiting_config::RateLimitStatus;

pub mod config;
Expand Down Expand Up @@ -186,9 +187,18 @@ impl LoadShedLimit {
return LoadShedResult::Pass;
}

// Fetch the counter
let value = match self.raw_config.load_shedding_metric.clone() {
LoadSheddingMetric::local_fb303_counter(metric) => {
let metric = metric.to_string();
STATS::load_shed_counter.get_value(fb, (metric.clone(),))
}
_ => None,
};

let metric = self.raw_config.metric.to_string();

match STATS::load_shed_counter.get_value(fb, (metric.clone(),)) {
match value {
Some(value) if value > self.raw_config.limit => {
log_or_enforce_status(self.raw_config.clone(), metric, value, scuba)
}
Expand Down

0 comments on commit d1b1fb1

Please sign in to comment.