Skip to content

Commit

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

Switch from Debug to Error when unrecoveral events happen and
add extra debug messages when indexing and matching pods.

(cherry picked from commit 1d6323f)

Co-authored-by: Flavio Percoco <flaper87@gmail.com>
  • Loading branch information
Carlos Pérez-Aradros Herce and flaper87 committed Mar 17, 2020
1 parent 0f31732 commit 5ef9c8c
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 @@ -86,6 +86,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Upgrade go-ucfg to latest v0.8.3. {pull}16450{16450}
- Add `ssl.ca_sha256` option to the supported TLS option, this allow to check that a specific certificate is used as part of the verified chain. {issue}15717[15717]
- Fix `NewContainerMetadataEnricher` to use default config for kubernetes module. {pull}16857[16857]
- Improve some logging messages for add_kubernetes_metadata processor {pull}16866{16866}
- Fix k8s metadata issue regarding node labels not shown up on root level of metadata. {pull}16834[16834]

*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 5ef9c8c

Please sign in to comment.