Add success metrics to LocalStore get methods

Summary: Adding metrics to enable a full picture of EdenFS cache hits top to bottom. In this case, adding cache hits (success) to LocalStore. This will be paired with existing cache misses (failure). We also add errors (exceptions) to the reporting.

Reviewed By: clara-9

Differential Revision: D49396438

fbshipit-source-id: e28bd8e2785c48f9e9acce5761b01aaeb47da59c
This commit is contained in:
John Elliott 2023-09-19 13:58:56 -07:00 committed by Facebook GitHub Bot
parent 0418f9202b
commit 301d414011
2 changed files with 17 additions and 6 deletions

View File

@ -35,20 +35,22 @@ using std::string;
namespace facebook::eden {
namespace {
template <typename T, typename C, typename F>
template <typename T, typename F>
FOLLY_ALWAYS_INLINE std::shared_ptr<T> parse(
const ObjectId& id,
std::string_view context,
const EdenStatsPtr& stats,
C failureCounter,
StatsGroupBase::Counter LocalStoreStats::*successCounter,
StatsGroupBase::Counter LocalStoreStats::*errorCounter,
F&& fn) {
std::shared_ptr<T> def(nullptr);
if (auto ew = folly::try_and_catch(
[&def, fn = std::forward<F>(fn)]() { def = fn(); })) {
stats->increment(failureCounter);
stats->increment(errorCounter);
XLOGF(ERR, "Failed to get {} for {}: {}", context, id, ew.what());
}
stats->increment(successCounter);
return def;
}
} // namespace
@ -123,7 +125,8 @@ ImmediateFuture<TreePtr> LocalStore::getTree(const ObjectId& id) const {
id,
"Tree",
stats,
&LocalStoreStats::getTreeFailure,
&LocalStoreStats::getTreeSuccess,
&LocalStoreStats::getTreeError,
[&id, &data]() {
auto tree =
Tree::tryDeserialize(id, StringPiece{data.bytes()});
@ -151,7 +154,8 @@ ImmediateFuture<BlobPtr> LocalStore::getBlob(const ObjectId& id) const {
id,
"Blob",
stats,
&LocalStoreStats::getBlobFailure,
&LocalStoreStats::getBlobSuccess,
&LocalStoreStats::getBlobError,
[&data]() {
auto buf = data.extractIOBuf();
return deserializeGitBlob(&buf);
@ -175,7 +179,8 @@ ImmediateFuture<BlobMetadataPtr> LocalStore::getBlobMetadata(
id,
"BlobMetadata",
stats,
&LocalStoreStats::getBlobMetadataFailure,
&LocalStoreStats::getBlobMetadataSuccess,
&LocalStoreStats::getBlobMetadataError,
[&id, &data]() {
return SerializedBlobMetadata::parse(id, data);
});

View File

@ -314,9 +314,15 @@ struct LocalStoreStats : StatsGroup<LocalStoreStats> {
Duration getTree{"local_store.get_tree_us"};
Duration getBlob{"local_store.get_blob_us"};
Duration getBlobMetadata{"local_store.get_blob_metadata_us"};
Counter getTreeSuccess{"local_store.get_tree_success"};
Counter getBlobSuccess{"local_store.get_blob_success"};
Counter getBlobMetadataSuccess{"local_store.get_blob_metadata_success"};
Counter getTreeFailure{"local_store.get_tree_failure"};
Counter getBlobFailure{"local_store.get_blob_failure"};
Counter getBlobMetadataFailure{"local_store.get_blob_metadata_failure"};
Counter getTreeError{"local_store.get_tree_error"};
Counter getBlobError{"local_store.get_blob_error"};
Counter getBlobMetadataError{"local_store.get_blob_metadata_error"};
};
/**