mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-04-18 17:24:03 +03:00
Add toLogFields for logging
Summary: This will be needed by logging components - eg QLog Reviewed By: hanidamlaj Differential Revision: D72476485 fbshipit-source-id: 3b7f3e81e87fc6cc2a252293208863d33bd5df50
This commit is contained in:
parent
d153b04ec4
commit
43af96e4f9
@ -13,6 +13,21 @@ constexpr size_t kDestroyIndexThreshold = 50;
|
||||
} // namespace
|
||||
|
||||
namespace quic {
|
||||
PriorityQueue::PriorityLogFields HTTPPriorityQueue::toLogFields(
|
||||
const PriorityQueue::Priority& pri) const {
|
||||
// This is defined by the QLOG schema
|
||||
auto httpPri = static_cast<const HTTPPriorityQueue::Priority&>(pri);
|
||||
if (httpPri->paused) {
|
||||
return {{"paused", "true"}};
|
||||
}
|
||||
PriorityLogFields result;
|
||||
result.reserve(3);
|
||||
result.emplace_back("urgency", std::to_string(httpPri->urgency));
|
||||
result.emplace_back("incremental", httpPri->incremental ? "true" : "false");
|
||||
result.emplace_back("order", std::to_string(httpPri->order));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
quic::Optional<HTTPPriorityQueue::FindResult> HTTPPriorityQueue::find(
|
||||
Identifier id) const {
|
||||
|
@ -133,6 +133,9 @@ class HTTPPriorityQueue : public quic::PriorityQueue {
|
||||
static_cast<const HTTPPriorityQueue::Priority&>(p2);
|
||||
}
|
||||
|
||||
[[nodiscard]] PriorityLogFields toLogFields(
|
||||
const PriorityQueue::Priority& pri) const override;
|
||||
|
||||
[[nodiscard]] bool contains(Identifier id) const override {
|
||||
return find(id) != quic::none;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <glog/logging.h>
|
||||
#include <quic/common/Optional.h>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace quic {
|
||||
/*
|
||||
@ -163,6 +164,11 @@ class PriorityQueue {
|
||||
// Returns true if the queue contains no elements, false otherwise
|
||||
[[nodiscard]] virtual bool empty() const = 0;
|
||||
|
||||
// Convert the Priority to JSON string.
|
||||
using PriorityLogFields = std::vector<std::pair<std::string, std::string>>;
|
||||
[[nodiscard]] virtual PriorityLogFields toLogFields(
|
||||
const Priority& pri) const = 0;
|
||||
|
||||
// Compare two Priority's for equality
|
||||
[[nodiscard]] virtual bool equalPriority(
|
||||
const Priority& p1,
|
||||
|
@ -306,4 +306,40 @@ TEST_F(HTTPPriorityQueueTest, IndexEverything) {
|
||||
queue_.erase(Identifier::fromStreamID(199));
|
||||
EXPECT_TRUE(queue_.empty());
|
||||
}
|
||||
|
||||
TEST_F(HTTPPriorityQueueTest, ToLogFields) {
|
||||
// Test for PAUSED priority
|
||||
HTTPPriorityQueue::Priority pausedPriority(
|
||||
HTTPPriorityQueue::Priority::PAUSED);
|
||||
auto lookup =
|
||||
[](const std::vector<std::pair<std::string, std::string>>& fields,
|
||||
const std::string& key) {
|
||||
auto it = std::find_if(
|
||||
fields.begin(),
|
||||
fields.end(),
|
||||
[&key](const std::pair<std::string, std::string>& field) {
|
||||
return field.first == key;
|
||||
});
|
||||
if (it != fields.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return std::string{};
|
||||
};
|
||||
|
||||
auto fieldsPaused = queue_.toLogFields(pausedPriority);
|
||||
EXPECT_EQ(lookup(fieldsPaused, "paused"), "true");
|
||||
|
||||
// Test for regular priority
|
||||
HTTPPriorityQueue::Priority regularPriority1(3, true, 0);
|
||||
auto fieldsRegular1 = queue_.toLogFields(regularPriority1);
|
||||
EXPECT_EQ(lookup(fieldsRegular1, "urgency"), "3");
|
||||
EXPECT_EQ(lookup(fieldsRegular1, "incremental"), "true");
|
||||
EXPECT_EQ(lookup(fieldsRegular1, "order"), "0");
|
||||
|
||||
HTTPPriorityQueue::Priority regularPriority2(4, false, 5);
|
||||
auto fieldsRegular2 = queue_.toLogFields(regularPriority2);
|
||||
EXPECT_EQ(lookup(fieldsRegular2, "urgency"), "4");
|
||||
EXPECT_EQ(lookup(fieldsRegular2, "incremental"), "false");
|
||||
EXPECT_EQ(lookup(fieldsRegular2, "order"), "5");
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user