Skip to content

Commit

Permalink
fix: clang, pr comments and rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioDonda committed Dec 12, 2024
1 parent 4439615 commit c21cc9a
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 38 deletions.
2 changes: 1 addition & 1 deletion etc/config/wazuh-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ agent:
retry_interval: 30s
events:
batch_interval: 10s
batch_size: 10000000
batch_size: 1MB
inventory:
enabled: true
interval: 1h
Expand Down
2 changes: 1 addition & 1 deletion src/agent/communicator/include/communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace communicator

if (m_batchSize < 1'000 || m_batchSize > 100'000'000)
{
LogWarn("batch_size must be between 1000B and 100MB. Using default value.");
LogWarn("batch_size must be between 1KB and 100MB. Using default value.");
m_batchSize = config::agent::DEFAULT_BATCH_SIZE;
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/agent/communicator/src/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,8 @@ namespace communicator

const auto reqParams = http_client::HttpRequestParams(
boost::beast::http::verb::get, m_serverUrl, "/api/v1/commands", m_getHeaderInfo ? m_getHeaderInfo() : "");
co_await m_httpClient->Co_PerformHttpRequest(m_token,
reqParams,
{},
onAuthenticationFailed,
m_retryInterval,
m_batchSize,
onSuccess,
loopCondition);
co_await m_httpClient->Co_PerformHttpRequest(
m_token, reqParams, {}, onAuthenticationFailed, m_retryInterval, m_batchSize, onSuccess, loopCondition);
}

boost::asio::awaitable<void> Communicator::WaitForTokenExpirationAndAuthenticate()
Expand Down
2 changes: 1 addition & 1 deletion src/agent/communicator/src/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace http_client

if (messagesCount)
{
LogInfo("Messages count: {}", messagesCount);
LogTrace("Messages count: {}", messagesCount);
reqParams.Body = std::get<1>(messages);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/agent/communicator/tests/communicator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// NOLINTBEGIN(cppcoreguidelines-avoid-capturing-lambda-coroutines)

using namespace testing;
using GetMessagesFuncType = std::function<boost::asio::awaitable<intStringTuple>(const int)>;
using GetMessagesFuncType = std::function<boost::asio::awaitable<intStringTuple>(const size_t)>;

namespace
{
Expand Down Expand Up @@ -52,7 +52,7 @@ TEST(CommunicatorTest, StatefulMessageProcessingTask_Success)
{
auto mockHttpClient = std::make_unique<MockHttpClient>();

auto getMessages = [](const int) -> boost::asio::awaitable<intStringTuple>
auto getMessages = [](const size_t) -> boost::asio::awaitable<intStringTuple>
{
co_return intStringTuple {1, std::string("message-content")};
};
Expand Down Expand Up @@ -137,7 +137,7 @@ TEST(CommunicatorTest, WaitForTokenExpirationAndAuthenticate_FailedAuthenticatio
{
co_await communicatorPtr->WaitForTokenExpirationAndAuthenticate();
co_await communicatorPtr->StatelessMessageProcessingTask(
[](const int) -> boost::asio::awaitable<intStringTuple>
[](const size_t) -> boost::asio::awaitable<intStringTuple>
{ co_return intStringTuple(1, std::string {"message"}); },
[]([[maybe_unused]] const int, const std::string&) {});
}(),
Expand Down Expand Up @@ -196,7 +196,7 @@ TEST(CommunicatorTest, StatelessMessageProcessingTask_CallsWithValidToken)
{
co_await communicatorPtr->WaitForTokenExpirationAndAuthenticate();
co_await communicatorPtr->StatelessMessageProcessingTask(
[](const int) -> boost::asio::awaitable<intStringTuple>
[](const size_t) -> boost::asio::awaitable<intStringTuple>
{ co_return intStringTuple(1, std::string {"message"}); },
[]([[maybe_unused]] const int, const std::string&) {});
}(),
Expand Down
10 changes: 5 additions & 5 deletions src/agent/communicator/tests/http_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ TEST_P(HttpClientTest, Co_PerformHttpRequest_Success)
SetupMockSocketReadExpectations(GetParam());

auto getMessagesCalled = false;
auto getMessages = [&getMessagesCalled](const int) -> boost::asio::awaitable<std::tuple<int, std::string>>
auto getMessages = [&getMessagesCalled](const size_t) -> boost::asio::awaitable<std::tuple<int, std::string>>
{
getMessagesCalled = true;
co_return std::tuple<int, std::string>(1, "test message");
Expand Down Expand Up @@ -276,7 +276,7 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_CallbacksNotCalledIfCannotConnect)
SetupMockSocketConnectExpectations(boost::system::errc::make_error_code(boost::system::errc::bad_address));

auto getMessagesCalled = false;
auto getMessages = [&getMessagesCalled](const int) -> boost::asio::awaitable<std::tuple<int, std::string>>
auto getMessages = [&getMessagesCalled](const size_t) -> boost::asio::awaitable<std::tuple<int, std::string>>
{
getMessagesCalled = true;
co_return std::tuple<int, std::string>(1, "test message");
Expand Down Expand Up @@ -323,7 +323,7 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_OnSuccessNotCalledIfAsyncWriteFails
SetupMockSocketWriteExpectations(boost::system::errc::make_error_code(boost::system::errc::bad_address));

auto getMessagesCalled = false;
auto getMessages = [&getMessagesCalled](const int) -> boost::asio::awaitable<std::tuple<int, std::string>>
auto getMessages = [&getMessagesCalled](const size_t) -> boost::asio::awaitable<std::tuple<int, std::string>>
{
getMessagesCalled = true;
co_return std::tuple<int, std::string>(1, "test message");
Expand Down Expand Up @@ -378,7 +378,7 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_OnSuccessNotCalledIfAsyncReadFails)
boost::system::errc::make_error_code(boost::system::errc::bad_address));

auto getMessagesCalled = false;
auto getMessages = [&getMessagesCalled](const int) -> boost::asio::awaitable<std::tuple<int, std::string>>
auto getMessages = [&getMessagesCalled](const size_t) -> boost::asio::awaitable<std::tuple<int, std::string>>
{
getMessagesCalled = true;
co_return std::tuple<int, std::string>(1, "test message");
Expand Down Expand Up @@ -432,7 +432,7 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_UnauthorizedCalledWhenAuthorization
SetupMockSocketReadExpectations(boost::beast::http::status::unauthorized);

auto getMessagesCalled = false;
auto getMessages = [&getMessagesCalled](const int) -> boost::asio::awaitable<std::tuple<int, std::string>>
auto getMessages = [&getMessagesCalled](const size_t) -> boost::asio::awaitable<std::tuple<int, std::string>>
{
getMessagesCalled = true;
co_return std::tuple<int, std::string>(1, "test message");
Expand Down
19 changes: 7 additions & 12 deletions src/agent/multitype_queue/include/multitype_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@ class MultiTypeQueue : public IMultiTypeQueue
{MessageType::COMMAND, "COMMAND"},
};

// TODO: doc
/// @brief
/// @brief maximun quantity of message to stored on the queue
size_t m_maxItems;

// TODO: doc
/// @brief
/// @brief timeout in milliseconds for refreshing the queue status
const std::chrono::milliseconds m_timeout;

// TODO: doc
/// @brief
/// @brief class for persistence implementation
std::unique_ptr<Persistence> m_persistenceDest;

// TODO: doc
/// @brief
/// @brief mutex for protecting the queue access
std::mutex m_mtx;

// TODO: doc
/// @brief
/// @brief condition variable related to the mutex
std::condition_variable m_cv;

/// @brief Time between batch requests
Expand Down Expand Up @@ -78,8 +73,8 @@ class MultiTypeQueue : public IMultiTypeQueue
m_batchInterval = config::agent::DEFAULT_BATCH_INTERVAL;
}

m_maxItems =
getConfigValue.template operator()<size_t>("agent", "queue_size").value_or(config::agent::QUEUE_DEFAULT_SIZE);
m_maxItems = getConfigValue.template operator()<size_t>("agent", "queue_size")
.value_or(config::agent::QUEUE_DEFAULT_SIZE);

const auto dbFilePath = dbFolderPath + "/" + config::agent::QUEUE_DB_NAME;

Expand Down
1 change: 0 additions & 1 deletion src/agent/multitype_queue/src/multitype_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ std::vector<Message> MultiTypeQueue::getNextN(MessageType type,
}
else if (std::holds_alternative<const size_t>(messageQuantity))
{
LogInfo("Requesting {}B ", std::get<const size_t>(messageQuantity));
arrayData = m_persistenceDest->RetrieveBySize(
std::get<const size_t>(messageQuantity), m_mapMessageTypeName.at(type), moduleName, moduleType);
}
Expand Down
3 changes: 2 additions & 1 deletion src/agent/multitype_queue/tests/multitype_queue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ namespace
return std::nullopt;
};

const auto MOCK_GET_CONFIG_SMALL_SIZE = []<typename T>(const std::string& table, const std::string& key) -> std::optional<T>
const auto MOCK_GET_CONFIG_SMALL_SIZE = []<typename T>(const std::string& table,
const std::string& key) -> std::optional<T>
{
if (table == "agent" && key == "path.data")
{
Expand Down
4 changes: 2 additions & 2 deletions src/agent/src/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void Agent::Run()
"FetchCommands");

m_taskManager.EnqueueTask(m_communicator.StatefulMessageProcessingTask(
[this](const int numMessages)
[this](const size_t numMessages)
{
return GetMessagesFromQueue(m_messageQueue,
MessageType::STATEFUL,
Expand All @@ -111,7 +111,7 @@ void Agent::Run()
"Stateful");

m_taskManager.EnqueueTask(m_communicator.StatelessMessageProcessingTask(
[this](const int numMessages)
[this](const size_t numMessages)
{
return GetMessagesFromQueue(m_messageQueue,
MessageType::STATELESS,
Expand Down
5 changes: 3 additions & 2 deletions src/agent/tests/message_queue_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,16 @@ TEST_F(MessageQueueUtilsTest, GetEmptyMessagesFromQueueTest)
metadata["agent"] = "test";

// NOLINTBEGIN(cppcoreguidelines-avoid-capturing-lambda-coroutines)
EXPECT_CALL(*mockQueue, getNextNAwaitable(MessageType::STATEFUL, MAX_MESSAGES, "", ""))
EXPECT_CALL(*mockQueue, getNextNAwaitable(MessageType::STATEFUL, MinMessagesSize, "", ""))
.WillOnce([&testMessages]() -> boost::asio::awaitable<std::vector<Message>> { co_return testMessages; });
// NOLINTEND(cppcoreguidelines-avoid-capturing-lambda-coroutines)

io_context.restart();

auto awaitableResult = boost::asio::co_spawn(
io_context,
GetMessagesFromQueue(mockQueue, MessageType::STATEFUL, MAX_MESSAGES, [&metadata]() { return metadata.dump(); }),
GetMessagesFromQueue(
mockQueue, MessageType::STATEFUL, MIN_SIZE_OF_MESSAGES, [&metadata]() { return metadata.dump(); }),
boost::asio::use_future);

const auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
Expand Down

0 comments on commit c21cc9a

Please sign in to comment.