Skip to content

Commit

Permalink
Modify Event struct to allow compressing multiple recurring events in…
Browse files Browse the repository at this point in the history
… to a single event.

# *** ERROR: *** Some API files are missing the required field descriptions
# Add description tags to all non-inline fields in the following files:
#   pkg/api/v1beta1/types.go
#   pkg/api/v1beta2/types.go
#
# Your commit will be aborted unless you fix these.
#   COMMIT_BLOCKED_ON_DESCRIPTION
  • Loading branch information
saad-ali committed Feb 6, 2015
1 parent ff4c23d commit 79cbcf9
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 44 deletions.
16 changes: 16 additions & 0 deletions pkg/api/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 15 additions & 2 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
},

Expand Down
11 changes: 11 additions & 0 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
},

Expand Down
11 changes: 11 additions & 0 deletions pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions pkg/client/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -135,7 +139,9 @@ func TestEventList(t *testing.T) {
Items: []api.Event{
{
InvolvedObject: *objReference,
Timestamp: timeStamp,
FirstTimestamp: timeStamp,
LastTimestamp: timeStamp,
Count: 1,
},
},
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/record/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions pkg/client/record/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
Expand All @@ -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`,
},
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 15 additions & 9 deletions pkg/kubectl/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/resource_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 15 additions & 9 deletions pkg/kubectl/resource_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/sorted_event_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
24 changes: 15 additions & 9 deletions pkg/kubectl/sorted_event_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})

Expand Down

0 comments on commit 79cbcf9

Please sign in to comment.