Skip to content

Commit

Permalink
Implement Counter Wrapper Classes
Browse files Browse the repository at this point in the history
Summary:
This adds the `NullableStats` counter wrapper classes which wrap the `BaseStats` counter classes.

On counter initialization, NullableStats determines the name of the generated counter type and checks if this name is present in the MonitoringConfigLoader regex set. If the name is present, the class is just a passthrough to the BaseStats counter.

Otherwise, it implements a "dummy" counter class that won't instantiate the counter in Service Data and won't add any values when called. This is implemented slightly differently for each counter type due to the underlying counter class and how initialization occurs. But the end result is the same, if the counter name is not present in the monitoring config regex list, it will not be present locally in service data.

Reviewed By: jalopezsilva

Differential Revision: D50521531

fbshipit-source-id: 051089e7af2027a5260e918364fc9f07eaf9226d
  • Loading branch information
naclander authored and facebook-github-bot committed Jan 5, 2024
1 parent c806558 commit fde32fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions proxygen/lib/stats/BaseStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
DEFINE_bool(basestats_all_time_timeseries,
false,
"If true, BaseStats will use all-time aggregations");

/*static*/
bool proxygen::BaseStats::isAllTimeTimeseriesEnabled() {
return FLAGS_basestats_all_time_timeseries;
}
6 changes: 5 additions & 1 deletion proxygen/lib/stats/BaseStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ class BaseStats {
tlStat->add(value);
}
}
static void incrementOptionalCounter(std::optional<TLCounter>& tlCounter,

template <typename StatT>
static void incrementOptionalCounter(std::optional<StatT>& tlCounter,
facebook::fb303::CounterType value) {
if (tlCounter) {
tlCounter->incrementValue(value);
}
}

static bool isAllTimeTimeseriesEnabled();
};

} // namespace proxygen

0 comments on commit fde32fe

Please sign in to comment.