mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-11-09 10:00:57 +03:00
FileQLogger Improvements
Summary: - Gracefully catch errors when QLog file cannot be created. - Remove an unused variable. Reviewed By: avasylev Differential Revision: D31671608 fbshipit-source-id: 058d852eb2dc1c513dc6c6eb22aee29b77a1b96d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
aa7cef3090
commit
dadf8652c2
@@ -37,8 +37,12 @@ void FileQLogger::setupStream() {
|
|||||||
auto extension = compress_ ? kCompressedQlogExtension : kQlogExtension;
|
auto extension = compress_ ? kCompressedQlogExtension : kQlogExtension;
|
||||||
std::string outputPath =
|
std::string outputPath =
|
||||||
folly::to<std::string>(path_, "/", (dcid.value()).hex(), extension);
|
folly::to<std::string>(path_, "/", (dcid.value()).hex(), extension);
|
||||||
std::ofstream file(outputPath);
|
try {
|
||||||
writer_ = std::make_unique<folly::AsyncFileWriter>(outputPath);
|
writer_ = std::make_unique<folly::AsyncFileWriter>(outputPath);
|
||||||
|
} catch (std::system_error err) {
|
||||||
|
LOG(ERROR) << "Error creating qlog file. " << err.what();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (compress_) {
|
if (compress_) {
|
||||||
compressionCodec_ = folly::io::getStreamCodec(folly::io::CodecType::GZIP);
|
compressionCodec_ = folly::io::getStreamCodec(folly::io::CodecType::GZIP);
|
||||||
compressionBuffer_ = folly::IOBuf::createCombined(kCompressionBufferSize);
|
compressionBuffer_ = folly::IOBuf::createCombined(kCompressionBufferSize);
|
||||||
@@ -74,6 +78,9 @@ void FileQLogger::setupStream() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileQLogger::writeToStream(folly::StringPiece message) {
|
void FileQLogger::writeToStream(folly::StringPiece message) {
|
||||||
|
if (!writer_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (compress_) {
|
if (compress_) {
|
||||||
bool inputConsumed = false;
|
bool inputConsumed = false;
|
||||||
while (!inputConsumed) {
|
while (!inputConsumed) {
|
||||||
@@ -96,6 +103,9 @@ void FileQLogger::writeToStream(folly::StringPiece message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileQLogger::finishStream() {
|
void FileQLogger::finishStream() {
|
||||||
|
if (!writer_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// finish copying the line that was stopped on
|
// finish copying the line that was stopped on
|
||||||
std::string unfinishedLine(
|
std::string unfinishedLine(
|
||||||
&eventLine_[pos_ + token_.size()],
|
&eventLine_[pos_ + token_.size()],
|
||||||
|
|||||||
@@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
#include <quic/logging/QLogger.h>
|
#include <quic/logging/QLogger.h>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <folly/FileUtil.h>
|
#include <folly/FileUtil.h>
|
||||||
#include <folly/Random.h>
|
#include <folly/Random.h>
|
||||||
#include <folly/json.h>
|
#include <folly/json.h>
|
||||||
|
#include <folly/portability/Filesystem.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <quic/common/test/TestUtils.h>
|
#include <quic/common/test/TestUtils.h>
|
||||||
#include <quic/congestion_control/Bbr.h>
|
#include <quic/congestion_control/Bbr.h>
|
||||||
@@ -1242,7 +1242,7 @@ TEST_F(QLoggerTest, PrettyStream) {
|
|||||||
ReadStreamFrame frame(streamId, offset, fin);
|
ReadStreamFrame frame(streamId, offset, fin);
|
||||||
|
|
||||||
regularQuicPacket.frames.emplace_back(std::move(frame));
|
regularQuicPacket.frames.emplace_back(std::move(frame));
|
||||||
auto dir = boost::filesystem::temp_directory_path().string();
|
auto dir = folly::fs::temp_directory_path().string();
|
||||||
|
|
||||||
auto* q = new FileQLogger(
|
auto* q = new FileQLogger(
|
||||||
VantagePoint::Server,
|
VantagePoint::Server,
|
||||||
@@ -1353,7 +1353,7 @@ TEST_F(QLoggerTest, NonPrettyStream) {
|
|||||||
ReadStreamFrame frame(streamId, offset, fin);
|
ReadStreamFrame frame(streamId, offset, fin);
|
||||||
|
|
||||||
regularQuicPacket.frames.emplace_back(std::move(frame));
|
regularQuicPacket.frames.emplace_back(std::move(frame));
|
||||||
auto dir = boost::filesystem::temp_directory_path().string();
|
auto dir = folly::fs::temp_directory_path().string();
|
||||||
|
|
||||||
auto* q = new FileQLogger(
|
auto* q = new FileQLogger(
|
||||||
VantagePoint::Server,
|
VantagePoint::Server,
|
||||||
@@ -1406,7 +1406,7 @@ TEST_F(QLoggerTest, CompressedStream) {
|
|||||||
ReadStreamFrame frame(streamId, offset, fin);
|
ReadStreamFrame frame(streamId, offset, fin);
|
||||||
|
|
||||||
regularQuicPacket.frames.emplace_back(std::move(frame));
|
regularQuicPacket.frames.emplace_back(std::move(frame));
|
||||||
auto dir = boost::filesystem::temp_directory_path().string();
|
auto dir = folly::fs::temp_directory_path().string();
|
||||||
|
|
||||||
auto* q = new FileQLogger(
|
auto* q = new FileQLogger(
|
||||||
VantagePoint::Server,
|
VantagePoint::Server,
|
||||||
@@ -1450,7 +1450,7 @@ TEST_F(QLoggerTest, CompressedNonStream) {
|
|||||||
ReadStreamFrame frame(streamId, offset, fin);
|
ReadStreamFrame frame(streamId, offset, fin);
|
||||||
|
|
||||||
regularQuicPacket.frames.emplace_back(std::move(frame));
|
regularQuicPacket.frames.emplace_back(std::move(frame));
|
||||||
auto dir = boost::filesystem::temp_directory_path().string();
|
auto dir = folly::fs::temp_directory_path().string();
|
||||||
|
|
||||||
FileQLogger q(
|
FileQLogger q(
|
||||||
VantagePoint::Server,
|
VantagePoint::Server,
|
||||||
@@ -1485,4 +1485,38 @@ TEST_F(QLoggerTest, CompressedNonStream) {
|
|||||||
EXPECT_EQ(expected["traces"], parsed["traces"]);
|
EXPECT_EQ(expected["traces"], parsed["traces"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(QLoggerTest, NoThrowOnStreamingWithNonExistentDirectory) {
|
||||||
|
auto headerIn =
|
||||||
|
ShortHeader(ProtectionType::KeyPhaseZero, getTestConnectionId(1), 1);
|
||||||
|
RegularQuicPacket regularQuicPacket(std::move(headerIn));
|
||||||
|
ReadStreamFrame frame(streamId, offset, fin);
|
||||||
|
|
||||||
|
regularQuicPacket.frames.emplace_back(std::move(frame));
|
||||||
|
auto dir = std::tmpnam(nullptr);
|
||||||
|
// Output directory does not exist.
|
||||||
|
ASSERT_FALSE(folly::fs::exists(dir));
|
||||||
|
|
||||||
|
auto* q = new FileQLogger(
|
||||||
|
VantagePoint::Server,
|
||||||
|
kHTTP3ProtocolType,
|
||||||
|
dir,
|
||||||
|
false /* prettyJson */,
|
||||||
|
true /* streaming */,
|
||||||
|
true /* compress */);
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(q->setDcid(ConnectionId::createRandom(8)));
|
||||||
|
q->addPacket(regularQuicPacket, 10);
|
||||||
|
EXPECT_EQ(
|
||||||
|
q->logs.size(),
|
||||||
|
0); // Packet is not written but also not being kept in memory
|
||||||
|
|
||||||
|
std::string outputPath =
|
||||||
|
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog.gz");
|
||||||
|
|
||||||
|
delete q;
|
||||||
|
|
||||||
|
// Output file was not created
|
||||||
|
EXPECT_FALSE(folly::fs::exists(outputPath));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace quic::test
|
} // namespace quic::test
|
||||||
|
|||||||
Reference in New Issue
Block a user