From 94cd582c7b8612e5fb0eea8621567606d39a6b59 Mon Sep 17 00:00:00 2001 From: quzard <1191890118@qq.com> Date: Tue, 31 Dec 2024 17:19:20 +0000 Subject: [PATCH] add GetAgentPrometheusAuthorizationPath --- core/app_config/AppConfig.cpp | 17 +++++++++++++++++ core/app_config/AppConfig.h | 1 + core/go_pipeline/LogtailPlugin.cpp | 1 + core/plugin/flusher/sls/SLSClientManager.cpp | 2 +- pkg/config/global_config.go | 3 +++ plugins/input/prometheus/input_prometheus.go | 2 +- 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/app_config/AppConfig.cpp b/core/app_config/AppConfig.cpp index c3662f8279..8eface143d 100644 --- a/core/app_config/AppConfig.cpp +++ b/core/app_config/AppConfig.cpp @@ -283,6 +283,23 @@ std::string GetAgentLogDir() { return dir; } +std::string GetAgentPrometheusAuthorizationPath() { + static std::string dir; + if (!dir.empty()) { + return dir; + } +#if defined(APSARA_UNIT_TEST_MAIN) + dir = GetProcessExecutionDir(); +#else + if (BOOL_FLAG(logtail_mode)) { + dir = GetProcessExecutionDir(); + } else { + return AppConfig::GetInstance()->GetLoongcollectorConfDir(); + } +#endif + return dir; +} + std::string GetAgentGoLogConfDir() { static std::string dir; if (!dir.empty()) { diff --git a/core/app_config/AppConfig.h b/core/app_config/AppConfig.h index 3c4779d3f3..38f79dc24d 100644 --- a/core/app_config/AppConfig.h +++ b/core/app_config/AppConfig.h @@ -49,6 +49,7 @@ std::string GetAgentThirdPartyDir(); std::string GetAgentGoCheckpointDir(); std::string GetAgentGoLogConfDir(); +std::string GetAgentPrometheusAuthorizationPath(); std::string GetAgentConfigFile(); std::string GetAgentAppInfoFile(); std::string GetAdhocCheckpointDirPath(); diff --git a/core/go_pipeline/LogtailPlugin.cpp b/core/go_pipeline/LogtailPlugin.cpp index 4ef9d61ce9..a163e68de0 100644 --- a/core/go_pipeline/LogtailPlugin.cpp +++ b/core/go_pipeline/LogtailPlugin.cpp @@ -73,6 +73,7 @@ LogtailPlugin::LogtailPlugin() { mPluginCfg["LoongcollectorVersionTag"] = GetVersionTag(); mPluginCfg["LoongcollectorCheckPointFile"] = GetGoPluginCheckpoint(); mPluginCfg["LoongcollectorThirdPartyDir"] = GetAgentThirdPartyDir(); + mPluginCfg["PrometheusAuthorizationPath"] = GetAgentPrometheusAuthorizationPath(); mPluginCfg["HostIP"] = LoongCollectorMonitor::mIpAddr; mPluginCfg["Hostname"] = LoongCollectorMonitor::mHostname; mPluginCfg["EnableContainerdUpperDirDetect"] = BOOL_FLAG(enable_containerd_upper_dir_detect); diff --git a/core/plugin/flusher/sls/SLSClientManager.cpp b/core/plugin/flusher/sls/SLSClientManager.cpp index a0a0d8acab..db7d1527a3 100644 --- a/core/plugin/flusher/sls/SLSClientManager.cpp +++ b/core/plugin/flusher/sls/SLSClientManager.cpp @@ -20,8 +20,8 @@ #include "app_config/AppConfig.h" #include "common/Flags.h" -#include "common/MachineInfoUtil.h" #include "common/HashUtil.h" +#include "common/MachineInfoUtil.h" #include "common/StringTools.h" #include "common/http/Constant.h" #include "common/http/Curl.h" diff --git a/pkg/config/global_config.go b/pkg/config/global_config.go index 92e5a34606..f2f9dd9a56 100644 --- a/pkg/config/global_config.go +++ b/pkg/config/global_config.go @@ -28,6 +28,8 @@ type GlobalConfig struct { DefaultLogQueueSize int DefaultLogGroupQueueSize int Tags map[string]string + // Directory to store prometheus configuration file. + PrometheusAuthorizationPath string // Directory to store loongcollector data, such as checkpoint, etc. LoongcollectorConfDir string // Directory to store loongcollector log config. @@ -82,6 +84,7 @@ func newGlobalConfig() (cfg GlobalConfig) { LoongcollectorDataDir: "./data/", LoongcollectorDebugDir: "./debug/", LoongcollectorThirdPartyDir: "./thirdparty/", + PrometheusAuthorizationPath: "./conf/", DelayStopSec: 300, } return diff --git a/plugins/input/prometheus/input_prometheus.go b/plugins/input/prometheus/input_prometheus.go index 0ecd38100c..c4f08c969b 100644 --- a/plugins/input/prometheus/input_prometheus.go +++ b/plugins/input/prometheus/input_prometheus.go @@ -85,7 +85,7 @@ func (p *ServiceStaticPrometheus) Init(context pipeline.Context) (int, error) { case p.Yaml != "": detail = []byte(p.Yaml) if p.AuthorizationPath == "" { - p.AuthorizationPath = config.LoongcollectorGlobalConfig.LoongcollectorConfDir + p.AuthorizationPath = config.LoongcollectorGlobalConfig.PrometheusAuthorizationPath } case p.ConfigFilePath != "": f, err := os.Open(p.ConfigFilePath)