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

Improve some logging messages for add_kubernetes_metadata processor #16866

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix k8s pods annotations broken schema. {pull}16554[16554]
- Upgrade go-ucfg to latest v0.8.3. {pull}16450{16450}
- Fix `NewContainerMetadataEnricher` to use default config for kubernetes module. {pull}16857[16857]
- Improve some logging messages for add_kubernetes_metadata processor {pull}16866{16866}

*Auditbeat*

Expand Down
6 changes: 3 additions & 3 deletions filebeat/processor/add_kubernetes_metadata/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (f *LogPathMatcher) MetadataIndex(event common.MapStr) string {
logp.Debug("kubernetes", "Incoming log.file.path value: %s", source)

if !strings.Contains(source, f.LogsPath) {
logp.Debug("kubernetes", "Error extracting container id - source value does not contain matcher's logs_path '%s'.", f.LogsPath)
logp.Err("Error extracting container id - source value does not contain matcher's logs_path '%s'.", f.LogsPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in process of refactoring log related like logp.Err in #15699. I can create a separate PR for this after this PR gets merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! 😊

return ""
}

Expand All @@ -105,7 +105,7 @@ func (f *LogPathMatcher) MetadataIndex(event common.MapStr) string {
return podUID
}

logp.Debug("kubernetes", "Error extracting pod uid - source value contains matcher's logs_path, however it is too short to contain a Pod UID.")
logp.Err("Error extracting pod uid - source value contains matcher's logs_path, however it is too short to contain a Pod UID.")
}
} else {
// In case of the Kubernetes log path "/var/log/containers/",
Expand All @@ -125,7 +125,7 @@ func (f *LogPathMatcher) MetadataIndex(event common.MapStr) string {
return cid
}

logp.Debug("kubernetes", "Error extracting container id - source value contains matcher's logs_path, however it is too short to contain a Docker container ID.")
logp.Err("Error extracting container id - source value contains matcher's logs_path, however it is too short to contain a Docker container ID.")
}
}

Expand Down
4 changes: 2 additions & 2 deletions filebeat/processor/add_kubernetes_metadata/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func TestLogsPathMatcher_AnotherLogDir(t *testing.T) {
cfgLogsPath := "/var/log/other/"
sourcePath := "/var/log/other/%s.log"
if runtime.GOOS == "windows" {
cfgLogsPath = "C:\\var\\log\\other\\"
sourcePath = "C:\\var\\log\\other\\%s.log"
cfgLogsPath = "C:\\var\\log\\othere\\"
sourcePath = "C:\\var\\log\\othere\\%s.log"
}

source := fmt.Sprintf(sourcePath, cid)
Expand Down
4 changes: 4 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,14 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) {
}
index := k.matchers.MetadataIndex(event.Fields)
if index == "" {
k.log.Debug("No container match string, not adding kubernetes data")
return event, nil
}

k.log.Debugf("Using the following index key %s", index)
metadata := k.cache.get(index)
if metadata == nil {
k.log.Debugf("Index key %s did not match any of the cached resources", index)
return event, nil
}

Expand All @@ -224,6 +227,7 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) {
func (k *kubernetesAnnotator) addPod(pod *kubernetes.Pod) {
metadata := k.indexers.GetMetadata(pod)
for _, m := range metadata {
k.log.Debugf("Created index %s for pod %s/%s", m.Index, pod.GetNamespace(), pod.GetName())
k.cache.set(m.Index, m.Data)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"
)

// Test metadata updates don't replace existing pod metrics
Expand All @@ -38,6 +39,7 @@ func TestAnnotatorDeepUpdate(t *testing.T) {
}

processor := kubernetesAnnotator{
log: logp.NewLogger(selector),
cache: newCache(10 * time.Second),
matchers: &Matchers{
matchers: []Matcher{matcher},
Expand Down