Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
Merged
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
18 changes: 16 additions & 2 deletions pkg/driver/dra_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"slices"
"strings"
"time"

"github.com/google/dranet/pkg/apis"
Expand Down Expand Up @@ -55,9 +56,9 @@ func (np *NetworkDriver) PublishResources(ctx context.Context) {
for {
select {
case devices := <-np.netdb.GetResources(ctx):
klog.V(4).Infof("Received %d devices", len(devices))
klog.V(3).Infof("Got %d devices from inventory: %s", len(devices), formatDeviceNames(devices, 15))
devices = filter.FilterDevices(np.celProgram, devices)
klog.V(4).Infof("After filtering %d devices", len(devices))
klog.V(3).Infof("After filtering, publishing %d devices in ResourceSlice(s): %s", len(devices), formatDeviceNames(devices, 15))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we have some debug mode which prints all devices? That might be a good middle ground.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you saying debug mode in ADDITION to the subset of devices?

(Usually I've not found debug mode to be helpful, because by the issue we wanted to catch is already missed, so I would want something else as well, besides the debug mode.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah that's fair, debug mode can sometimes be helpful if we can repro the issue but can't see enough logs as is. Do we not usually expect to see > 15 devices in our inventory? If so then we can go ahead with this, but might want to make it something we can pass as a command line variable so if we need to we can adjust it if it's not too much work to plumb it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha, thanks! I think 15 should be good for now. As you described, we've not even close to 15 so far. Mostly just 10.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this is always something we can improve on, this seems good as is and adds value.


np.publishResourcesPrometheusMetrics(devices)

Expand Down Expand Up @@ -431,3 +432,16 @@ func (np *NetworkDriver) HandleError(ctx context.Context, err error, msg string)
// See: https://pkg.go.dev/k8s.io/apimachinery/pkg/util/runtime#HandleErrorWithContext
runtime.HandleErrorWithContext(ctx, err, msg)
}

func formatDeviceNames(devices []resourceapi.Device, max int) string {
deviceNames := make([]string, len(devices))
for i := range devices {
deviceNames[i] = devices[i].Name
}

if len(deviceNames) <= max {
return strings.Join(deviceNames, ", ")
}

return fmt.Sprintf("%s, and %d more", strings.Join(deviceNames[:max], ", "), len(deviceNames)-max)
}
5 changes: 5 additions & 0 deletions pkg/inventory/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"maps"
"net"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -197,6 +198,10 @@ func (db *DB) scan() []resourceapi.Device {
filteredDevices = append(filteredDevices, device)
}

sort.Slice(filteredDevices, func(i, j int) bool {
return filteredDevices[i].Name < filteredDevices[j].Name
})

klog.V(4).Infof("Found %d devices", len(filteredDevices))
db.updateDeviceStore(filteredDevices)
return filteredDevices
Expand Down
Loading