Skip to content

Commit

Permalink
Unexport local functions in k8s matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
zentron committed Nov 27, 2018
1 parent 3a5b30d commit b176ab5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions filebeat/processor/add_kubernetes_metadata/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
}

const LogPathMatcherName = "logs_path"
const PathSeparator = string(os.PathSeparator)
const pathSeparator = string(os.PathSeparator)

type LogPathMatcher struct {
LogsPath string
Expand All @@ -62,8 +62,8 @@ func newLogsPathMatcher(cfg common.Config) (add_kubernetes_metadata.Matcher, err
}

logPath := config.LogsPath
if logPath[len(logPath)-1:] != PathSeparator {
logPath = logPath + PathSeparator
if logPath[len(logPath)-1:] != pathSeparator {
logPath = logPath + pathSeparator
}
resourceType := config.ResourceType

Expand Down Expand Up @@ -95,10 +95,10 @@ func (f *LogPathMatcher) MetadataIndex(event common.MapStr) string {
if f.ResourceType == "pod" {
// Specify a pod resource type when manually mounting log volumes and they end up under "/var/lib/kubelet/pods/"
// This will extract only the pod UID, which offers less granularity of metadata when compared to the container ID
if strings.HasPrefix(f.LogsPath, PodLogsPath()) && strings.HasSuffix(source, ".log") {
pathDirs := strings.Split(source, PathSeparator)
if strings.HasPrefix(f.LogsPath, podLogsPath()) && strings.HasSuffix(source, ".log") {
pathDirs := strings.Split(source, pathSeparator)
if len(pathDirs) > podUIDPos {
podUID := strings.Split(source, PathSeparator)[podUIDPos]
podUID := strings.Split(source, pathSeparator)[podUIDPos]

logp.Debug("kubernetes", "Using pod uid: %s", podUID)
return podUID
Expand All @@ -109,7 +109,7 @@ func (f *LogPathMatcher) MetadataIndex(event common.MapStr) string {
} else {
// In case of the Kubernetes log path "/var/log/containers/",
// the container ID will be located right before the ".log" extension.
if strings.HasPrefix(f.LogsPath, ContainerLogsPath()) && strings.HasSuffix(source, ".log") && sourceLen >= containerIdLen+4 {
if strings.HasPrefix(f.LogsPath, containerLogsPath()) && strings.HasSuffix(source, ".log") && sourceLen >= containerIdLen+4 {
containerIDEnd := sourceLen - 4
cid := source[containerIDEnd-containerIdLen : containerIDEnd]
logp.Debug("kubernetes", "Using container id: %s", cid)
Expand Down Expand Up @@ -138,14 +138,14 @@ func defaultLogPath() string {
return "/var/lib/docker/containers/"
}

func PodLogsPath() string {
func podLogsPath() string {
if runtime.GOOS == "windows" {
return "C:\\var\\lib\\kubelet\\pods\\"
}
return "/var/lib/kubelet/pods/"
}

func ContainerLogsPath() string {
func containerLogsPath() string {
if runtime.GOOS == "windows" {
return "C:\\var\\log\\containers\\"
}
Expand Down

0 comments on commit b176ab5

Please sign in to comment.