Skip to content

Commit

Permalink
Improve some logging messages for add_kubernetes_metadata processor (e…
Browse files Browse the repository at this point in the history
…lastic#16866)

Switch from Debug to Error when unrecoveral events happen and
add extra debug messages when indexing and matching pods.
  • Loading branch information
flaper87 authored Mar 6, 2020
1 parent c756ba8 commit 1d6323f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
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)
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
2 changes: 2 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/kubernetes_test.go
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

0 comments on commit 1d6323f

Please sign in to comment.