Skip to content

Commit ee8d7fa

Browse files
Michaelcraigcondit
Michael
authored andcommitted
[YUNIKORN-2907] Avoid extraneous logging during queue config processing (#1009)
Closes: #1009 Signed-off-by: Craig Condit <[email protected]>
1 parent 4f2f1b3 commit ee8d7fa

14 files changed

+148
-105
lines changed

pkg/common/security/acl.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ func (a *ACL) setAllAllowed(part string) {
4646
a.allAllowed = part == common.Wildcard
4747
}
4848

49-
// set the user list in the ACL, invalid user names are ignored
50-
func (a *ACL) setUsers(userList []string) {
49+
// set the user list in the ACL, invalid user names are ignored.
50+
// If the silence flag is set to true, the function will not log when setting the users.
51+
func (a *ACL) setUsers(userList []string, silence bool) {
5152
a.users = make(map[string]bool)
5253
// special case if the user list is just the wildcard
5354
if len(userList) == 1 && userList[0] == common.Wildcard {
54-
log.Log(log.Security).Info("user list is wildcard, allowing all access")
55+
if !silence {
56+
log.Log(log.Security).Info("user list is wildcard, allowing all access")
57+
}
5558
a.allAllowed = true
5659
return
5760
}
@@ -64,23 +67,28 @@ func (a *ACL) setUsers(userList []string) {
6467
// check the users validity
6568
if userNameRegExp.MatchString(user) {
6669
a.users[user] = true
67-
} else {
70+
} else if !silence {
6871
log.Log(log.Security).Info("ignoring user in ACL definition",
6972
zap.String("user", user))
7073
}
7174
}
7275
}
7376

7477
// set the group list in the ACL, invalid group names are ignored
75-
func (a *ACL) setGroups(groupList []string) {
78+
// If the silence flag is set to true, the function will not log when setting the groups.
79+
func (a *ACL) setGroups(groupList []string, silence bool) {
7680
a.groups = make(map[string]bool)
7781
// special case if the wildcard was already set
7882
if a.allAllowed {
79-
log.Log(log.Security).Info("ignoring group list in ACL: wildcard set")
83+
if !silence {
84+
log.Log(log.Security).Info("ignoring group list in ACL: wildcard set")
85+
}
8086
return
8187
}
8288
if len(groupList) == 1 && groupList[0] == common.Wildcard {
83-
log.Log(log.Security).Info("group list is wildcard, allowing all access")
89+
if !silence {
90+
log.Log(log.Security).Info("group list is wildcard, allowing all access")
91+
}
8492
a.users = make(map[string]bool)
8593
a.allAllowed = true
8694
return
@@ -94,15 +102,15 @@ func (a *ACL) setGroups(groupList []string) {
94102
// check the group validity
95103
if groupRegExp.MatchString(group) {
96104
a.groups[group] = true
97-
} else {
105+
} else if !silence {
98106
log.Log(log.Security).Info("ignoring group in ACL",
99107
zap.String("group", group))
100108
}
101109
}
102110
}
103111

104112
// create a new ACL from scratch
105-
func NewACL(aclStr string) (ACL, error) {
113+
func NewACL(aclStr string, silence bool) (ACL, error) {
106114
acl := ACL{}
107115
if aclStr == "" {
108116
return acl, nil
@@ -116,9 +124,9 @@ func NewACL(aclStr string) (ACL, error) {
116124
// trim and check for wildcard
117125
acl.setAllAllowed(aclStr)
118126
// parse users and groups
119-
acl.setUsers(strings.Split(fields[0], common.Separator))
127+
acl.setUsers(strings.Split(fields[0], common.Separator), silence)
120128
if len(fields) == 2 {
121-
acl.setGroups(strings.Split(fields[1], common.Separator))
129+
acl.setGroups(strings.Split(fields[1], common.Separator), silence)
122130
}
123131
return acl, nil
124132
}

pkg/common/security/acl_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestACLCreate(t *testing.T) {
155155
}
156156
for _, tt := range tests {
157157
t.Run(tt.input, func(t *testing.T) {
158-
got, err := NewACL(tt.input)
158+
got, err := NewACL(tt.input, false)
159159
if err != nil {
160160
t.Errorf("parsing failed for string: %s", tt.input)
161161
}
@@ -177,7 +177,7 @@ func TestNewACLErrorCase(t *testing.T) {
177177
}
178178
for _, tt := range tests {
179179
t.Run(tt.caseName, func(t *testing.T) {
180-
if _, err := NewACL(tt.acl); err == nil {
180+
if _, err := NewACL(tt.acl, false); err == nil {
181181
t.Errorf("parsing %s string should be failed", tt.acl)
182182
}
183183
})
@@ -238,7 +238,7 @@ func TestACLAccess(t *testing.T) {
238238
}
239239
for _, tt := range tests {
240240
t.Run(fmt.Sprintf("vistor %v, acl %s", tt.visitor, tt.acl), func(t *testing.T) {
241-
acl, err := NewACL(tt.acl)
241+
acl, err := NewACL(tt.acl, false)
242242
if err != nil {
243243
t.Error("the number of space should not be more than 2 because the number of categories only include users and groups")
244244
}

pkg/scheduler/context.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func (cc *ClusterContext) updateSchedulerConfig(conf *configs.SchedulerConfig, r
365365
part, ok := cc.partitions[p.Name]
366366
if ok {
367367
// make sure the new info passes all checks
368-
_, err = newPartitionContext(p, rmID, nil)
368+
_, err = newPartitionContext(p, rmID, nil, true)
369369
if err != nil {
370370
return err
371371
}
@@ -379,7 +379,7 @@ func (cc *ClusterContext) updateSchedulerConfig(conf *configs.SchedulerConfig, r
379379
// not found: new partition, no checks needed
380380
log.Log(log.SchedContext).Info("added partitions", zap.String("partitionName", partitionName))
381381

382-
part, err = newPartitionContext(p, rmID, cc)
382+
part, err = newPartitionContext(p, rmID, cc, false)
383383
if err != nil {
384384
return err
385385
}

pkg/scheduler/context_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func createTestContext(t *testing.T, partitionName string) *ClusterContext {
8686
},
8787
},
8888
}
89-
partition, err := newPartitionContext(conf, "test", context)
89+
partition, err := newPartitionContext(conf, "test", context, false)
9090
assert.NilError(t, err, "partition create should not have failed with error")
9191
context.partitions[partition.Name] = partition
9292
return context

pkg/scheduler/objects/queue.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ func newBlankQueue() *Queue {
114114
}
115115

116116
// NewConfiguredQueue creates a new queue from scratch based on the configuration
117-
// lock free as it cannot be referenced yet
118-
func NewConfiguredQueue(conf configs.QueueConfig, parent *Queue) (*Queue, error) {
117+
// lock free as it cannot be referenced yet.
118+
// If the silence flag is set to true, the function will neither log the queue creation nor send a queue event.
119+
func NewConfiguredQueue(conf configs.QueueConfig, parent *Queue, silence bool) (*Queue, error) {
119120
sq := newBlankQueue()
120121
sq.Name = strings.ToLower(conf.Name)
121122
sq.QueuePath = strings.ToLower(conf.Name)
@@ -128,7 +129,7 @@ func NewConfiguredQueue(conf configs.QueueConfig, parent *Queue) (*Queue, error)
128129
sq.updateMaxRunningAppsMetrics()
129130

130131
// update the properties
131-
if err := sq.applyConf(conf); err != nil {
132+
if err := sq.applyConf(conf, silence); err != nil {
132133
return nil, errors.Join(errors.New("configured queue creation failed: "), err)
133134
}
134135

@@ -145,10 +146,13 @@ func NewConfiguredQueue(conf configs.QueueConfig, parent *Queue) (*Queue, error)
145146
} else {
146147
sq.UpdateQueueProperties()
147148
}
148-
sq.queueEvents = schedEvt.NewQueueEvents(events.GetEventSystem())
149-
log.Log(log.SchedQueue).Info("configured queue added to scheduler",
150-
zap.String("queueName", sq.QueuePath))
151-
sq.queueEvents.SendNewQueueEvent(sq.QueuePath, sq.isManaged)
149+
150+
if !silence {
151+
sq.queueEvents = schedEvt.NewQueueEvents(events.GetEventSystem())
152+
log.Log(log.SchedQueue).Info("configured queue added to scheduler",
153+
zap.String("queueName", sq.QueuePath))
154+
sq.queueEvents.SendNewQueueEvent(sq.QueuePath, sq.isManaged)
155+
}
152156

153157
return sq, nil
154158
}
@@ -310,21 +314,22 @@ func filterParentProperty(key string, value string) string {
310314
func (sq *Queue) ApplyConf(conf configs.QueueConfig) error {
311315
sq.Lock()
312316
defer sq.Unlock()
313-
return sq.applyConf(conf)
317+
return sq.applyConf(conf, false)
314318
}
315319

316320
// applyConf applies all the properties to the queue from the config.
317-
// lock free call, must be called holding the queue lock or during create only
318-
func (sq *Queue) applyConf(conf configs.QueueConfig) error {
321+
// lock free call, must be called holding the queue lock or during create only.
322+
// If the silence flag is set to true, the function will not log when setting users and groups.
323+
func (sq *Queue) applyConf(conf configs.QueueConfig, silence bool) error {
319324
// Set the ACLs
320325
var err error
321-
sq.submitACL, err = security.NewACL(conf.SubmitACL)
326+
sq.submitACL, err = security.NewACL(conf.SubmitACL, silence)
322327
if err != nil {
323328
log.Log(log.SchedQueue).Error("parsing submit ACL failed this should not happen",
324329
zap.Error(err))
325330
return err
326331
}
327-
sq.adminACL, err = security.NewACL(conf.AdminACL)
332+
sq.adminACL, err = security.NewACL(conf.AdminACL, silence)
328333
if err != nil {
329334
log.Log(log.SchedQueue).Error("parsing admin ACL failed this should not happen",
330335
zap.Error(err))

pkg/scheduler/objects/queue_test.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ func TestNewConfiguredQueue(t *testing.T) {
22672267
},
22682268
},
22692269
}
2270-
parent, err := NewConfiguredQueue(parentConfig, nil)
2270+
parent, err := NewConfiguredQueue(parentConfig, nil, false)
22712271
assert.NilError(t, err, "failed to create queue: %v", err)
22722272
assert.Equal(t, parent.Name, "parent_queue")
22732273
assert.Equal(t, parent.QueuePath, "parent_queue")
@@ -2287,7 +2287,7 @@ func TestNewConfiguredQueue(t *testing.T) {
22872287
Guaranteed: getResourceConf(),
22882288
},
22892289
}
2290-
childLeaf, err := NewConfiguredQueue(leafConfig, parent)
2290+
childLeaf, err := NewConfiguredQueue(leafConfig, parent, false)
22912291
assert.NilError(t, err, "failed to create queue: %v", err)
22922292
assert.Equal(t, childLeaf.QueuePath, "parent_queue.leaf_queue")
22932293
assert.Assert(t, childLeaf.template == nil)
@@ -2304,13 +2304,26 @@ func TestNewConfiguredQueue(t *testing.T) {
23042304
Name: "nonleaf_queue",
23052305
Parent: true,
23062306
}
2307-
childNonLeaf, err := NewConfiguredQueue(NonLeafConfig, parent)
2307+
childNonLeaf, err := NewConfiguredQueue(NonLeafConfig, parent, false)
23082308
assert.NilError(t, err, "failed to create queue: %v", err)
23092309
assert.Equal(t, childNonLeaf.QueuePath, "parent_queue.nonleaf_queue")
23102310
assert.Assert(t, reflect.DeepEqual(childNonLeaf.template, parent.template))
23112311
assert.Equal(t, len(childNonLeaf.properties), 0)
23122312
assert.Assert(t, childNonLeaf.guaranteedResource == nil)
23132313
assert.Assert(t, childNonLeaf.maxResource == nil)
2314+
2315+
// case 2: do not send queue event when silence flag is set to true
2316+
events.Init()
2317+
eventSystem := events.GetEventSystem().(*events.EventSystemImpl) //nolint:errcheck
2318+
eventSystem.StartServiceWithPublisher(false)
2319+
rootConfig := configs.QueueConfig{
2320+
Name: "root",
2321+
}
2322+
_, err = NewConfiguredQueue(rootConfig, nil, true)
2323+
assert.NilError(t, err, "failed to create queue: %v", err)
2324+
time.Sleep(time.Second)
2325+
noEvents := eventSystem.Store.CountStoredEvents()
2326+
assert.Equal(t, noEvents, uint64(0), "expected 0 event, got %d", noEvents)
23142327
}
23152328

23162329
func TestResetRunningState(t *testing.T) {
@@ -2333,11 +2346,11 @@ func TestResetRunningState(t *testing.T) {
23332346
parent.MarkQueueForRemoval()
23342347
assert.Assert(t, parent.IsDraining(), "parent should be marked as draining")
23352348
assert.Assert(t, leaf.IsDraining(), "leaf should be marked as draining")
2336-
err = parent.applyConf(emptyConf)
2349+
err = parent.applyConf(emptyConf, false)
23372350
assert.NilError(t, err, "failed to update parent")
23382351
assert.Assert(t, parent.IsRunning(), "parent should be running again")
23392352
assert.Assert(t, leaf.IsDraining(), "leaf should still be marked as draining")
2340-
err = leaf.applyConf(emptyConf)
2353+
err = leaf.applyConf(emptyConf, false)
23412354
assert.NilError(t, err, "failed to update leaf")
23422355
assert.Assert(t, leaf.IsRunning(), "leaf should be running again")
23432356
}
@@ -2360,7 +2373,7 @@ func TestNewRecoveryQueue(t *testing.T) {
23602373
Properties: map[string]string{configs.ApplicationSortPolicy: "fair"},
23612374
ChildTemplate: configs.ChildTemplate{Properties: map[string]string{configs.ApplicationSortPolicy: "fair"}},
23622375
}
2363-
parent, err = NewConfiguredQueue(parentConfig, nil)
2376+
parent, err = NewConfiguredQueue(parentConfig, nil, false)
23642377
assert.NilError(t, err, "failed to create queue: %v", err)
23652378
recoveryQueue, err := NewRecoveryQueue(parent)
23662379
assert.NilError(t, err, "failed to create recovery queue: %v", err)

pkg/scheduler/objects/utilities_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func createManagedQueuePropsMaxApps(parentSQ *Queue, name string, parent bool, m
9797
Guaranteed: guarRes,
9898
}
9999
}
100-
queue, err := NewConfiguredQueue(queueConfig, parentSQ)
100+
queue, err := NewConfiguredQueue(queueConfig, parentSQ, false)
101101
if err != nil {
102102
return nil, err
103103
}

0 commit comments

Comments
 (0)