Skip to content

Commit

Permalink
Use DoubleBuffer and if there is no valid instance_identity file, req…
Browse files Browse the repository at this point in the history
…uest ecsmeta once at startup. (#2021)

(cherry picked from commit 2f2061e)
  • Loading branch information
quzard committed Jan 13, 2025
1 parent 969f80c commit 6169522
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 181 deletions.
37 changes: 35 additions & 2 deletions core/app_config/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,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 @@ -343,11 +369,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 @@ -391,7 +424,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
9 changes: 7 additions & 2 deletions core/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ void Application::Init() {
}

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

#ifdef __ENTERPRISE__
if (!InstanceIdentity::Instance()->InitFromFile()) {
InstanceIdentity::Instance()->InitFromNetwork();
InstanceIdentity::Instance()->DumpInstanceIdentity();
}
#endif
// Initialize basic information: IP, hostname, etc.
LoongCollectorMonitor::GetInstance();
#ifdef __ENTERPRISE__
Expand Down Expand Up @@ -168,7 +173,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

0 comments on commit 6169522

Please sign in to comment.