Skip to content

Commit 329a00b

Browse files
committed
chore: log action filter parameters for job events
Log the parameters used to filter job events by action to improve traceability and debugging. Signed-off-by: Michael Adler <[email protected]>
1 parent 26b4360 commit 329a00b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

internal/handler/job/events/events.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ type FilterParams struct {
8282

8383
type Action string
8484

85+
// compile-time check to ensure we implement the zerolog's serialization interface
86+
var _ zerolog.LogObjectMarshaler = (Action)("")
87+
88+
func (a Action) MarshalZerologObject(e *zerolog.Event) {
89+
e.Str("action", string(a))
90+
}
91+
8592
const (
8693
ActionCreate Action = "CREATE"
8794
ActionDelete Action = "DELETE"
@@ -106,7 +113,8 @@ func AddSubscriber(ctx context.Context, graceInterval time.Duration, filter Filt
106113
Dict("filterParams", zerolog.Dict().
107114
Strs("clientIDs", filter.ClientIDs).
108115
Strs("jobIDs", filter.JobIDs).
109-
Strs("workflows", filter.Workflows)).
116+
Strs("workflows", filter.Workflows).
117+
Interface("actions", filter.Actions)).
110118
Strs("tags", tags).
111119
Msg("Adding new subscriber for job events")
112120

@@ -166,14 +174,14 @@ func RemoveSubscriber(subscriber *Subscriber) {
166174
muSubscribers.Lock()
167175
defer muSubscribers.Unlock()
168176

169-
oldSubscribers := subscribers
170-
subscribers = make([]*Subscriber, 0, len(subscribers))
171-
for _, sub := range oldSubscribers {
177+
var newSubscribers []*Subscriber
178+
for _, sub := range subscribers {
172179
if sub == subscriber {
173180
continue
174181
}
175-
subscribers = append(subscribers, sub)
182+
newSubscribers = append(newSubscribers, sub)
176183
}
184+
subscribers = newSubscribers
177185
close(subscriber.ch)
178186
log.Info().Str("id", subscriber.id).Msg("Removed subscriber")
179187
}
@@ -193,9 +201,9 @@ func PublishEvent(ctx context.Context, event JobEvent) {
193201
defer muSubscribers.Unlock()
194202

195203
// the subscribers that are still active and we'll keep
196-
count := len(subscribers)
197-
newSubscribers := make([]*Subscriber, 0, count)
204+
var newSubscribers []*Subscriber
198205

206+
count := len(subscribers)
199207
log.Debug().Int("count", count).Msg("Publishing event to subscribers")
200208
for _, sub := range subscribers {
201209
ctxLog := log.With().Str("id", sub.id).Logger()

0 commit comments

Comments
 (0)