zhuqi-lucas commented on code in PR #533:
URL: https://github.com/apache/yunikorn-core/pull/533#discussion_r1409245366


##########
pkg/events/event_streaming.go:
##########
@@ -0,0 +1,180 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package events
+
+import (
+       "sync"
+       "time"
+
+       "go.uber.org/zap"
+
+       "github.com/apache/yunikorn-core/pkg/log"
+       "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
+)
+
+const defaultChannelBufSize = 100
+
+// EventStreaming implements the event streaming logic.
+// New events are immediately forwarded to all active consumers.
+type EventStreaming struct {
+       buffer       *eventRingBuffer
+       stopCh       chan struct{}
+       eventStreams map[*EventStream]eventConsumerDetails
+       sync.Mutex
+}
+
+type eventConsumerDetails struct {
+       local     chan *si.EventRecord
+       consumer  chan<- *si.EventRecord
+       stopCh    chan struct{}
+       name      string
+       createdAt time.Time
+}
+
+// EventStream handle type returned to the client that wants to capture the 
stream of events.
+type EventStream struct {
+       Events <-chan *si.EventRecord
+}
+
+// PublishEvent publishes an event to all event stream consumers.
+//
+// The streaming logic uses bridging to ensure proper ordering of existing and 
new events.
+// Events are sent to the "local" channel from where it is forwarded to the 
"consumer" channel.
+//
+// If "local" is full, it means that the consumer side has not processed the 
events at an appropriate pace.
+// Such a consumer is removed and the related channels are closed.
+func (e *EventStreaming) PublishEvent(event *si.EventRecord) {
+       e.Lock()
+       defer e.Unlock()
+
+       for consumer, details := range e.eventStreams {

Review Comment:
   @wilfred-s @pbacsko I think the customer here is a good place for us to set 
a internal customer, the new trackingService, we can at least use it to 
streaming resourcce related events and aggregated tracking events.



-- 
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]

Reply via email to