|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This software may be used and distributed according to the terms of the |
| 5 | + * GNU General Public License version 2. |
| 6 | + */ |
| 7 | + |
| 8 | +#include <gtest/gtest.h> |
| 9 | +#include <stdexcept> |
| 10 | +#include <system_error> |
| 11 | + |
| 12 | +#include "eden/common/utils/PathFuncs.h" |
| 13 | +#include "eden/fs/config/EdenConfig.h" |
| 14 | +#include "eden/fs/config/ReloadableConfig.h" |
| 15 | +#include "eden/fs/nfs/Nfsd3.h" |
| 16 | +#include "eden/fs/telemetry/ErrorLogger.h" |
| 17 | +#include "eden/fs/telemetry/test/CapturingScribeLogger.h" |
| 18 | + |
| 19 | +using namespace facebook::eden; |
| 20 | + |
| 21 | +namespace { |
| 22 | + |
| 23 | +std::shared_ptr<ReloadableConfig> makeTestConfig() { |
| 24 | + auto edenConfig = EdenConfig::createTestEdenConfig(); |
| 25 | + edenConfig->enableErrorLogging.setValue( |
| 26 | + true, ConfigSourceType::Default, true); |
| 27 | + return std::make_shared<ReloadableConfig>(edenConfig); |
| 28 | +} |
| 29 | + |
| 30 | +} // namespace |
| 31 | + |
| 32 | +TEST(NfsErrorLoggingTest, serverfaultIsLogged) { |
| 33 | + auto scribe = std::make_shared<CapturingScribeLogger>(); |
| 34 | + auto config = makeTestConfig(); |
| 35 | + ErrorLogger logger(scribe, SessionInfo{}, config); |
| 36 | + |
| 37 | + folly::exception_wrapper ex{std::runtime_error("backing store failure")}; |
| 38 | + detail::logNfsError( |
| 39 | + nfsstat3::NFS3ERR_SERVERFAULT, |
| 40 | + ex, |
| 41 | + logger, |
| 42 | + 42, |
| 43 | + canonicalPath("/mnt/repo")); |
| 44 | + |
| 45 | + ASSERT_EQ(scribe->messages().size(), 1); |
| 46 | + const auto& msg = scribe->messages()[0]; |
| 47 | + EXPECT_NE(msg.find("nfs"), std::string::npos) |
| 48 | + << "Should contain nfs component, got: " << msg; |
| 49 | + EXPECT_NE(msg.find("backing store failure"), std::string::npos) |
| 50 | + << "Should contain error message, got: " << msg; |
| 51 | + EXPECT_NE(msg.find("mnt"), std::string::npos) |
| 52 | + << "Should contain mount point, got: " << msg; |
| 53 | +} |
| 54 | + |
| 55 | +TEST(NfsErrorLoggingTest, nonServerfaultIsNotLogged) { |
| 56 | + auto scribe = std::make_shared<CapturingScribeLogger>(); |
| 57 | + auto config = makeTestConfig(); |
| 58 | + ErrorLogger logger(scribe, SessionInfo{}, config); |
| 59 | + |
| 60 | + folly::exception_wrapper ex{ |
| 61 | + std::system_error(ENOENT, std::generic_category(), "file not found")}; |
| 62 | + detail::logNfsError( |
| 63 | + nfsstat3::NFS3ERR_NOENT, ex, logger, 42, canonicalPath("/mnt/repo")); |
| 64 | + |
| 65 | + EXPECT_EQ(scribe->messages().size(), 0) |
| 66 | + << "Non-SERVERFAULT errors should not be logged"; |
| 67 | +} |
0 commit comments