Skip to content

Commit

Permalink
feat: remove batchInterval from communicator
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioDonda committed Dec 11, 2024
1 parent fd9679a commit a9b4410
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 35 deletions.
12 changes: 0 additions & 12 deletions src/agent/communicator/include/communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ namespace communicator
m_retryInterval = getConfigValue.template operator()<std::time_t>("agent", "retry_interval")
.value_or(config::agent::DEFAULT_RETRY_INTERVAL);

m_batchInterval = getConfigValue.template operator()<std::time_t>("events", "batch_interval")
.value_or(config::agent::DEFAULT_BATCH_INTERVAL);

if (m_batchInterval < 1'000 || m_batchInterval > (1'000 * 60 * 60))
{
LogWarn("batch_interval must be between 1s and 1h. Using default value.");
m_batchInterval = config::agent::DEFAULT_BATCH_INTERVAL;
}

m_batchSize = getConfigValue.template operator()<size_t>("events", "batch_size")
.value_or(config::agent::DEFAULT_BATCH_SIZE);

Expand Down Expand Up @@ -135,9 +126,6 @@ namespace communicator
/// @brief Time in milliseconds between authentication attemps in case of failure
std::time_t m_retryInterval = config::agent::DEFAULT_RETRY_INTERVAL;

/// @brief Time between batch requests
std::time_t m_batchInterval = config::agent::DEFAULT_BATCH_INTERVAL;

/// @brief Size for batch requests
size_t m_batchSize = config::agent::DEFAULT_BATCH_SIZE;

Expand Down
1 change: 0 additions & 1 deletion src/agent/communicator/include/http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace http_client
std::function<boost::asio::awaitable<std::tuple<int, std::string>>(const size_t)> messageGetter,
std::function<void()> onUnauthorized,
std::time_t connectionRetry,
std::time_t batchInterval,
size_t batchSize,
std::function<void(const int, const std::string&)> onSuccess = {},
std::function<bool()> loopRequestCondition = {}) override;
Expand Down
1 change: 0 additions & 1 deletion src/agent/communicator/include/ihttp_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace http_client
std::function<boost::asio::awaitable<std::tuple<int, std::string>>(const size_t)> messageGetter,
std::function<void()> onUnauthorized,
std::time_t connectionRetry,
std::time_t batchInterval,
size_t batchSize,
std::function<void(const int, const std::string&)> onSuccess = {},
std::function<bool()> loopRequestCondition = {}) = 0;
Expand Down
3 changes: 0 additions & 3 deletions src/agent/communicator/src/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ namespace communicator
{},
onAuthenticationFailed,
m_retryInterval,
m_batchInterval,
m_batchSize,
onSuccess,
loopCondition);
Expand Down Expand Up @@ -169,7 +168,6 @@ namespace communicator
getMessages,
onAuthenticationFailed,
m_retryInterval,
m_batchInterval,
m_batchSize,
onSuccess,
loopCondition);
Expand Down Expand Up @@ -198,7 +196,6 @@ namespace communicator
getMessages,
onAuthenticationFailed,
m_retryInterval,
m_batchInterval,
m_batchSize,
onSuccess,
loopCondition);
Expand Down
5 changes: 0 additions & 5 deletions src/agent/communicator/src/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ namespace http_client
std::function<boost::asio::awaitable<std::tuple<int, std::string>>(const size_t)> messageGetter,
std::function<void()> onUnauthorized,
std::time_t connectionRetry,
std::time_t batchInterval,
size_t batchSize,
std::function<void(const int, const std::string&)> onSuccess,
std::function<bool()> loopRequestCondition)
Expand Down Expand Up @@ -156,10 +155,6 @@ namespace http_client

if (messageGetter != nullptr)
{
//TODO: delete batchInterval
boost::asio::steady_timer batchTimeoutTimer(co_await boost::asio::this_coro::executor);
batchTimeoutTimer.expires_after(std::chrono::milliseconds(batchInterval));

while (loopRequestCondition != nullptr && loopRequestCondition())
{
const auto messages = co_await messageGetter(batchSize);
Expand Down
9 changes: 3 additions & 6 deletions src/agent/communicator/tests/communicator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ TEST(CommunicatorTest, StatefulMessageProcessingTask_Success)
GetMessagesFuncType pGetMessages,
std::function<void()>,
[[maybe_unused]] std::time_t connectionRetry,
[[maybe_unused]] std::time_t batchInterval,
[[maybe_unused]] size_t batchSize,
std::function<void(const int, const std::string&)> pOnSuccess,
[[maybe_unused]] std::function<bool()> loopRequestCondition) -> boost::asio::awaitable<void>
Expand All @@ -78,7 +77,7 @@ TEST(CommunicatorTest, StatefulMessageProcessingTask_Success)
co_return;
};

EXPECT_CALL(*mockHttpClient, Co_PerformHttpRequest(_, _, _, _, _, _, _, _, _))
EXPECT_CALL(*mockHttpClient, Co_PerformHttpRequest(_, _, _, _, _, _, _, _))
.WillOnce(Invoke(MockCo_PerformHttpRequest));

communicator::Communicator communicator(std::move(mockHttpClient), "uuid", "key", nullptr, FUNC);
Expand Down Expand Up @@ -118,7 +117,6 @@ TEST(CommunicatorTest, WaitForTokenExpirationAndAuthenticate_FailedAuthenticatio
[[maybe_unused]] GetMessagesFuncType pGetMessages,
[[maybe_unused]] std::function<void()> onUnauthorized,
[[maybe_unused]] std::time_t connectionRetry,
[[maybe_unused]] std::time_t batchInterval,
[[maybe_unused]] size_t batchSize,
[[maybe_unused]] std::function<void(const int, const std::string&)> onSuccess,
[[maybe_unused]] std::function<bool()> loopCondition) -> boost::asio::awaitable<void>
Expand All @@ -128,7 +126,7 @@ TEST(CommunicatorTest, WaitForTokenExpirationAndAuthenticate_FailedAuthenticatio
};

