Make EventData a concrete type.
Having this as an interface was giving us a lot of problems with unmarshaling. Made into a union of concrete types.
This commit is contained in:
parent
e32b661ac3
commit
a21bf2555e
@ -479,14 +479,17 @@ func calculateCpuUsage(prev, cur uint64) uint64 {
|
|||||||
// differentiated by the EventType field of Event.
|
// differentiated by the EventType field of Event.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
// the absolute container name for which the event occurred
|
// the absolute container name for which the event occurred
|
||||||
ContainerName string
|
ContainerName string `json:"container_name"`
|
||||||
|
|
||||||
// the time at which the event occurred
|
// the time at which the event occurred
|
||||||
Timestamp time.Time
|
Timestamp time.Time `json:"timestamp"`
|
||||||
|
|
||||||
// the type of event. EventType is an enumerated type
|
// the type of event. EventType is an enumerated type
|
||||||
EventType EventType
|
EventType EventType `json:"event_type"`
|
||||||
|
|
||||||
// the original event object and all of its extraneous data, ex. an
|
// the original event object and all of its extraneous data, ex. an
|
||||||
// OomInstance
|
// OomInstance
|
||||||
EventData EventDataInterface
|
EventData EventData `json:"event_data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventType is an enumerated type which lists the categories under which
|
// EventType is an enumerated type which lists the categories under which
|
||||||
@ -499,7 +502,26 @@ const (
|
|||||||
EventContainerDeletion
|
EventContainerDeletion
|
||||||
)
|
)
|
||||||
|
|
||||||
// a general interface which populates the Event field EventData. The actual
|
// Extra information about an event. Only one type will be set.
|
||||||
// object, such as an OomInstance, is set as an Event's EventData
|
type EventData struct {
|
||||||
type EventDataInterface interface {
|
// Information about a container creation event.
|
||||||
|
Created *CreatedEventData `json:"created,omitempty"`
|
||||||
|
|
||||||
|
// Information about an OOM event.
|
||||||
|
Oom *OomEventData `json:"oom,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Information related to a container creation event.
|
||||||
|
type CreatedEventData struct {
|
||||||
|
// Spec of the container at creation.
|
||||||
|
Spec ContainerSpec `json:"spec"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Information related to an OOM kill instance
|
||||||
|
type OomEventData struct {
|
||||||
|
// process id of the killed process
|
||||||
|
Pid int `json:"pid"`
|
||||||
|
|
||||||
|
// The name of the killed process
|
||||||
|
ProcessName string `json:"process_name"`
|
||||||
}
|
}
|
||||||
|
@ -660,12 +660,12 @@ func (m *manager) createContainer(containerName string) error {
|
|||||||
}
|
}
|
||||||
glog.V(2).Infof("Added container: %q (aliases: %v, namespace: %q)", containerName, cont.info.Aliases, cont.info.Namespace)
|
glog.V(2).Infof("Added container: %q (aliases: %v, namespace: %q)", containerName, cont.info.Aliases, cont.info.Namespace)
|
||||||
|
|
||||||
contSpecs, err := cont.handler.GetSpec()
|
contSpec, err := cont.handler.GetSpec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if contSpecs.CreationTime.After(m.startupTime) {
|
if contSpec.CreationTime.After(m.startupTime) {
|
||||||
contRef, err := cont.handler.ContainerReference()
|
contRef, err := cont.handler.ContainerReference()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -673,9 +673,13 @@ func (m *manager) createContainer(containerName string) error {
|
|||||||
|
|
||||||
newEvent := &info.Event{
|
newEvent := &info.Event{
|
||||||
ContainerName: contRef.Name,
|
ContainerName: contRef.Name,
|
||||||
EventData: contSpecs,
|
Timestamp: contSpec.CreationTime,
|
||||||
Timestamp: contSpecs.CreationTime,
|
|
||||||
EventType: info.EventContainerCreation,
|
EventType: info.EventContainerCreation,
|
||||||
|
EventData: info.EventData{
|
||||||
|
Created: &info.CreatedEventData{
|
||||||
|
Spec: contSpec,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
err = m.eventHandler.AddEvent(newEvent)
|
err = m.eventHandler.AddEvent(newEvent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -878,7 +882,12 @@ func (self *manager) watchForNewOoms() error {
|
|||||||
ContainerName: oomInstance.ContainerName,
|
ContainerName: oomInstance.ContainerName,
|
||||||
Timestamp: oomInstance.TimeOfDeath,
|
Timestamp: oomInstance.TimeOfDeath,
|
||||||
EventType: info.EventOom,
|
EventType: info.EventOom,
|
||||||
EventData: oomInstance,
|
EventData: info.EventData{
|
||||||
|
Oom: &info.OomEventData{
|
||||||
|
Pid: oomInstance.Pid,
|
||||||
|
ProcessName: oomInstance.ProcessName,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
glog.V(1).Infof("Created an oom event: %v", newEvent)
|
glog.V(1).Infof("Created an oom event: %v", newEvent)
|
||||||
err := self.eventHandler.AddEvent(newEvent)
|
err := self.eventHandler.AddEvent(newEvent)
|
||||||
|
Loading…
Reference in New Issue
Block a user