Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support configServer V2 #1592

Merged
merged 41 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e510929
modify pb
quzard Jul 3, 2024
735ff23
Merge remote-tracking branch 'origin/main' into add-pb-v2-config
quzard Jul 5, 2024
e12c3c9
fix
quzard Jul 5, 2024
5fc1a8a
rm mAttributes
quzard Jul 5, 2024
ab3622a
rm FetchConfig
quzard Jul 5, 2024
5099796
rm SendHeartBeat
quzard Jul 5, 2024
ce7f50c
add ProcessSourceDir
quzard Jul 5, 2024
2d6f928
support CommonConfigProvider
quzard Jul 5, 2024
ecb0ae8
add FetchProcessConfigFromServer and FetchPipelineConfigFromServer
quzard Jul 5, 2024
b4c5c35
fix test
quzard Jul 5, 2024
29a5716
add config feedbacker
yyuuttaaoo Jul 7, 2024
632c4e2
fix loadconfigfile
yyuuttaaoo Jul 7, 2024
61f2236
heartbeat
quzard Jul 8, 2024
f7c71ff
Merge branch 'add-pb-v2-config' of github.com:quzard/ilogtail into ad…
quzard Jul 8, 2024
bcf2965
rm once from cpp
quzard Jul 8, 2024
73ed36e
add mProcessFileInfoMap
quzard Jul 8, 2024
2a35ce6
add CommandSource
quzard Jul 8, 2024
10bdd72
modify ConfigWatcher
quzard Jul 10, 2024
201596e
modify mRegion
quzard Jul 10, 2024
b631d23
modify operator=
quzard Jul 10, 2024
e965763
modify
quzard Jul 10, 2024
dfd8252
format
quzard Jul 10, 2024
fd9be79
modify
quzard Jul 10, 2024
1b64e88
Merge remote-tracking branch 'origin/main' into add-pb-v2-config
quzard Jul 15, 2024
2feaf90
fix Update
quzard Jul 15, 2024
e4270e6
add test
quzard Jul 15, 2024
210007e
add RegisterCallback
quzard Jul 15, 2024
a7679b3
fix
quzard Jul 15, 2024
2a1e6b8
format
quzard Jul 15, 2024
9620876
add test
quzard Jul 15, 2024
b6300f7
fix test
quzard Jul 15, 2024
0596d47
add FeedbackProcessConfigStatus
quzard Jul 16, 2024
8ae972e
rm callbacks
quzard Jul 16, 2024
6e37835
fix test
quzard Jul 16, 2024
2dd767c
add ConfigFeedbackableUnittest
quzard Jul 16, 2024
9b091f8
fix
quzard Jul 16, 2024
f4e6281
add GenerateCommandFeedBackKey
quzard Jul 16, 2024
3c086e3
LCOV_EXCL_STOP
quzard Jul 16, 2024
6ed5cb1
fix
quzard Jul 16, 2024
71d41ec
Merge remote-tracking branch 'origin/main' into add-pb-v2-config
quzard Jul 16, 2024
bedf60e
rm provider
quzard Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config_server/protocol/v2/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enum RequestFlags {
// API: /Agent/Heartbeat

// Agent sends requests to the ConfigServer to get config updates and receive commands.
message HearbeatRequest {
message HeartbeatRequest {
bytes request_id = 1;
uint64 sequence_num = 2; // Increment every request, for server to check sync status
uint64 capabilities = 3; // Bitmask of flags defined by AgentCapabilities enum
Expand All @@ -85,7 +85,7 @@ message HearbeatRequest {
repeated CommandInfo custom_commands = 12; // Information about command history
uint64 flags = 13; // Predefined command flag
bytes opaque = 14; // Opaque data for extension
// before 100 (inclusive) are reserved for future official fields}
// before 100 (inclusive) are reserved for future official fields
}

// Define Config's detail
Expand Down
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/flusher/links.cmake)

# Subdirectories (modules). except for common, input, processor, flusher, observer, helper and spl.
set(SUB_DIRECTORIES_LIST
batch application app_config checkpoint compression config config/provider config/watcher config_manager config_server_pb
batch application app_config checkpoint compression config config/feedbacker config/provider config/watcher config_manager config_server_pb/v1 config_server_pb/v2
container_manager controller event event_handler event_listener file_server go_pipeline log_pb logger
models monitor parser pipeline plugin plugin/creator plugin/instance plugin/interface polling
profile_sender queue reader sdk sender serializer sls_control fuse
Expand Down
53 changes: 38 additions & 15 deletions core/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
#include "monitor/LogFileProfiler.h"
#include "monitor/MetricExportor.h"
#include "monitor/Monitor.h"
#include "pipeline/PipelineManager.h"
#include "pipeline/PipelineConfigManager.h"
#include "pipeline/ProcessConfigManager.h"
#include "plugin/PluginRegistry.h"
#include "processor/daemon/LogProcess.h"
#include "sender/Sender.h"
Expand All @@ -55,6 +56,7 @@
#endif
#else
#include "config/provider/CommonConfigProvider.h"
#include "config/provider/LegacyCommonConfigProvider.h"
#endif
#include "queue/ExactlyOnceQueueManager.h"

Expand Down Expand Up @@ -193,23 +195,39 @@ void Application::Start() {
// flusher_sls should always be loaded, since profiling will rely on this.
Sender::Instance()->Init();

// add local config dir
filesystem::path localConfigPath
= filesystem::path(AppConfig::GetInstance()->GetLogtailSysConfDir()) / "config" / "local";
error_code ec;
filesystem::create_directories(localConfigPath, ec);
if (ec) {
LOG_WARNING(sLogger,
("failed to create dir for local config",
"manual creation may be required")("error code", ec.value())("error msg", ec.message()));
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分代码下一步抽离到LocalProvider的Init里。

// add local config dir
filesystem::path localConfigPath
= filesystem::path(AppConfig::GetInstance()->GetLogtailSysConfDir()) / "config" / "local";
error_code ec;
filesystem::create_directories(localConfigPath, ec);
if (ec) {
LOG_WARNING(sLogger,
("failed to create dir for local pipelineconfig",
"manual creation may be required")("error code", ec.value())("error msg", ec.message()));
}
ConfigWatcher::GetInstance()->AddPipelineSource(localConfigPath.string());
}
{
// add local config dir
filesystem::path localConfigPath
= filesystem::path(AppConfig::GetInstance()->GetLogtailSysConfDir()) / "processconfig" / "local";
error_code ec;
filesystem::create_directories(localConfigPath, ec);
if (ec) {
LOG_WARNING(sLogger,
("failed to create dir for local processconfig",
"manual creation may be required")("error code", ec.value())("error msg", ec.message()));
}
ConfigWatcher::GetInstance()->AddProcessSource(localConfigPath.string());
}
ConfigWatcher::GetInstance()->AddSource(localConfigPath.string());

#ifdef __ENTERPRISE__
EnterpriseConfigProvider::GetInstance()->Init("enterprise");
LegacyConfigProvider::GetInstance()->Init("legacy");
#else
CommonConfigProvider::GetInstance()->Init("common");
CommonConfigProvider::GetInstance()->Init("common_v2");
LegacyCommonConfigProvider::GetInstance()->Init("common");
#endif

LogtailAlarm::GetInstance()->Init();
Expand Down Expand Up @@ -251,9 +269,13 @@ void Application::Start() {
lastCheckTagsTime = curTime;
}
if (curTime - lastConfigCheckTime >= INT32_FLAG(config_scan_interval)) {
ConfigDiff diff = ConfigWatcher::GetInstance()->CheckConfigDiff();
if (!diff.IsEmpty()) {
PipelineManager::GetInstance()->UpdatePipelines(diff);
PipelineConfigDiff pipelineConfigDiff = ConfigWatcher::GetInstance()->CheckPipelineConfigDiff();
if (!pipelineConfigDiff.IsEmpty()) {
PipelineManager::GetInstance()->UpdatePipelines(pipelineConfigDiff);
}
ProcessConfigDiff processConfigDiff = ConfigWatcher::GetInstance()->CheckProcessConfigDiff();
if (!processConfigDiff.IsEmpty()) {
ProcessConfigManager::GetInstance()->UpdateProcessConfigs(processConfigDiff);
}
lastConfigCheckTime = curTime;
}
Expand Down Expand Up @@ -330,6 +352,7 @@ void Application::Exit() {
LegacyConfigProvider::GetInstance()->Stop();
#else
CommonConfigProvider::GetInstance()->Stop();
LegacyCommonConfigProvider::GetInstance()->Stop();
#endif

LogtailMonitor::GetInstance()->Stop();
Expand Down
18 changes: 14 additions & 4 deletions core/config/ConfigDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@
#include <string>
#include <vector>

#include "config/Config.h"
#include "config/PipelineConfig.h"
#include "config/ProcessConfig.h"

namespace logtail {

struct ConfigDiff {
std::vector<Config> mAdded;
std::vector<Config> mModified;
class PipelineConfigDiff {
public:
std::vector<PipelineConfig> mAdded;
std::vector<PipelineConfig> mModified;
std::vector<std::string> mRemoved;
std::vector<std::string> mUnchanged; // 过渡使用,仅供插件系统用
bool IsEmpty() { return mRemoved.empty() && mAdded.empty() && mModified.empty(); }
};

class ProcessConfigDiff {
public:
std::vector<ProcessConfig> mAdded;
std::vector<ProcessConfig> mModified;
std::vector<std::string> mRemoved;
std::vector<std::string> mUnchanged; // 过渡使用,仅供插件系统用
bool IsEmpty() { return mRemoved.empty() && mAdded.empty() && mModified.empty(); }
};

Expand Down
6 changes: 3 additions & 3 deletions core/config/Config.cpp → core/config/PipelineConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "config/Config.h"
#include "config/PipelineConfig.h"

#include <string>

Expand Down Expand Up @@ -94,7 +94,7 @@ static void ReplaceEnvVarRef(Json::Value& value, bool& res) {
}
}

bool Config::Parse() {
bool PipelineConfig::Parse() {
if (BOOL_FLAG(enable_env_ref_in_config)) {
if (ReplaceEnvVar()) {
LOG_INFO(sLogger, ("env vars in config are replaced, config", mDetail->toStyledString())("config", mName));
Expand Down Expand Up @@ -698,7 +698,7 @@ bool Config::Parse() {
return true;
}

bool Config::ReplaceEnvVar() {
bool PipelineConfig::ReplaceEnvVar() {
bool res = false;
ReplaceEnvVarRef(*mDetail, res);
return res;
Expand Down
8 changes: 4 additions & 4 deletions core/config/Config.h → core/config/PipelineConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace logtail {

struct Config {
struct PipelineConfig {
std::string mName;
std::unique_ptr<Json::Value> mDetail;
uint32_t mCreateTime = 0;
Expand All @@ -49,7 +49,7 @@ struct Config {
std::string mLogstore;
std::string mRegion;

Config(const std::string& name, std::unique_ptr<Json::Value>&& detail) : mName(name), mDetail(std::move(detail)) {}
PipelineConfig(const std::string& name, std::unique_ptr<Json::Value>&& detail) : mName(name), mDetail(std::move(detail)) {}

bool Parse();

Expand All @@ -75,11 +75,11 @@ struct Config {
bool ReplaceEnvVar();
};

inline bool operator==(const Config& lhs, const Config& rhs) {
inline bool operator==(const PipelineConfig& lhs, const PipelineConfig& rhs) {
return (lhs.mName == rhs.mName) && (*lhs.mDetail == *rhs.mDetail);
}

inline bool operator!=(const Config& lhs, const Config& rhs) {
inline bool operator!=(const PipelineConfig& lhs, const PipelineConfig& rhs) {
return !(lhs == rhs);
}

Expand Down
30 changes: 30 additions & 0 deletions core/config/ProcessConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023 iLogtail Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "config/ProcessConfig.h"

#include <string>

#include "app_config/AppConfig.h"
#include "common/FileSystemUtil.h"
#include "common/Flags.h"
#include "common/JsonUtil.h"
#include "common/ParamExtractor.h"
#include "common/YamlUtil.h"
#include "plugin/PluginRegistry.h"


using namespace std;

namespace logtail {} // namespace logtail
88 changes: 88 additions & 0 deletions core/config/ProcessConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2023 iLogtail Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <json/json.h>
#include <re2/re2.h>

#include <cstdint>
#include <filesystem>
#include <memory>
#include <string>
#include <vector>

namespace logtail {

struct ProcessConfig {
std::string mName;
std::unique_ptr<Json::Value> mDetail;

// for alarm only
std::string mProject;
std::string mLogstore;
std::string mRegion;

ProcessConfig(const std::string& name, std::unique_ptr<Json::Value>&& detail)
: mName(name), mDetail(std::move(detail)) {
mProject = "";
mLogstore = "";
mRegion = "";
}
ProcessConfig(const logtail::ProcessConfig& config) {
mName = config.mName;
mDetail = std::make_unique<Json::Value>(*config.mDetail);
mProject = "";
mLogstore = "";
mRegion = "";
}

ProcessConfig& operator=(ProcessConfig&& other) {
if (this != &other) {
mName = std::move(other.mName);
mDetail = std::move(other.mDetail);
mProject = "";
mLogstore = "";
mRegion = "";
}
return *this;
}

ProcessConfig& operator=(const ProcessConfig& other) {
if (this != &other) {
mName = other.mName;
mDetail = std::make_unique<Json::Value>(*other.mDetail);
mProject = "";
mLogstore = "";
mRegion = "";
}
return *this;
}

bool Parse() { return true; }

const Json::Value& GetConfig() const { return *mDetail; }
};

inline bool operator==(const ProcessConfig& lhs, const ProcessConfig& rhs) {
return (lhs.mName == rhs.mName) && (*lhs.mDetail == *rhs.mDetail);
}

inline bool operator!=(const ProcessConfig& lhs, const ProcessConfig& rhs) {
return !(lhs == rhs);
}

} // namespace logtail
Loading
Loading