// A following call to Co_PerformHttpRequest should not have a token
EXPECT_CALL(*mockHttpClientPtr, Co_PerformHttpRequest(_, _, _, _, _, _, _, _, _))
EXPECT_CALL(*mockHttpClientPtr, Co_PerformHttpRequest(_, _, _, _, _, _, _, _))
.WillOnce(Invoke(MockCo_PerformHttpRequest));

boost::asio::io_context ioContext;
Expand Down Expand Up @@ -179,7 +177,6 @@ TEST(CommunicatorTest, StatelessMessageProcessingTask_CallsWithValidToken)
[[maybe_unused]] GetMessagesFuncType pGetMessages,
[[maybe_unused]] std::function<void()> onUnauthorized,
[[maybe_unused]] std::time_t connectionRetry,
[[maybe_unused]] std::time_t batchInterval,
[[maybe_unused]] size_t batchSize,
[[maybe_unused]] std::function<void(const int, const std::string&)> onSuccess,
[[maybe_unused]] std::function<bool()> loopCondition) -> boost::asio::awaitable<void>
Expand All @@ -188,7 +185,7 @@ TEST(CommunicatorTest, StatelessMessageProcessingTask_CallsWithValidToken)
co_return;
};

EXPECT_CALL(*mockHttpClientPtr, Co_PerformHttpRequest(_, _, _, _, _, _, _, _, _))
EXPECT_CALL(*mockHttpClientPtr, Co_PerformHttpRequest(_, _, _, _, _, _, _, _))
.WillOnce(Invoke(MockCo_PerformHttpRequest));

boost::asio::io_context ioContext;
Expand Down
5 changes: 0 additions & 5 deletions src/agent/communicator/tests/http_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ TEST_P(HttpClientTest, Co_PerformHttpRequest_Success)
onUnauthorized,
5, // NOLINT
1, // NOLINT
1, // NOLINT
onSuccess,
loopRequestCondition);

Expand Down Expand Up @@ -303,7 +302,6 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_CallbacksNotCalledIfCannotConnect)
onUnauthorized,
5, // NOLINT
1, // NOLINT
1, // NOLINT
onSuccess,
nullptr);

Expand Down Expand Up @@ -357,7 +355,6 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_OnSuccessNotCalledIfAsyncWriteFails
onUnauthorized,
5, // NOLINT
1, // NOLINT
1, // NOLINT
onSuccess,
loopRequestCondition);

Expand Down Expand Up @@ -413,7 +410,6 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_OnSuccessNotCalledIfAsyncReadFails)
onUnauthorized,
5, // NOLINT
1, // NOLINT
1, // NOLINT
onSuccess,
loopRequestCondition);

Expand Down Expand Up @@ -468,7 +464,6 @@ TEST_F(HttpClientTest, Co_PerformHttpRequest_UnauthorizedCalledWhenAuthorization
onUnauthorized,
5, // NOLINT
1, // NOLINT
1, // NOLINT
onSuccess,
loopRequestCondition);

Expand Down
1 change: 0 additions & 1 deletion src/agent/communicator/tests/mocks/mock_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class MockHttpClient : public http_client::IHttpClient
std::function<boost::asio::awaitable<intStringTuple>(const size_t)> messageGetter,
std::function<void()> onUnauthorized,
std::time_t connectionRetry,
std::time_t batchInterval,
size_t batchSize,
std::function<void(const int, const std::string&)> onSuccess,
std::function<bool()> loopRequestCondition),
Expand Down
2 changes: 1 addition & 1 deletion src/agent/multitype_queue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ find_package(Boost REQUIRED COMPONENTS asio)

add_library(MultiTypeQueue src/sqlitestorage.cpp src/multitype_queue.cpp src/persistence_factory.cpp)
target_include_directories(MultiTypeQueue PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(MultiTypeQueue PUBLIC nlohmann_json::nlohmann_json Boost::asio PRIVATE SQLiteCpp fmt::fmt Logger)
target_link_libraries(MultiTypeQueue PUBLIC Config nlohmann_json::nlohmann_json Boost::asio PRIVATE SQLiteCpp fmt::fmt Logger)

include(../../cmake/ConfigureTarget.cmake)
configure_target(MultiTypeQueue)
Expand Down
15 changes: 15 additions & 0 deletions src/agent/multitype_queue/src/multitype_queue.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <multitype_queue.hpp>

#include <config.h>
#include <logger.hpp>
#include <persistence_factory.hpp>

Expand All @@ -14,6 +15,20 @@ MultiTypeQueue::MultiTypeQueue(const std::string& dbFolderPath, size_t size, int
{
const auto dbFilePath = dbFolderPath + "/" + QUEUE_DB_NAME;

// const ConfigGetter& getConfigValue

// m_batchInterval = getConfigValue.template operator()<std::time_t>("events", "batch_interval")
// .value_or(config::agent::DEFAULT_BATCH_INTERVAL);

// if (m_batchInterval < 1'000 || m_batchInterval > (1'000 * 60 * 60))
// {
// LogWarn("batch_interval must be between 1s and 1h. Using default value.");
// m_batchInterval = config::agent::DEFAULT_BATCH_INTERVAL;
// }

// /// @brief Time between batch requests
// std::time_t m_batchInterval = config::agent::DEFAULT_BATCH_INTERVAL;

try
{
m_persistenceDest = PersistenceFactory::createPersistence(PersistenceFactory::PersistenceType::SQLITE3,
Expand Down

0 comments on commit a9b4410

Please sign in to comment.