-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
fix: adapt kubernetes event #29591
fix: adapt kubernetes event #29591
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,3 +116,17 @@ func ContainerIDWithRuntime(s PodContainerStatus) (string, string) { | |
} | ||
return "", "" | ||
} | ||
|
||
func EventLastTimestamp(eve *Event) metav1.Time { | ||
lastTimestamp := eve.LastTimestamp | ||
if lastTimestamp.IsZero() { | ||
if eve.Series != nil && !eve.Series.LastObservedTime.IsZero() { | ||
lastTimestamp = metav1.Time(eve.Series.LastObservedTime) | ||
} else if !eve.EventTime.IsZero() { | ||
lastTimestamp = metav1.Time(eve.EventTime) | ||
} else { | ||
lastTimestamp = eve.CreationTimestamp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this field actually exist? I cannot find on the version of the client library we use (v1.21): https://github.com/kubernetes/api/blob/release-1.21/core/v1/types.go#L5463 |
||
} | ||
} | ||
return lastTimestamp | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,18 @@ func (m *MetricSet) Run(reporter mb.PushReporter) { | |
return | ||
} | ||
|
||
func getEventCount(eve *kubernetes.Event) int32 { | ||
count := eve.Count | ||
if count == 0 { | ||
if eve.Series != nil && eve.Series.Count != 0 { | ||
count = eve.Series.Count | ||
} else { | ||
count = 1 | ||
} | ||
} | ||
return count | ||
} | ||
|
||
func generateMapStrFromEvent(eve *kubernetes.Event, dedotConfig dedotConfig) common.MapStr { | ||
eventMeta := common.MapStr{ | ||
"timestamp": common.MapStr{ | ||
|
@@ -176,7 +188,7 @@ func generateMapStrFromEvent(eve *kubernetes.Event, dedotConfig dedotConfig) com | |
"message": eve.Message, | ||
"reason": eve.Reason, | ||
"type": eve.Type, | ||
"count": eve.Count, | ||
"count": getEventCount(eve), | ||
"source": common.MapStr{ | ||
"host": eve.Source.Host, | ||
"component": eve.Source.Component, | ||
|
@@ -193,8 +205,14 @@ func generateMapStrFromEvent(eve *kubernetes.Event, dedotConfig dedotConfig) com | |
|
||
tsMap := make(common.MapStr) | ||
|
||
tsMap["first_occurrence"] = kubernetes.Time(&eve.FirstTimestamp).UTC() | ||
tsMap["last_occurrence"] = kubernetes.Time(&eve.LastTimestamp).UTC() | ||
lastTimestamp := kubernetes.EventLastTimestamp(eve) | ||
tsMap["first_occurrence"] = func() time.Time { | ||
if eve.FirstTimestamp.IsZero() { | ||
return kubernetes.Time(&lastTimestamp).UTC() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is correct. If an event has no Maybe it's better here to use |
||
} | ||
return kubernetes.Time(&eve.FirstTimestamp).UTC() | ||
}() | ||
tsMap["last_occurrence"] = kubernetes.Time(&lastTimestamp).UTC() | ||
|
||
if len(tsMap) != 0 { | ||
output["timestamp"] = tsMap | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we fallback to a value that is described as
Time when this Event was first observed
, is this something that is actually correct?EventTime
is mostly a good fallback ifFirstTimestamp
is not present.