Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TAS: allow to dump the usage of domains for TAS ResourceFlavors #4295

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ func (s *Snapshot) Log(log logr.Logger) {
"usage", cohort.ResourceNode.Usage,
)
}

// Dump TAS snapshots if the feature is enabled
if features.Enabled(features.TopologyAwareScheduling) {
for cqName, cq := range s.ClusterQueues {
for tasFlavor, tasSnapshot := range cq.TASFlavors {
log.Info("TAS Snapshot Free Capacity",
"clusterQueue", cqName,
"resourceFlavor", tasFlavor,
"freeCapacityPerDomain", tasSnapshot.FreeCapacityPerDomain(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify that this log line works properly when running integration test, and that is not affected by #4137. There is no need to write a new integration test, unless this path is not covered. We only want to make sure that this line is output properly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it looks now: 2025/02/26 10:38:20 INFO TAS Snapshot Free Capacity freeCapacityPerDomain="map[domain1:map[cpu:2000 memory:4294967296 nvidia.com/gpu:1] domain2:map[cpu:1000 memory:2147483648]]"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pretty print these? 4294967296, 2147483648 is hard for humans to read

Try this function

func ResourceQuantityString(name corev1.ResourceName, v int64) string {
rq := ResourceQuantity(name, v)
return rq.String()
}

)
}
}
}
}

func (c *Cache) Snapshot(ctx context.Context) (*Snapshot, error) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/cache/tas_flavor_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ func (s *TASFlavorSnapshot) removeTASUsage(domainID utiltas.TopologyDomainID, us
s.leaves[domainID].tasUsage.Sub(usage)
}

func (s *TASFlavorSnapshot) FreeCapacityPerDomain() map[string]resources.Requests {
freeCapacityPerDomain := make(map[string]resources.Requests)

for domainID, leaf := range s.leaves {
// CPU is represented in millicores
// Memory is represented in bytes
// For other resources, use their raw integer value
freeCapacityPerDomain[string(domainID)] = leaf.freeCapacity.Clone()
}

return freeCapacityPerDomain
}

type TASPodSetRequests struct {
PodSet *kueue.PodSet
SinglePodRequests resources.Requests
Expand Down
63 changes: 63 additions & 0 deletions pkg/cache/tas_flavor_snapshot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright The Kubernetes Authors.

Licensed 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 cache

import (
"testing"

"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"

"sigs.k8s.io/kueue/pkg/resources"
)

func TestFreeCapacityPerDomain(t *testing.T) {
snapshot := &TASFlavorSnapshot{
leaves: leafDomainByID{
"domain1": &leafDomain{
freeCapacity: resources.Requests{
corev1.ResourceCPU: 2000,
corev1.ResourceMemory: 4 * 1024 * 1024 * 1024, // 4 GiB
"nvidia.com/gpu": 1,
},
},
"domain2": &leafDomain{
freeCapacity: resources.Requests{
corev1.ResourceCPU: 1000,
corev1.ResourceMemory: 2 * 1024 * 1024 * 1024, // 2 GiB
},
},
},
}

expected := map[string]resources.Requests{
"domain1": {
corev1.ResourceCPU: 2000,
corev1.ResourceMemory: 4 * 1024 * 1024 * 1024,
"nvidia.com/gpu": 1,
},
"domain2": {
corev1.ResourceCPU: 1000,
corev1.ResourceMemory: 2 * 1024 * 1024 * 1024,
},
}

actual := snapshot.FreeCapacityPerDomain()
if diff := cmp.Diff(expected, actual); diff != "" {
t.Errorf("FreeCapacityPerDomain() mismatch (-expected +actual):\n%s", diff)
}
}