From c61bf9a557579f8c837ab0f32542e1275ac348c4 Mon Sep 17 00:00:00 2001 From: steinsgateted Date: Tue, 1 Mar 2022 16:13:03 +0800 Subject: [PATCH] [YUNIKORN-1097] ERMProxy DEBUG cannot log event with channel --- pkg/rmproxy/rmevent/events.go | 46 +++++++++++++++++++++++++++++++++++ pkg/rmproxy/rmproxy.go | 2 +- pkg/scheduler/scheduler.go | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/pkg/rmproxy/rmevent/events.go b/pkg/rmproxy/rmevent/events.go index 322063794..1eba7eb21 100644 --- a/pkg/rmproxy/rmevent/events.go +++ b/pkg/rmproxy/rmevent/events.go @@ -99,3 +99,49 @@ type RMNodeUpdateEvent struct { AcceptedNodes []*si.AcceptedNode RejectedNodes []*si.RejectedNode } + +//log only +func GetEventWithoutChan(ev interface{}) interface{} { + m := map[string]interface{}{} + switch v := ev.(type) { + case *RMRegistrationEvent: + c := <-v.Channel + m["RMRegistrationEvent"] = map[string]interface{}{ + "Registration": v.Registration, + "Channel": c, + } + return m + case *RMConfigUpdateEvent: + c := <-v.Channel + m["RMConfigUpdateEvent"] = map[string]interface{}{ + "RmID": v.RmID, + "Channel": c, + } + return m + case *RMPartitionsRemoveEvent: + c := <-v.Channel + m["RMPartitionsRemoveEvent"] = map[string]interface{}{ + "RmID": v.RmID, + "Channel": c, + } + return m + case *RMNewAllocationsEvent: + c := <-v.Channel + m["RMNewAllocationsEvent"] = map[string]interface{}{ + "RmID": v.RmID, + "Allocations": v.Allocations, + "Channel": c, + } + return m + case *RMReleaseAllocationEvent: + c := <-v.Channel + m["RMPartitionsRemoveEvent"] = map[string]interface{}{ + "RmID": v.RmID, + "ReleasedAllocations": v.ReleasedAllocations, + "Channel": c, + } + return m + default: + return ev + } +} diff --git a/pkg/rmproxy/rmproxy.go b/pkg/rmproxy/rmproxy.go index 1753671de..f74d3a70f 100644 --- a/pkg/rmproxy/rmproxy.go +++ b/pkg/rmproxy/rmproxy.go @@ -62,7 +62,7 @@ func enqueueAndCheckFull(queue chan interface{}, ev interface{}) { select { case queue <- ev: log.Logger().Debug("enqueue event", - zap.Any("event", ev), + zap.Any("event", rmevent.GetEventWithoutChan(ev)), zap.Int("currentQueueSize", len(queue))) default: log.Logger().Panic("failed to enqueue event", diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index f4e791bfd..4ce67d5cd 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -96,7 +96,7 @@ func enqueueAndCheckFull(queue chan interface{}, ev interface{}) { case queue <- ev: log.Logger().Debug("enqueued event", zap.String("eventType", reflect.TypeOf(ev).String()), - zap.Any("event", ev), + zap.Any("event", rmevent.GetEventWithoutChan(ev)), zap.Int("currentQueueSize", len(queue))) default: log.Logger().DPanic("failed to enqueue event",