Skip to content

Commit

Permalink
fix enable containerd upper dir detect not effective (#2041)
Browse files Browse the repository at this point in the history
* fix enable containerd upper dir detect not effective

* remove useless comment
  • Loading branch information
yyuuttaaoo authored Jan 23, 2025
1 parent d8b756e commit 5e562cb
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 101 deletions.
63 changes: 0 additions & 63 deletions core/common/LogtailCommonFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,6 @@

#include "common/LogtailCommonFlags.h"

// 商业版
// DEFINE_FLAG_STRING(ilogtail_aliuid_env_name, "aliuid", "ALIYUN_LOGTAIL_USER_ID");
// DEFINE_FLAG_STRING(ilogtail_user_defined_id_env_name, "user defined id", "ALIYUN_LOGTAIL_USER_DEFINED_ID");
// DEFINE_FLAG_STRING(logtail_sys_conf_users_dir, "", "users");
// DEFINE_FLAG_STRING(user_defined_id_file, "", "user_defined_id");
// DEFINE_FLAG_INT32(default_StreamLog_tcp_port, "", 11111);
// DEFINE_FLAG_INT32(default_StreamLog_poll_size_in_mb, "", 50);
// DEFINE_FLAG_INT32(default_StreamLog_recv_size_each_call, "<= 1Mb", 1024);
// DEFINE_FLAG_INT64(default_StreamLog_fd_send_buffer, "", 512 * 1024);
// DEFINE_FLAG_INT64(default_StreamLog_fd_send_timeout, "", 10 * 1000 * 1000);
// DEFINE_FLAG_INT32(StreamLog_line_max_length, "", 10 * 1024 * 1024);
// DEFINE_FLAG_STRING(logtail_config_address,
// "the target address to which to get config update",
// "http://config.sls.aliyun-inc.com");
// DEFINE_FLAG_STRING(logtail_send_address,
// "the target address to which to send the log result",
// "http://sls.aliyun-inc.com");

// 移动
// Windows only has polling, give a bigger tail limit.
// #if defined(__linux__)
// DEFINE_FLAG_INT32(default_tail_limit_kb,
// "when first open file, if offset little than this value, move offset to beginning, KB",
// 1024);
// #elif defined(_MSC_VER)
// DEFINE_FLAG_INT32(default_tail_limit_kb,
// "when first open file, if offset little than this value, move offset to beginning, KB",
// 1024 * 50);
// #endif
// DEFINE_FLAG_BOOL(enable_sls_metrics_format, "if enable format metrics in SLS metricstore log pattern", false);
// DEFINE_FLAG_BOOL(enable_containerd_upper_dir_detect,
// "if enable containerd upper dir detect when locating rootfs",
// false);
// DEFINE_FLAG_INT32(profile_data_send_interval, "interval of send LogFile/DomainSocket profile data, seconds", 600);
// DEFINE_FLAG_STRING(logtail_profile_snapshot, "reader profile on local disk", "logtail_profile_snapshot");
// DEFINE_FLAG_BOOL(default_secondary_storage, "default strategy whether enable secondary storage", false);
// DEFINE_FLAG_INT32(buffer_check_period, "check logtail local storage buffer period", 60);
// DEFINE_FLAG_INT32(log_expire_time, "log expire time", 24 * 3600);
// DEFINE_FLAG_INT32(max_holded_data_size,
// "for every id and metric name, the max data size can be holded in memory (default 512KB)",
// 512 * 1024);
// DEFINE_FLAG_INT32(pub_max_holded_data_size,
// "for every id and metric name, the max data size can be holded in memory (default 512KB)",
// 512 * 1024);
// DEFINE_FLAG_INT32(batch_send_metric_size, "batch send metric size limit(bytes)(default 256KB)", 256 * 1024);
// DEFINE_FLAG_INT32(batch_send_interval, "batch sender interval (second)(default 3)", 3);
// DEFINE_FLAG_INT32(default_max_inotify_watch_num, "the max allowed inotify watch dir number", 3000);
// DEFINE_FLAG_STRING(app_info_file, "", "app_info.json");
// DEFINE_FLAG_STRING(ilogtail_config_env_name, "config file path", "ALIYUN_LOGTAIL_CONFIG");
// DEFINE_FLAG_STRING(app_info_file, "", "app_info.json");

// 废弃
// DEFINE_FLAG_STRING(fuse_root_dir, "root dir for fuse file polling", "/home/admin/logs");
// DEFINE_FLAG_INT32(fuse_dir_max_depth, "max depth from fuse root dir", 100);
// DEFINE_FLAG_INT32(fuse_file_max_count, "max file total count from fuse root dir", 10000);
// DEFINE_FLAG_STRING(user_log_config,
// "the configuration file storing user's log collecting parameter",
// "user_log_config.json");
// DEFINE_FLAG_STRING(local_machine_uuid, "use this value if not empty, for ut/debug", "");
// DEFINE_FLAG_STRING(logtail_status_snapshot, "status on local disk", "logtail_status_snapshot");

// DEFINE_FLAG_STRING(logtail_line_count_snapshot, "line count file on local disk", "logtail_line_count_snapshot.json");
// DEFINE_FLAG_STRING(logtail_integrity_snapshot, "integrity file on local disk", "logtail_integrity_snapshot.json");

// app config
DEFINE_FLAG_STRING(ilogtail_config,
Expand Down
4 changes: 0 additions & 4 deletions core/go_pipeline/LogtailPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
#endif

DEFINE_FLAG_BOOL(enable_sls_metrics_format, "if enable format metrics in SLS metricstore log pattern", false);
DEFINE_FLAG_BOOL(enable_containerd_upper_dir_detect,
"if enable containerd upper dir detect when locating rootfs",
false);
DECLARE_FLAG_STRING(ALIYUN_LOG_FILE_TAGS);

using namespace std;
Expand Down Expand Up @@ -77,7 +74,6 @@ LogtailPlugin::LogtailPlugin() {
mPluginCfg["LoongcollectorPrometheusAuthorizationPath"] = GetAgentPrometheusAuthorizationPath();
mPluginCfg["HostIP"] = LoongCollectorMonitor::mIpAddr;
mPluginCfg["Hostname"] = LoongCollectorMonitor::mHostname;
mPluginCfg["EnableContainerdUpperDirDetect"] = BOOL_FLAG(enable_containerd_upper_dir_detect);
mPluginCfg["EnableSlsMetricsFormat"] = BOOL_FLAG(enable_sls_metrics_format);
mPluginCfg["FileTagsPath"] = STRING_FLAG(ALIYUN_LOG_FILE_TAGS);
}
Expand Down
2 changes: 0 additions & 2 deletions core/logtail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ DECLARE_FLAG_STRING(metrics_report_method);
DECLARE_FLAG_INT32(data_server_port);
DECLARE_FLAG_BOOL(enable_env_ref_in_config);
DECLARE_FLAG_BOOL(enable_sls_metrics_format);
DECLARE_FLAG_BOOL(enable_containerd_upper_dir_detect);
DECLARE_FLAG_BOOL(logtail_mode);

void HandleSigtermSignal(int signum, siginfo_t* info, void* context) {
Expand Down Expand Up @@ -84,7 +83,6 @@ static void overwrite_community_edition_flags() {
STRING_FLAG(metrics_report_method) = "";
INT32_FLAG(data_server_port) = 443;
BOOL_FLAG(enable_env_ref_in_config) = true;
BOOL_FLAG(enable_containerd_upper_dir_detect) = true;
BOOL_FLAG(enable_sls_metrics_format) = false;
}

Expand Down
2 changes: 0 additions & 2 deletions core/logtail_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ DECLARE_FLAG_STRING(metrics_report_method);
DECLARE_FLAG_INT32(data_server_port);
DECLARE_FLAG_BOOL(enable_env_ref_in_config);
DECLARE_FLAG_BOOL(enable_sls_metrics_format);
DECLARE_FLAG_BOOL(enable_containerd_upper_dir_detect);

static void overwrite_community_edition_flags() {
// support run in installation dir on default
STRING_FLAG(metrics_report_method) = "";
INT32_FLAG(data_server_port) = 443;
BOOL_FLAG(enable_env_ref_in_config) = true;
BOOL_FLAG(enable_containerd_upper_dir_detect) = true;
BOOL_FLAG(enable_sls_metrics_format) = false;
}

Expand Down
12 changes: 7 additions & 5 deletions docs/cn/installation/start-with-k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@
```yaml
- name: loongcollector
command:
- /usr/local/loongcollector/loongcollector_control.sh
- /usr/local/loongcollector/loongcollector_control.sh
args:
- "start_and_block"
- "-enable_containerd_upper_dir_detect=true"
- "-dirfile_check_interval_ms=5000"
- "-logtail_checkpoint_check_gc_interval_sec=120"
- "start_and_block"
- "-dirfile_check_interval_ms=5000"
- "-logtail_checkpoint_check_gc_interval_sec=120"
env:
- name: enable_containerd_upper_dir_detect
value: "true"
```

应用上述配置
Expand Down
9 changes: 4 additions & 5 deletions pkg/config/global_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ type GlobalConfig struct {
DelayStopSec int
FileTagsPath string

EnableTimestampNanosecond bool
UsingOldContentTag bool
EnableContainerdUpperDirDetect bool
EnableSlsMetricsFormat bool
EnableProcessorTag bool
EnableTimestampNanosecond bool
UsingOldContentTag bool
EnableSlsMetricsFormat bool
EnableProcessorTag bool

PipelineMetaTagKey map[string]string
AppendingAllEnvMetaTag bool
Expand Down
38 changes: 20 additions & 18 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,25 @@ var (

SelfEnvConfigFlag bool

GlobalConfig = flag.String("global", "./global.json", "global config.")
PluginConfig = flag.String("plugin", "./plugin.json", "plugin config.")
FlusherConfig = flag.String("flusher", "./default_flusher.json", "the default flusher configuration is used not only in the plugins without flusher but also to transfer the self telemetry data.")
ForceSelfCollect = flag.Bool("force-statics", false, "force collect self telemetry data before closing.")
AutoProfile = flag.Bool("prof-auto", true, "auto dump prof file when prof-flag is open.")
HTTPProfFlag = flag.Bool("prof-flag", false, "http pprof flag.")
Cpuprofile = flag.String("cpu-profile", "cpu.prof", "write cpu profile to file.")
Memprofile = flag.String("mem-profile", "mem.prof", "write mem profile to file.")
HTTPAddr = flag.String("server", ":18689", "http server address.")
Doc = flag.Bool("doc", false, "generate plugin docs")
DocPath = flag.String("docpath", "./docs/en/plugins", "generate plugin docs")
HTTPLoadFlag = flag.Bool("http-load", false, "export http endpoint for load plugin config.")
FileIOFlag = flag.Bool("file-io", false, "use file for input or output.")
InputFile = flag.String("input-file", "./input.log", "input file")
InputField = flag.String("input-field", "content", "input file")
InputLineLimit = flag.Int("input-line-limit", 1000, "input file")
OutputFile = flag.String("output-file", "./output.log", "output file")
StatefulSetFlag = flag.Bool("ALICLOUD_LOG_STATEFULSET_FLAG", false, "alibaba log export ports flag, set true if you want to use it")
EnableContainerdUpperDirDetect = flag.Bool("enable_containerd_upper_dir_detect", false, "if enable containerd upper dir detect when locating rootfs")
GlobalConfig = flag.String("global", "./global.json", "global config.")
PluginConfig = flag.String("plugin", "./plugin.json", "plugin config.")
FlusherConfig = flag.String("flusher", "./default_flusher.json", "the default flusher configuration is used not only in the plugins without flusher but also to transfer the self telemetry data.")
ForceSelfCollect = flag.Bool("force-statics", false, "force collect self telemetry data before closing.")
AutoProfile = flag.Bool("prof-auto", true, "auto dump prof file when prof-flag is open.")
HTTPProfFlag = flag.Bool("prof-flag", false, "http pprof flag.")
Cpuprofile = flag.String("cpu-profile", "cpu.prof", "write cpu profile to file.")
Memprofile = flag.String("mem-profile", "mem.prof", "write mem profile to file.")
HTTPAddr = flag.String("server", ":18689", "http server address.")
Doc = flag.Bool("doc", false, "generate plugin docs")
DocPath = flag.String("docpath", "./docs/en/plugins", "generate plugin docs")
HTTPLoadFlag = flag.Bool("http-load", false, "export http endpoint for load plugin config.")
FileIOFlag = flag.Bool("file-io", false, "use file for input or output.")
InputFile = flag.String("input-file", "./input.log", "input file")
InputField = flag.String("input-field", "content", "input file")
InputLineLimit = flag.Int("input-line-limit", 1000, "input file")
OutputFile = flag.String("output-file", "./output.log", "output file")
StatefulSetFlag = flag.Bool("ALICLOUD_LOG_STATEFULSET_FLAG", false, "alibaba log export ports flag, set true if you want to use it")

DeployMode = flag.String("DEPLOY_MODE", DeployDaemonset, "alibaba log deploy mode, daemonset or statefulset or singleton")
EnableKubernetesMeta = flag.Bool("ENABLE_KUBERNETES_META", false, "enable kubernetes meta")
Expand Down Expand Up @@ -331,6 +332,7 @@ func init() {
_ = util.InitFromEnvString("ALICLOUD_LOG_REGION", DefaultRegion, *DefaultRegion)
_ = util.InitFromEnvBool("ALICLOUD_LOG_PLUGIN_ENV_CONFIG", DockerConfigPluginInitFlag, *DockerConfigPluginInitFlag)

_ = util.InitFromEnvBool("enable_containerd_upper_dir_detect", EnableContainerdUpperDirDetect, *EnableContainerdUpperDirDetect)
_ = util.InitFromEnvBool("LOGTAIL_DEBUG_FLAG", HTTPProfFlag, *HTTPProfFlag)
_ = util.InitFromEnvBool("LOGTAIL_AUTO_PROF", AutoProfile, *AutoProfile)
_ = util.InitFromEnvBool("LOGTAIL_FORCE_COLLECT_SELF_TELEMETRY", ForceSelfCollect, *ForceSelfCollect)
Expand Down
4 changes: 2 additions & 2 deletions pkg/helper/docker_cri_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"google.golang.org/grpc"
cri "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"

"github.com/alibaba/ilogtail/pkg/config"
"github.com/alibaba/ilogtail/pkg/flags"
"github.com/alibaba/ilogtail/pkg/logger"
)

Expand Down Expand Up @@ -174,7 +174,7 @@ func NewCRIRuntimeWrapper(dockerCenter *DockerCenter) (*CRIRuntimeWrapper, error
}

var containerdClient *containerd.Client
if config.LoongcollectorGlobalConfig.EnableContainerdUpperDirDetect {
if *flags.EnableContainerdUpperDirDetect {
containerdClient, err = containerd.New(containerdUnixSocket, containerd.WithDefaultNamespace("k8s.io"))
if err == nil {
_, err = containerdClient.Version(context.Background())
Expand Down

0 comments on commit 5e562cb

Please sign in to comment.