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

[BUG]:容器内日志文件路径**通配采集不到文件 #1545

Open
liqq86 opened this issue Jun 18, 2024 · 0 comments
Open

[BUG]:容器内日志文件路径**通配采集不到文件 #1545

liqq86 opened this issue Jun 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@liqq86
Copy link

liqq86 commented Jun 18, 2024

Describe the bug
业务pod容器宿主机挂载,并且业务pod正常输出到日志文件:
volumeMounts:
- mountPath: /var/log/als/file/output/
name: volume1
volumes:

  • hostPath:
    path: /app/logs/
    type: ""
    name: volume1
    配置采集规则的input:
    "inputs" : [ {
    "Type" : "input_file",
    "FilePaths" : [ "/var/log/**/random_json_file_.log" ],
    "MaxDirSearchDepth" : 5,
    "ExcludeFilePaths" : [ ],
    "TailSizeKB" : 0,
    "EnableContainerDiscovery" : true,
    "ContainerFilters" : {
    "K8sNamespaceRegex" : "rule-verify-namespace",
    "K8sPodRegex" : "hostpath-json-
    "
    },
    "AppendingLogPositionMeta" : true,
    "AllowingIncludedByMultiConfigs" : true
    } ],

原因:没有匹配到正确的挂载点,StartsWith("/var/log", "/var/log/als/file/output")这里是false ,而是使用了容器内的overlay路径,因此采不到。
日志:
set container base dir:/lmtagent_host/data/docker/overlay2/4997753881ff76a72d83f61d622324e2fb21a8d48e12c914e4b812483e1202fc/diff/var/log container id:92a89d9354a5a3692ab5f51323bcd7170efc5580a59676ba1a2af35645ce821f logPath:/var/log

InputFile.cpp 代码:
bool InputFile::SetContainerBaseDir(ContainerInfo& containerInfo, const std::string& logPath, const std::string& configName) {
if (!containerInfo.mRealBaseDir.empty()) {
return true;
}
size_t pthSize = logPath.size();

size_t size = containerInfo.mMounts.size();
size_t bestMatchedMountsIndex = size;
// ParseByJSONObj 确保 Destination、Source、mUpperDir 不会以\或者/结尾
for (size_t i = 0; i < size; ++i) {
    StringView dst = containerInfo.mMounts[i].mDestination;
    size_t dstSize = dst.size();

    if (StartWith(logPath, dst)
        && (pthSize == dstSize || (pthSize > dstSize && (logPath[dstSize] == '/' || logPath[dstSize] == '\\')))
        && (bestMatchedMountsIndex == size
            || containerInfo.mMounts[bestMatchedMountsIndex].mDestination.size() < dstSize)) {
        bestMatchedMountsIndex = i;
    }
}
if (bestMatchedMountsIndex < size) {
    containerInfo.mRealBaseDir = STRING_FLAG(default_container_host_path)
        + containerInfo.mMounts[bestMatchedMountsIndex].mSource
        + logPath.substr(containerInfo.mMounts[bestMatchedMountsIndex].mDestination.size());
    LOG_DEBUG(sLogger,
              ("set container base dir",
               containerInfo.mRealBaseDir)("source", containerInfo.mMounts[bestMatchedMountsIndex].mSource)(
                  "destination", containerInfo.mMounts[bestMatchedMountsIndex].mDestination)("logPath", logPath));
} else {
    containerInfo.mRealBaseDir = STRING_FLAG(default_container_host_path) + containerInfo.mUpperDir + logPath;
}
LOG_INFO(sLogger, ("set container base dir", containerInfo.mRealBaseDir)("container id", containerInfo.mID)("logPath", logPath)("config", configName));
return true;

}

@liqq86 liqq86 added the bug Something isn't working label Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant