From e0aa1c71ea712f37d2a645b8e8086f42a69576b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=84=E9=A3=8F?= Date: Tue, 3 Dec 2024 06:32:20 +0000 Subject: [PATCH] polish --- .../common_provider/CommonConfigProvider.cpp | 4 ---- .../common_provider/CommonConfigProvider.h | 2 -- core/config/watcher/PipelineConfigWatcher.cpp | 22 +++++++++---------- core/config/watcher/PipelineConfigWatcher.h | 2 +- .../config/CommonConfigProviderUnittest.cpp | 14 +++++------- core/unittest/config/ConfigUpdateUnittest.cpp | 3 +-- .../unittest/config/ConfigWatcherUnittest.cpp | 9 +++----- 7 files changed, 21 insertions(+), 35 deletions(-) diff --git a/core/config/common_provider/CommonConfigProvider.cpp b/core/config/common_provider/CommonConfigProvider.cpp index 1131574141..e86808d7a2 100644 --- a/core/config/common_provider/CommonConfigProvider.cpp +++ b/core/config/common_provider/CommonConfigProvider.cpp @@ -132,10 +132,6 @@ void CommonConfigProvider::Stop() { } } -const std::map& CommonConfigProvider::GetAllInernalPipelineConfigs() { - return mPipelineMaps; -} - void CommonConfigProvider::LoadConfigFile() { error_code ec; lock_guard pipelineInfomaplock(mContinuousPipelineInfoMapMux); diff --git a/core/config/common_provider/CommonConfigProvider.h b/core/config/common_provider/CommonConfigProvider.h index 03da3e9972..f7a4e918a6 100644 --- a/core/config/common_provider/CommonConfigProvider.h +++ b/core/config/common_provider/CommonConfigProvider.h @@ -54,7 +54,6 @@ class CommonConfigProvider : public ConfigProvider, ConfigFeedbackable { void Init(const std::string& dir) override; void Stop() override; - const std::map& GetAllInernalPipelineConfigs(); void FeedbackContinuousPipelineConfigStatus(const std::string& name, ConfigFeedbackStatus status) override; void FeedbackInstanceConfigStatus(const std::string& name, ConfigFeedbackStatus status) override; void FeedbackOnetimePipelineConfigStatus(const std::string& type, @@ -131,7 +130,6 @@ class CommonConfigProvider : public ConfigProvider, ConfigFeedbackable { std::vector mConfigServerAddresses; int mConfigServerAddressId = 0; std::map mConfigServerTags; - std::map mPipelineMaps; #ifdef APSARA_UNIT_TEST_MAIN friend class CommonConfigProviderUnittest; diff --git a/core/config/watcher/PipelineConfigWatcher.cpp b/core/config/watcher/PipelineConfigWatcher.cpp index a0a0db9e14..d68d7cedf3 100644 --- a/core/config/watcher/PipelineConfigWatcher.cpp +++ b/core/config/watcher/PipelineConfigWatcher.cpp @@ -41,9 +41,9 @@ pair PipelineConfigWatcher::CheckConfigDiff( PipelineConfigDiff pDiff; TaskConfigDiff tDiff; unordered_set configSet; - // inner configs - InsertInnerPipelines(pDiff, tDiff, configSet); - // configs from file + // builtin pipeline configs + InsertBuiltInPipelines(pDiff, tDiff, configSet); + // file pipeline configs InsertPipelines(pDiff, tDiff, configSet); for (const auto& name : mPipelineManager->GetAllConfigNames()) { @@ -87,19 +87,14 @@ pair PipelineConfigWatcher::CheckConfigDiff( return make_pair(std::move(pDiff), std::move(tDiff)); } -void PipelineConfigWatcher::InsertInnerPipelines(PipelineConfigDiff& pDiff, +void PipelineConfigWatcher::InsertBuiltInPipelines(PipelineConfigDiff& pDiff, TaskConfigDiff& tDiff, unordered_set& configSet) { #ifdef __ENTERPRISE__ - const std::map& innerPipelines - = EnterpriseConfigProvider::GetInstance()->GetAllInernalPipelineConfigs(); -#else - const std::map& innerPipelines - = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs(); -#endif + const std::map& builtInPipelines + = EnterpriseConfigProvider::GetInstance()->GetAllBuiltInPipelineConfigs(); - // process - for (const auto& pipeline : innerPipelines) { + for (const auto& pipeline : builtInPipelines) { const string& pipelineName = pipeline.first; const string& pipleineDetail = pipeline.second; if (configSet.find(pipelineName) != configSet.end()) { @@ -173,6 +168,9 @@ void PipelineConfigWatcher::InsertInnerPipelines(PipelineConfigDiff& pDiff, LOG_DEBUG(sLogger, ("existing inner config unchanged", "skip current object")); } } +#else + return; +#endif } void PipelineConfigWatcher::InsertPipelines(PipelineConfigDiff& pDiff, diff --git a/core/config/watcher/PipelineConfigWatcher.h b/core/config/watcher/PipelineConfigWatcher.h index 28a7f00f97..98c2677264 100644 --- a/core/config/watcher/PipelineConfigWatcher.h +++ b/core/config/watcher/PipelineConfigWatcher.h @@ -46,7 +46,7 @@ class PipelineConfigWatcher : public ConfigWatcher { PipelineConfigWatcher(); ~PipelineConfigWatcher() = default; - void InsertInnerPipelines(PipelineConfigDiff& pDiff, TaskConfigDiff& tDiff, std::unordered_set& configSet); + void InsertBuiltInPipelines(PipelineConfigDiff& pDiff, TaskConfigDiff& tDiff, std::unordered_set& configSet); void InsertPipelines(PipelineConfigDiff& pDiff, TaskConfigDiff& tDiff, std::unordered_set& configSet); bool CheckAddedConfig(const std::string& configName, std::unique_ptr&& configDetail, diff --git a/core/unittest/config/CommonConfigProviderUnittest.cpp b/core/unittest/config/CommonConfigProviderUnittest.cpp index 1686af94dc..451880ceb4 100644 --- a/core/unittest/config/CommonConfigProviderUnittest.cpp +++ b/core/unittest/config/CommonConfigProviderUnittest.cpp @@ -433,19 +433,18 @@ void CommonConfigProviderUnittest::TestGetConfigUpdateAndConfigWatcher() { // 处理 pipelineconfig auto pipelineConfigDiff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); - auto innerPipelinesCnt = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs().size(); PipelineManager::GetInstance()->UpdatePipelines(pipelineConfigDiff.first); APSARA_TEST_TRUE(!pipelineConfigDiff.first.IsEmpty()); - APSARA_TEST_EQUAL(1U + innerPipelinesCnt, pipelineConfigDiff.first.mAdded.size()); - APSARA_TEST_EQUAL(pipelineConfigDiff.first.mAdded[innerPipelinesCnt].mName, "config1"); - APSARA_TEST_EQUAL(PipelineManager::GetInstance()->GetAllConfigNames().size(), 1 + innerPipelinesCnt); + APSARA_TEST_EQUAL(1U, pipelineConfigDiff.first.mAdded.size()); + APSARA_TEST_EQUAL(pipelineConfigDiff.first.mAdded[0].mName, "config1"); + APSARA_TEST_EQUAL(PipelineManager::GetInstance()->GetAllConfigNames().size(), 1); APSARA_TEST_TRUE(PipelineManager::GetInstance()->FindConfigByName("config1").get() != nullptr); // 再次处理 pipelineconfig pipelineConfigDiff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); PipelineManager::GetInstance()->UpdatePipelines(pipelineConfigDiff.first); APSARA_TEST_TRUE(pipelineConfigDiff.first.IsEmpty()); APSARA_TEST_TRUE(pipelineConfigDiff.first.mAdded.empty()); - APSARA_TEST_EQUAL(PipelineManager::GetInstance()->GetAllConfigNames().size(), 1 + innerPipelinesCnt); + APSARA_TEST_EQUAL(PipelineManager::GetInstance()->GetAllConfigNames().size(), 1); APSARA_TEST_TRUE(PipelineManager::GetInstance()->FindConfigByName("config1").get() != nullptr); @@ -650,18 +649,17 @@ void CommonConfigProviderUnittest::TestGetConfigUpdateAndConfigWatcher() { // 处理pipelineConfigDiff auto pipelineConfigDiff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); - auto innerPipelinesCnt = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs().size(); PipelineManager::GetInstance()->UpdatePipelines(pipelineConfigDiff.first); APSARA_TEST_TRUE(!pipelineConfigDiff.first.IsEmpty()); APSARA_TEST_EQUAL(1U, pipelineConfigDiff.first.mRemoved.size()); APSARA_TEST_EQUAL(pipelineConfigDiff.first.mRemoved[0], "config1"); - APSARA_TEST_EQUAL(0U + innerPipelinesCnt, PipelineManager::GetInstance()->GetAllConfigNames().size()); + APSARA_TEST_EQUAL(0U, PipelineManager::GetInstance()->GetAllConfigNames().size()); // 再次处理pipelineConfigDiff pipelineConfigDiff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); PipelineManager::GetInstance()->UpdatePipelines(pipelineConfigDiff.first); APSARA_TEST_TRUE(pipelineConfigDiff.first.IsEmpty()); APSARA_TEST_TRUE(pipelineConfigDiff.first.mRemoved.empty()); - APSARA_TEST_EQUAL(0U + innerPipelinesCnt, PipelineManager::GetInstance()->GetAllConfigNames().size()); + APSARA_TEST_EQUAL(0U, PipelineManager::GetInstance()->GetAllConfigNames().size()); APSARA_TEST_TRUE(provider.mInstanceConfigInfoMap.empty()); // 处理instanceConfigDiff diff --git a/core/unittest/config/ConfigUpdateUnittest.cpp b/core/unittest/config/ConfigUpdateUnittest.cpp index 38c9c167e4..341f48f00d 100644 --- a/core/unittest/config/ConfigUpdateUnittest.cpp +++ b/core/unittest/config/ConfigUpdateUnittest.cpp @@ -268,8 +268,7 @@ class ConfigUpdateUnittest : public testing::Test { void ConfigUpdateUnittest::OnStartUp() const { auto diff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); - auto innerPipelinesCnt = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs().size(); - APSARA_TEST_EQUAL(innerPipelinesCnt, diff.first.mAdded.size()); + APSARA_TEST_EQUAL(0U, diff.first.mAdded.size()); APSARA_TEST_TRUE(diff.second.IsEmpty()); GenerateInitialConfigs(); diff --git a/core/unittest/config/ConfigWatcherUnittest.cpp b/core/unittest/config/ConfigWatcherUnittest.cpp index c1908c9976..8ed7327cbc 100644 --- a/core/unittest/config/ConfigWatcherUnittest.cpp +++ b/core/unittest/config/ConfigWatcherUnittest.cpp @@ -51,8 +51,7 @@ const filesystem::path ConfigWatcherUnittest::instanceConfigDir = "./instance_co void ConfigWatcherUnittest::InvalidConfigDirFound() const { { auto diff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); - auto innerPipelinesCnt = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs().size(); - APSARA_TEST_EQUAL(innerPipelinesCnt, diff.first.mAdded.size()); + APSARA_TEST_EQUAL(0U, diff.first.mAdded.size()); APSARA_TEST_TRUE(diff.second.IsEmpty()); { ofstream fout("continuous_pipeline_config"); } @@ -84,8 +83,7 @@ void ConfigWatcherUnittest::InvalidConfigFileFound() const { fout << "[}"; } auto diff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); - auto innerPipelinesCnt = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs().size(); - APSARA_TEST_EQUAL(innerPipelinesCnt, diff.first.mAdded.size()); + APSARA_TEST_EQUAL(0U, diff.first.mAdded.size()); APSARA_TEST_TRUE(diff.second.IsEmpty()); filesystem::remove_all(configDir); } @@ -134,9 +132,8 @@ void ConfigWatcherUnittest::DuplicateConfigs() const { } { ofstream fout("dir2/config.json"); } auto diff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff(); - auto innerPipelinesCnt = CommonConfigProvider::GetInstance()->GetAllInernalPipelineConfigs().size(); APSARA_TEST_FALSE(diff.first.IsEmpty()); - APSARA_TEST_EQUAL(1U + innerPipelinesCnt, diff.first.mAdded.size()); + APSARA_TEST_EQUAL(1U, diff.first.mAdded.size()); filesystem::remove_all("dir1"); filesystem::remove_all("dir2");