Skip to content

Commit

Permalink
Enhance filter check in k8s event metricset (elastic#29470) (elastic#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 17, 2021
1 parent fa132b7 commit fb9e7cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Groups same timestamp metric values to one event in the app_insights metricset. {pull}20403[20403]
- Fix in rename processor to ingest metrics for `write.iops` to proper field instead of `write_iops` in rds metricset. {pull}28960[28960]
- Use xpack.enabled on SM modules to write into .monitoring indices when using Metricbeat standalone {pull}28365[28365]
- Enhance filter check in kubernetes event metricset. {pull}29470[29470]

*Packetbeat*

Expand Down
5 changes: 5 additions & 0 deletions libbeat/common/kubernetes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func Time(t *metav1.Time) time.Time {
return t.Time
}

// MicroTime extracts time from k8s.MicroTime type
func MicroTime(t *metav1.MicroTime) time.Time {
return t.Time
}

// ContainerID parses the container ID to get the actual ID string
func ContainerID(s PodContainerStatus) string {
cID, _ := ContainerIDWithRuntime(s)
Expand Down
10 changes: 9 additions & 1 deletion metricbeat/module/kubernetes/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,16 @@ func (m *MetricSet) Run(reporter mb.PushReporter) {
m.watcher.AddEventHandler(kubernetes.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
eve := obj.(*kubernetes.Event)
// if fields are null they are decoded to `0001-01-01 00:00:00 +0000 UTC`
// so we need to check if they are valid first
lastTimestampValid := !kubernetes.Time(&eve.LastTimestamp).IsZero()
eventTimeValid := !kubernetes.MicroTime(&eve.EventTime).IsZero()
// if skipOlder, skip events happened before watch
if m.skipOlder && kubernetes.Time(&eve.LastTimestamp).Before(now) {
if m.skipOlder && kubernetes.Time(&eve.LastTimestamp).Before(now) && lastTimestampValid {
return false
} else if m.skipOlder && kubernetes.MicroTime(&eve.EventTime).Before(now) && eventTimeValid {
// there might be cases that `LastTimestamp` is not a valid number so double check
// with `EventTime`
return false
}
return true
Expand Down

0 comments on commit fb9e7cf

Please sign in to comment.