Skip to content

Commit

Permalink
adding eventTime initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysied committed Jul 17, 2019
1 parent 0791f5b commit 67e1974
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions staging/src/k8s.io/client-go/tools/record/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ func (recorder *recorderImpl) makeEvent(ref *v1.ObjectReference, annotations map
InvolvedObject: *ref,
Reason: reason,
Message: message,
EventTime: (metav1.MicroTime)(t),
FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
Expand Down
1 change: 1 addition & 0 deletions staging/src/k8s.io/client-go/tools/record/events_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (e *EventAggregator) EventAggregate(newEvent *v1.Event) (*v1.Event, string)
Namespace: newEvent.Namespace,
},
Count: 1,
EventTime: (metav1.MicroTime)(now),
FirstTimestamp: now,
InvolvedObject: newEvent.InvolvedObject,
LastTimestamp: now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func makeEvent(reason, message string, involvedObject v1.ObjectReference) v1.Eve
Host: "kublet.node1",
},
Count: 1,
EventTime: (metav1.MicroTime)(eventTime),
FirstTimestamp: eventTime,
LastTimestamp: eventTime,
Type: v1.EventTypeNormal,
Expand Down Expand Up @@ -102,6 +103,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
}
actualFirstTimestamp := recvEvent.FirstTimestamp
actualLastTimestamp := recvEvent.LastTimestamp
actualEventTime := recvEvent.EventTime
if actualFirstTimestamp.Equal(&actualLastTimestamp) {
if expectCompression {
t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be different to indicate event compression happened, but were the same. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent)
Expand All @@ -114,6 +116,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
// Temp clear time stamps for comparison because actual values don't matter for comparison
recvEvent.FirstTimestamp = expectedEvent.FirstTimestamp
recvEvent.LastTimestamp = expectedEvent.LastTimestamp
recvEvent.EventTime = expectedEvent.EventTime
// Check that name has the right prefix.
if n, en := recvEvent.Name, expectedEvent.Name; !strings.HasPrefix(n, en) {
t.Errorf("%v - Name '%v' does not contain prefix '%v'", messagePrefix, n, en)
Expand All @@ -124,6 +127,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
}
recvEvent.FirstTimestamp = actualFirstTimestamp
recvEvent.LastTimestamp = actualLastTimestamp
recvEvent.EventTime = actualEventTime
return actualEvent, nil
}

Expand Down Expand Up @@ -240,6 +244,7 @@ func TestEventCorrelator(t *testing.T) {
now := metav1.NewTime(clock.Now())
event.FirstTimestamp = now
event.LastTimestamp = now
testInput.newEvent.EventTime = (metav1.MicroTime)(now)
result, err := correlator.EventCorrelate(&event)
if err != nil {
t.Errorf("scenario %v: unexpected error playing back prevEvents %v", testScenario, err)
Expand All @@ -254,6 +259,7 @@ func TestEventCorrelator(t *testing.T) {
now := metav1.NewTime(clock.Now())
testInput.newEvent.FirstTimestamp = now
testInput.newEvent.LastTimestamp = now
testInput.newEvent.EventTime = (metav1.MicroTime)(now)
result, err := correlator.EventCorrelate(&testInput.newEvent)
if err != nil {
t.Errorf("scenario %v: unexpected error correlating input event %v", testScenario, err)
Expand Down

0 comments on commit 67e1974

Please sign in to comment.