Skip to content

Commit 6976061

Browse files
authored
Merge pull request #1201 from PapaPiya/configurable_path
[PDR-16096][fix]: logkit 多个关键目录无法自定义配置存储路径
2 parents b5500fa + 2e1b962 commit 6976061

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

mgr/dataflow.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ func RawData(readerConfig conf.MapConf) ([]string, error) {
5656
if rawDataTimeOut < 10 || rawDataTimeOut > 300 {
5757
rawDataTimeOut = DefaultRawDataTimeout
5858
}
59-
configMetaPath := runnerName + "_" + Hash(strconv.FormatInt(time.Now().Unix(), 10))
60-
metaPath := filepath.Join(MetaTmp, configMetaPath)
59+
metaPath, _ := readerConfig.GetString(config.KeyMetaTmpPath)
60+
if metaPath == "" {
61+
configMetaPath := runnerName + "_" + Hash(strconv.FormatInt(time.Now().Unix(), 10))
62+
metaPath = filepath.Join(MetaTmp, configMetaPath)
63+
}
6164
log.Debugf("Runner[%v] Using %s as default metaPath", runnerName, metaPath)
6265
readerConfig[config.KeyMetaPath] = metaPath
6366
size, _ := readerConfig.GetIntOr("raw_data_lines", DefaultRawDataBatchLen)

reader/config/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
KeyLogPath = "log_path"
1515
KeyLogPathOld = "log_path_old"
1616
KeyMetaPath = "meta_path"
17+
KeyMetaTmpPath = "meta_tmp_path"
1718
KeyFileDone = "file_done"
1819
KeyMode = "mode"
1920
KeyBufSize = "reader_buf_size"

reader/meta.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,18 @@ func GetLogPathAbs(conf conf.MapConf) (logpath, oldLogPath string, err error) {
850850
return logpath, oldLogPath, err
851851
}
852852

853+
func SetMetaPath(conf conf.MapConf, runnerName, metaDir string) {
854+
if metaDir == "" {
855+
return
856+
}
857+
logPath, _ := conf.GetStringOr(KeyLogPath, "")
858+
if logPath != "" {
859+
logPath = filepath.Base(logPath)
860+
}
861+
metaPath := filepath.Join(metaDir, fmt.Sprintf("%s_%s", runnerName, Hash(logPath)))
862+
conf[KeyMetaPath] = metaPath
863+
}
864+
853865
func GetMetaOption(conf conf.MapConf) (string, string, string, error) {
854866
mode, _ := conf.GetStringOr(KeyMode, ModeDir)
855867
logPath, oldLogPath, err := GetLogPathAbs(conf)

0 commit comments

Comments
 (0)