mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Merge pull request #4206 from saad-ali/modifyEventStruct
Modify Event struct to allow compressing multiple recurring events in to a single event
This commit is contained in:
commit
8eeb2d1358
@ -211,6 +211,22 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
|
||||
c.Fuzz(&ct.Privileged)
|
||||
c.Fuzz(&ct.Capabilities)
|
||||
},
|
||||
func(e *api.Event, c fuzz.Continue) {
|
||||
// Fix event count to 1, otherwise, if a v1beta1 or v1beta2 event has a count set arbitrarily, it's count is ignored
|
||||
c.Fuzz(&e.TypeMeta)
|
||||
c.Fuzz(&e.ObjectMeta)
|
||||
c.Fuzz(&e.InvolvedObject)
|
||||
c.Fuzz(&e.Reason)
|
||||
c.Fuzz(&e.Message)
|
||||
c.Fuzz(&e.Source)
|
||||
c.Fuzz(&e.FirstTimestamp)
|
||||
c.Fuzz(&e.LastTimestamp)
|
||||
if e.FirstTimestamp.IsZero() {
|
||||
e.Count = 1
|
||||
} else {
|
||||
c.Fuzz(&e.Count)
|
||||
}
|
||||
},
|
||||
)
|
||||
return f
|
||||
}
|
||||
|
@ -1079,8 +1079,14 @@ type Event struct {
|
||||
// Optional. The component reporting this event. Should be a short machine understandable string.
|
||||
Source EventSource `json:"source,omitempty"`
|
||||
|
||||
// The time at which the client recorded the event. (Time of server receipt is in TypeMeta.)
|
||||
Timestamp util.Time `json:"timestamp,omitempty"`
|
||||
// The time at which the event was first recorded. (Time of server receipt is in TypeMeta.)
|
||||
FirstTimestamp util.Time `json:"firstTimestamp,omitempty"`
|
||||
|
||||
// The time at which the most recent occurance of this event was recorded.
|
||||
LastTimestamp util.Time `json:"lastTimestamp,omitempty"`
|
||||
|
||||
// The number of times this event has occurred.
|
||||
Count int `json:"count,omitempty"`
|
||||
}
|
||||
|
||||
// EventList is a list of events.
|
||||
|
@ -898,7 +898,11 @@ func init() {
|
||||
out.Message = in.Message
|
||||
out.Source = in.Source.Component
|
||||
out.Host = in.Source.Host
|
||||
out.Timestamp = in.Timestamp
|
||||
out.Timestamp = in.FirstTimestamp
|
||||
out.FirstTimestamp = in.FirstTimestamp
|
||||
out.LastTimestamp = in.LastTimestamp
|
||||
out.Count = in.Count
|
||||
|
||||
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
|
||||
},
|
||||
func(in *Event, out *newer.Event, s conversion.Scope) error {
|
||||
@ -912,7 +916,16 @@ func init() {
|
||||
out.Message = in.Message
|
||||
out.Source.Component = in.Source
|
||||
out.Source.Host = in.Host
|
||||
out.Timestamp = in.Timestamp
|
||||
if in.FirstTimestamp.IsZero() {
|
||||
// Assume this is an old event that does not specify FirstTimestamp/LastTimestamp/Count
|
||||
out.FirstTimestamp = in.Timestamp
|
||||
out.LastTimestamp = in.Timestamp
|
||||
out.Count = 1
|
||||
} else {
|
||||
out.FirstTimestamp = in.FirstTimestamp
|
||||
out.LastTimestamp = in.LastTimestamp
|
||||
out.Count = in.Count
|
||||
}
|
||||
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
|
||||
},
|
||||
|
||||
|
@ -865,7 +865,18 @@ type Event struct {
|
||||
Host string `json:"host,omitempty" description:"host name on which this event was generated"`
|
||||
|
||||
// The time at which the client recorded the event. (Time of server receipt is in TypeMeta.)
|
||||
// Deprecated: Use InitialTimeStamp/LastSeenTimestamp/Count instead.
|
||||
// For backwards compatability, this will map to IntialTimestamp.
|
||||
Timestamp util.Time `json:"timestamp,omitempty" description:"time at which the client recorded the event"`
|
||||
|
||||
// The time at which the event was first recorded. (Time of server receipt is in TypeMeta.)
|
||||
FirstTimestamp util.Time `json:"firstTimestamp,omitempty" description:"the time at which the event was first recorded"`
|
||||
|
||||
// The time at which the most recent occurance of this event was recorded.
|
||||
LastTimestamp util.Time `json:"lastTimestamp,omitempty" description:"the time at which the most recent occurance of this event was recorded"`
|
||||
|
||||
// The number of times this event has occurred.
|
||||
Count int `json:"count,omitempty" description:"the number of times this event has occurred"`
|
||||
}
|
||||
|
||||
// EventList is a list of events.
|
||||
|
@ -819,7 +819,10 @@ func init() {
|
||||
out.Message = in.Message
|
||||
out.Source = in.Source.Component
|
||||
out.Host = in.Source.Host
|
||||
out.Timestamp = in.Timestamp
|
||||
out.Timestamp = in.FirstTimestamp
|
||||
out.FirstTimestamp = in.FirstTimestamp
|
||||
out.LastTimestamp = in.LastTimestamp
|
||||
out.Count = in.Count
|
||||
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
|
||||
},
|
||||
func(in *Event, out *newer.Event, s conversion.Scope) error {
|
||||
@ -833,7 +836,16 @@ func init() {
|
||||
out.Message = in.Message
|
||||
out.Source.Component = in.Source
|
||||
out.Source.Host = in.Host
|
||||
out.Timestamp = in.Timestamp
|
||||
if in.FirstTimestamp.IsZero() {
|
||||
// Assume this is an old event that does not specify FirstTimestamp/LastTimestamp/Count
|
||||
out.FirstTimestamp = in.Timestamp
|
||||
out.LastTimestamp = in.Timestamp
|
||||
out.Count = 1
|
||||
} else {
|
||||
out.FirstTimestamp = in.FirstTimestamp
|
||||
out.LastTimestamp = in.LastTimestamp
|
||||
out.Count = in.Count
|
||||
}
|
||||
return s.Convert(&in.InvolvedObject, &out.InvolvedObject, 0)
|
||||
},
|
||||
|
||||
|
@ -840,7 +840,18 @@ type Event struct {
|
||||
Host string `json:"host,omitempty" description:"host name on which this event was generated"`
|
||||
|
||||
// The time at which the client recorded the event. (Time of server receipt is in TypeMeta.)
|
||||
// Deprecated: Use InitialTimeStamp/LastSeenTimestamp/Count instead.
|
||||
// For backwards compatability, this will map to IntialTimestamp.
|
||||
Timestamp util.Time `json:"timestamp,omitempty" description:"time at which the client recorded the event"`
|
||||
|
||||
// The time at which the event was first recorded. (Time of server receipt is in TypeMeta.)
|
||||
FirstTimestamp util.Time `json:"firstTimestamp,omitempty" description:"the time at which the event was first recorded"`
|
||||
|
||||
// The time at which the most recent occurance of this event was recorded.
|
||||
LastTimestamp util.Time `json:"lastTimestamp,omitempty" description:"the time at which the most recent occurance of this event was recorded"`
|
||||
|
||||
// The number of times this event has occurred.
|
||||
Count int `json:"count,omitempty" description:"the number of times this event has occurred"`
|
||||
}
|
||||
|
||||
// EventList is a list of events.
|
||||
|
@ -1058,8 +1058,14 @@ type Event struct {
|
||||
// Optional. The component reporting this event. Should be a short machine understandable string.
|
||||
Source EventSource `json:"source,omitempty"`
|
||||
|
||||
// The time at which the client recorded the event. (Time of server receipt is in TypeMeta.)
|
||||
Timestamp util.Time `json:"timestamp,omitempty"`
|
||||
// The time at which the event was first recorded. (Time of server receipt is in TypeMeta.)
|
||||
FirstTimestamp util.Time `json:"firstTimestamp,omitempty"`
|
||||
|
||||
// The time at which the most recent occurance of this event was recorded.
|
||||
LastTimestamp util.Time `json:"lastTimestamp,omitempty"`
|
||||
|
||||
// The number of times this event has occurred.
|
||||
Count int `json:"count,omitempty"`
|
||||
}
|
||||
|
||||
// EventList is a list of events.
|
||||
|
@ -64,7 +64,9 @@ func TestEventCreate(t *testing.T) {
|
||||
event := &api.Event{
|
||||
//namespace: namespace{"default"},
|
||||
InvolvedObject: *objReference,
|
||||
Timestamp: timeStamp,
|
||||
FirstTimestamp: timeStamp,
|
||||
LastTimestamp: timeStamp,
|
||||
Count: 1,
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
@ -98,7 +100,9 @@ func TestEventGet(t *testing.T) {
|
||||
timeStamp := util.Now()
|
||||
event := &api.Event{
|
||||
InvolvedObject: *objReference,
|
||||
Timestamp: timeStamp,
|
||||
FirstTimestamp: timeStamp,
|
||||
LastTimestamp: timeStamp,
|
||||
Count: 1,
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{
|
||||
@ -135,7 +139,9 @@ func TestEventList(t *testing.T) {
|
||||
Items: []api.Event{
|
||||
{
|
||||
InvolvedObject: *objReference,
|
||||
Timestamp: timeStamp,
|
||||
FirstTimestamp: timeStamp,
|
||||
LastTimestamp: timeStamp,
|
||||
Count: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -170,7 +170,9 @@ func Event(object runtime.Object, reason, message string) {
|
||||
InvolvedObject: *ref,
|
||||
Reason: reason,
|
||||
Message: message,
|
||||
Timestamp: t,
|
||||
FirstTimestamp: t,
|
||||
LastTimestamp: t,
|
||||
Count: 1,
|
||||
}
|
||||
|
||||
events.Action(watch.Added, e)
|
||||
|
@ -93,6 +93,7 @@ func TestEventf(t *testing.T) {
|
||||
Reason: "Started",
|
||||
Message: "some verbose message: 1",
|
||||
Source: api.EventSource{Component: "eventTest"},
|
||||
Count: 1,
|
||||
},
|
||||
expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:"desiredState.manifest.containers[2]"}): reason: 'Started' some verbose message: 1`,
|
||||
},
|
||||
@ -116,6 +117,7 @@ func TestEventf(t *testing.T) {
|
||||
Reason: "Started",
|
||||
Message: "some verbose message: 1",
|
||||
Source: api.EventSource{Component: "eventTest"},
|
||||
Count: 1,
|
||||
},
|
||||
expectLog: `Event(api.ObjectReference{Kind:"Pod", Namespace:"baz", Name:"foo", UID:"bar", APIVersion:"v1beta1", ResourceVersion:"", FieldPath:""}): reason: 'Started' some verbose message: 1`,
|
||||
},
|
||||
@ -127,10 +129,11 @@ func TestEventf(t *testing.T) {
|
||||
OnEvent: func(event *api.Event) (*api.Event, error) {
|
||||
a := *event
|
||||
// Just check that the timestamp was set.
|
||||
if a.Timestamp.IsZero() {
|
||||
if a.FirstTimestamp.IsZero() || a.LastTimestamp.IsZero() {
|
||||
t.Errorf("timestamp wasn't set")
|
||||
}
|
||||
a.Timestamp = item.expect.Timestamp
|
||||
a.FirstTimestamp = item.expect.FirstTimestamp
|
||||
a.LastTimestamp = item.expect.LastTimestamp
|
||||
// Check that name has the right prefix.
|
||||
if n, en := a.Name, item.expect.Name; !strings.HasPrefix(n, en) {
|
||||
t.Errorf("Name '%v' does not contain prefix '%v'", n, en)
|
||||
|
@ -301,7 +301,7 @@ func describeEvents(el *api.EventList, w io.Writer) {
|
||||
fmt.Fprint(w, "Events:\nTime\tFrom\tSubobjectPath\tReason\tMessage\n")
|
||||
for _, e := range el.Items {
|
||||
fmt.Fprintf(w, "%s\t%v\t%v\t%v\t%v\n",
|
||||
e.Timestamp.Time.Format(time.RFC1123Z),
|
||||
e.FirstTimestamp.Time.Format(time.RFC1123Z),
|
||||
e.Source,
|
||||
e.InvolvedObject.FieldPath,
|
||||
e.Reason,
|
||||
|
@ -69,19 +69,25 @@ func TestPodDescribeResultsSorted(t *testing.T) {
|
||||
EventsList: api.EventList{
|
||||
Items: []api.Event{
|
||||
{
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 1",
|
||||
Timestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 1",
|
||||
FirstTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
{
|
||||
Source: api.EventSource{Component: "scheduler"},
|
||||
Message: "Item 2",
|
||||
Timestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "scheduler"},
|
||||
Message: "Item 2",
|
||||
FirstTimestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
{
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 3",
|
||||
Timestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 3",
|
||||
FirstTimestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -407,7 +407,7 @@ func printStatus(status *api.Status, w io.Writer) error {
|
||||
func printEvent(event *api.Event, w io.Writer) error {
|
||||
_, err := fmt.Fprintf(
|
||||
w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
||||
event.Timestamp.Time.Format(time.RFC1123Z),
|
||||
event.FirstTimestamp.Time.Format(time.RFC1123Z),
|
||||
event.InvolvedObject.Name,
|
||||
event.InvolvedObject.Kind,
|
||||
event.InvolvedObject.FieldPath,
|
||||
|
@ -480,19 +480,25 @@ func TestPrintEventsResultSorted(t *testing.T) {
|
||||
obj := api.EventList{
|
||||
Items: []api.Event{
|
||||
{
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 1",
|
||||
Timestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 1",
|
||||
FirstTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
{
|
||||
Source: api.EventSource{Component: "scheduler"},
|
||||
Message: "Item 2",
|
||||
Timestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "scheduler"},
|
||||
Message: "Item 2",
|
||||
FirstTimestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
{
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 3",
|
||||
Timestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 3",
|
||||
FirstTimestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -32,5 +32,5 @@ func (list SortableEvents) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (list SortableEvents) Less(i, j int) bool {
|
||||
return list[i].Timestamp.Time.Before(list[j].Timestamp.Time)
|
||||
return list[i].LastTimestamp.Time.Before(list[j].LastTimestamp.Time)
|
||||
}
|
||||
|
@ -55,19 +55,25 @@ func TestSortableEvents(t *testing.T) {
|
||||
// Arrange
|
||||
list := SortableEvents([]api.Event{
|
||||
{
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 1",
|
||||
Timestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 1",
|
||||
FirstTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
{
|
||||
Source: api.EventSource{Component: "scheduler"},
|
||||
Message: "Item 2",
|
||||
Timestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "scheduler"},
|
||||
Message: "Item 2",
|
||||
FirstTimestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
{
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 3",
|
||||
Timestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
Source: api.EventSource{Component: "kubelet"},
|
||||
Message: "Item 3",
|
||||
FirstTimestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
LastTimestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user