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

Use DoubleBuffer and if there is no valid instance_identity file, request ecsmeta once at startup. #2021

Merged
merged 33 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
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
37 changes: 35 additions & 2 deletions core/app_config/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ std::string GetAgentGoLogConfDir() {
return dir;
}

std::string GetBufferFileDir() {
static std::string dir;
if (!dir.empty()) {
return dir;
}
if (BOOL_FLAG(logtail_mode)) {
dir = GetProcessExecutionDir();
} else {
dir = GetAgentDataDir();
}
return dir;
}

std::string GetHistoryDataPath() {
static std::string dir;
if (!dir.empty()) {
return dir;
}
if (BOOL_FLAG(logtail_mode)) {
dir = GetProcessExecutionDir();
} else {
dir = GetAgentDataDir();
}
return dir;
}

std::string GetAgentGoCheckpointDir() {
static std::string dir;
if (!dir.empty()) {
Expand All @@ -344,11 +370,18 @@ std::string GetAgentDataDir() {
dir = GetProcessExecutionDir();
#else
if (BOOL_FLAG(logtail_mode)) {
dir = GetProcessExecutionDir();
dir = AppConfig::GetInstance()->GetLoongcollectorConfDir() + PATH_SEPARATOR + "checkpoint";
} else {
dir = STRING_FLAG(loongcollector_data_dir) + PATH_SEPARATOR;
}
#endif
if (!CheckExistance(dir)) {
if (Mkdirs(dir)) {
LOG_INFO(sLogger, ("create data dir success", dir));
} else {
LOG_ERROR(sLogger, ("create data dir failed", dir));
}
}
return dir;
}

Expand Down Expand Up @@ -392,7 +425,7 @@ std::string GetAgentDockerPathConfig() {
return file_path;
}
if (BOOL_FLAG(logtail_mode)) {
file_path = GetAgentDataDir() + STRING_FLAG(ilogtail_docker_file_path_config);
file_path = GetProcessExecutionDir() + STRING_FLAG(ilogtail_docker_file_path_config);
} else {
file_path = GetAgentDataDir() + "docker_path_config.json";
}
Expand Down
2 changes: 2 additions & 0 deletions core/app_config/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ std::string GetAgentConfDir();
std::string GetAgentRunDir();
std::string GetAgentThirdPartyDir();

std::string GetBufferFileDir();
std::string GetHistoryDataPath();
std::string GetAgentGoCheckpointDir();
std::string GetAgentGoLogConfDir();
std::string GetAgentPrometheusAuthorizationPath();
Expand Down
10 changes: 8 additions & 2 deletions core/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ void Application::Init() {
}

AppConfig::GetInstance()->LoadAppConfig(GetAgentConfigFile());

#ifdef __ENTERPRISE__
InstanceIdentity::Instance()->InitFromFile();
if (InstanceIdentity::Instance()->NeedFetchECSMeta()) {
InstanceIdentity::Instance()->InitFromNetwork();
InstanceIdentity::Instance()->DumpInstanceIdentity();
}
#endif
// Initialize basic information: IP, hostname, etc.
LoongCollectorMonitor::GetInstance();
#ifdef __ENTERPRISE__
Expand Down Expand Up @@ -168,7 +174,7 @@ void Application::Init() {
appInfoJson["UUID"] = Json::Value(Application::GetInstance()->GetUUID());
appInfoJson["instance_id"] = Json::Value(Application::GetInstance()->GetInstanceId());
#ifdef __ENTERPRISE__
appInfoJson["host_id"] = Json::Value(HostIdentifier::Instance()->GetHostId().id);
appInfoJson["host_id"] = Json::Value(InstanceIdentity::Instance()->GetEntity()->GetHostID().to_string());
appInfoJson[GetVersionTag()] = Json::Value(ILOGTAIL_VERSION);
#else
appInfoJson[GetVersionTag()] = Json::Value(string(ILOGTAIL_VERSION) + " Community Edition");
Expand Down
Loading
Loading