Skip to content

Commit

Permalink
fix: use eventime as the event version to improve the granularity (#8822
Browse files Browse the repository at this point in the history
)
  • Loading branch information
xuriwuyun authored Jan 21, 2025
1 parent 1f8a679 commit ee38f3e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions controllers/k8score/event_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ var _ = Describe("Event Controller", func() {
role = "follower"
sndValidEvent := createRoleChangedEvent(podName, role, uid)
sndValidEvent.LastTimestamp = metav1.NewTime(afterLastTS)
sndValidEvent.EventTime = metav1.NewMicroTime(afterLastTS)
Expect(testCtx.CreateObj(ctx, sndValidEvent)).Should(Succeed())
Eventually(func() string {
event := &corev1.Event{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/instanceset/pod_role_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func parseGlobalRoleSnapshot(role string, event *corev1.Event) *common.GlobalRol
if err := json.Unmarshal([]byte(role), snapshot); err == nil {
return snapshot
}
snapshot.Version = strconv.FormatInt(event.LastTimestamp.UnixMicro(), 10)
snapshot.Version = strconv.FormatInt(event.EventTime.UnixMicro(), 10)
pair := common.PodRoleNamePair{
PodName: event.InvolvedObject.Name,
RoleName: role,
Expand Down
5 changes: 4 additions & 1 deletion pkg/kbagent/util/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ func createOrUpdateEvent(reason, message string) error {
if err == nil {
// update
event.Count++
event.LastTimestamp = metav1.Now()
// the granularity of lastTimestamp is second and it is not enough for the event.
// there may multiple events in the same second, so we need to use EventTime here.
// event.LastTimestamp = metav1.Now()
event.EventTime = metav1.NowMicro()
_, err = eventsClient.Update(context.Background(), event, metav1.UpdateOptions{})
if err == nil {
return nil
Expand Down

0 comments on commit ee38f3e

Please sign in to comment.