craigcondit commented on code in PR #589:
URL: https://github.com/apache/yunikorn-core/pull/589#discussion_r1270816194
##########
pkg/scheduler/objects/common_test.go:
##########
@@ -39,6 +39,10 @@ func (m *EventSystemMock) Reset() {
m.events = make([]*si.EventRecord, 0)
}
+func (m *EventSystemMock) GetEventsFromId(uint64, uint64) ([]*si.EventRecord,
uint64, uint64) {
Review Comment:
As above, GetEventsFromId -> GetEventsFromID. Also, name the output
variables.
##########
pkg/events/event_system.go:
##########
@@ -28,38 +28,46 @@ import (
// need to change for testing
var defaultEventChannelSize = 100000
+var defaultRingBufferSize uint64 = 100000
var ev EventSystem
type EventSystem interface {
AddEvent(event *si.EventRecord)
StartService()
Stop()
+ GetEventsFromId(uint64, uint64) ([]*si.EventRecord, uint64, uint64)
Review Comment:
ID should be capitalized here. (GetEventsFromId -> GetEventsFromID).
##########
pkg/webservice/handlers.go:
##########
@@ -869,3 +870,53 @@ func getGroupResourceUsage(w http.ResponseWriter, r
*http.Request) {
buildJSONErrorResponse(w, err.Error(),
http.StatusInternalServerError)
}
}
+
+func getEvents(w http.ResponseWriter, r *http.Request) {
+ writeHeaders(w)
+ eventSystem := events.GetEventSystem()
+ if eventSystem == nil {
+ buildJSONErrorResponse(w, "Event system is disabled",
http.StatusBadRequest)
+ return
+ }
+
+ count := uint64(10000)
+ var fromId uint64
+ vars := httprouter.ParamsFromContext(r.Context())
+ if vars != nil {
+ if countStr := vars.ByName("count"); countStr != "" {
+ c, err := strconv.ParseInt(countStr, 10, 64)
+ if err != nil {
+ buildJSONErrorResponse(w, err.Error(),
http.StatusBadRequest)
+ return
+ }
+ if c <= 0 {
+ buildJSONErrorResponse(w, fmt.Sprintf("Illegal
number of events: %d", c), http.StatusBadRequest)
+ return
+ }
+ count = uint64(c)
+ }
+
+ if fromIdStr := vars.ByName("fromId"); fromIdStr != "" {
Review Comment:
I think we should name this parameter "start" instead of fromID. It's
simpler to type and no casing issues to address. As such, startStr should be
the variable name used.
##########
pkg/events/event_system.go:
##########
@@ -28,38 +28,46 @@ import (
// need to change for testing
var defaultEventChannelSize = 100000
+var defaultRingBufferSize uint64 = 100000
var ev EventSystem
type EventSystem interface {
AddEvent(event *si.EventRecord)
StartService()
Stop()
+ GetEventsFromId(uint64, uint64) ([]*si.EventRecord, uint64, uint64)
}
type EventSystemImpl struct {
- Store *EventStore // storing eventChannel
- publisher *EventPublisher
+ Store *EventStore // storing eventChannel
+ publisher *EventPublisher
+ eventBuffer *eventRingBuffer
channel chan *si.EventRecord // channelling input eventChannel
- stop chan bool // whether the service is stop
+ stop chan bool // whether the service is stopped
stopped bool
sync.Mutex
}
+func (ec *EventSystemImpl) GetEventsFromId(id, count uint64)
([]*si.EventRecord, uint64, uint64) {
Review Comment:
Let's add names for the returned values for clarity.
##########
pkg/events/event_ringbuffer.go:
##########
@@ -66,14 +66,14 @@ func (e *eventRingBuffer) Add(event *si.EventRecord) {
// identifier is returned which can be used to get the first batch.
// If the caller does not want to pose limit on the number of events returned,
"count" must be set to a high
// value, e.g. math.MaxUint64.
-func (e *eventRingBuffer) GetEventsFromID(id uint64, count uint64)
([]*si.EventRecord, uint64) {
+func (e *eventRingBuffer) GetEventsFromID(id uint64, count uint64)
([]*si.EventRecord, uint64, uint64) {
Review Comment:
Let's name the output variables for clarity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]